diff --git a/products/iap/api.yaml b/products/iap/api.yaml index 8af0a2448919..e59b5589cbcf 100644 --- a/products/iap/api.yaml +++ b/products/iap/api.yaml @@ -176,13 +176,14 @@ objects: - !ruby/object:Api::Resource name: 'Client' base_url: '{{brand}}/identityAwareProxyClients' - self_link: '{{name}}' + self_link: '{{client_id}}' input: true description: | Contains the data that describes an Identity Aware Proxy owned client. parameters: - !ruby/object:Api::Type::String - name: 'name' + name: 'clientId' + api_name: name description: | Output only. Unique identifier of the OAuth client. output: true diff --git a/products/iap/terraform.yaml b/products/iap/terraform.yaml index 5c1461e6e8b6..f3d26a38dd41 100644 --- a/products/iap/terraform.yaml +++ b/products/iap/terraform.yaml @@ -188,14 +188,13 @@ overrides: !ruby/object:Overrides::ResourceOverrides attributes: | * `client_id`: The OAuth2 ID of the client. properties: - name: !ruby/object:Overrides::Terraform::PropertyOverride - exclude: true + clientId: !ruby/object:Overrides::Terraform::PropertyOverride + custom_flatten: templates/terraform/custom_flatten/name_from_self_link.erb secret: !ruby/object:Overrides::Terraform::PropertyOverride sensitive: true custom_code: !ruby/object:Provider::Terraform::CustomCode post_create: templates/terraform/post_create/iap_client.go.erb custom_import: templates/terraform/custom_import/iap_client.go.erb - extra_schema_entry: templates/terraform/extra_schema_entry/iap_client.erb # This is for copying files over files: !ruby/object:Provider::Config::Files # These files have templating (ERB) code that will be run. diff --git a/templates/terraform/custom_import/iap_client.go.erb b/templates/terraform/custom_import/iap_client.go.erb index 81318d9f5583..9d051f0b8fdb 100644 --- a/templates/terraform/custom_import/iap_client.go.erb +++ b/templates/terraform/custom_import/iap_client.go.erb @@ -9,8 +9,8 @@ nameParts := strings.Split(d.Get("brand").(string), "/") if len(nameParts) != 6 { return nil, fmt.Errorf( "Saw %s when the name is expected to have shape %s", - d.Get("name"), - "{{brand}}/identityAwareProxyClients/{{client_id}}", + d.Get("brand").(string), + "projects/{{project_number}}/brands/{{brand_id}}/identityAwareProxyClients/{{client_id}}", ) } diff --git a/templates/terraform/extra_schema_entry/iap_client.erb b/templates/terraform/extra_schema_entry/iap_client.erb deleted file mode 100644 index 24f7c97bd06b..000000000000 --- a/templates/terraform/extra_schema_entry/iap_client.erb +++ /dev/null @@ -1,4 +0,0 @@ -"client_id": { - Type: schema.TypeString, - Computed: true, -}, diff --git a/templates/terraform/post_create/iap_client.go.erb b/templates/terraform/post_create/iap_client.go.erb index d48209b0140f..40e3123eae1e 100644 --- a/templates/terraform/post_create/iap_client.go.erb +++ b/templates/terraform/post_create/iap_client.go.erb @@ -1,18 +1,5 @@ -// `name` is autogenerated from the api so needs to be set post-create -name, ok := res["name"] -if !ok { - return fmt.Errorf("Create response didn't contain critical fields. Create may not have succeeded.") -} +brand := d.Get("brand") +clientId := flattenIapClientClientId(res["name"], d, config) -nameParts := strings.Split(name.(string), "/") -if len(nameParts) != 6 { - return fmt.Errorf( - "Saw %s when the name is expected to have shape %s", - d.Get("name"), - "{{brand}}/identityAwareProxyClients/{{client_id}}", - ) -} - -log.Printf("[DEBUG] Setting client_id to %s", nameParts[5]) -d.Set("client_id", nameParts[5]) -d.SetId(name.(string)) +d.Set("client_id", clientId) +d.SetId(fmt.Sprintf("%s/identityAwareProxyClients/%s", brand, clientId))