From cc980e50266f10d675e8bcc2bbad9db63fe2ce75 Mon Sep 17 00:00:00 2001 From: Dana Hoffman Date: Mon, 4 Nov 2019 16:16:26 -0800 Subject: [PATCH] =?UTF-8?q?remove=20long=20name=20behavior=20for=20pubsub?= =?UTF-8?q?=20subscriptions,=20clean=20up=20cu=E2=80=A6=20(#2561)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * remove long name behavior for pubsub subscriptions, clean up custom expanders * fix build * fix tests --- products/binaryauthorization/terraform.yaml | 2 +- products/cloudscheduler/terraform.yaml | 2 +- products/compute/terraform.yaml | 16 ++++++--- products/pubsub/terraform.yaml | 3 +- products/redis/terraform.yaml | 2 +- products/sourcerepo/terraform.yaml | 2 +- provider/terraform/sub_template.rb | 5 +-- .../binaryauthorization_attestor_name.erb | 17 --------- .../custom_expand/cloudscheduler_job_name.erb | 35 ------------------ .../computed_subscription_name.erb | 36 ------------------- .../custom_expand/monitoring_group_name.erb | 26 -------------- .../custom_expand/redis_instance_name.erb | 27 -------------- .../repository_name_from_short_name.go.erb | 17 --------- .../terraform/custom_expand/route_gateway.erb | 6 +--- .../custom_expand/shortname_to_url.go.erb | 17 +++++++++ .../custom_expand/spanner_instance_config.go | 27 -------------- .../url_map_only_set_string.go.erb | 19 ---------- .../terraform/expand_property_method.erb | 5 +-- templates/terraform/objectlib/base.go.erb | 2 +- templates/terraform/resource.erb | 2 +- .../resource_pubsub_subscription_test.go | 30 +++++----------- third_party/terraform/utils/pubsub_utils.go | 10 ------ 22 files changed, 52 insertions(+), 256 deletions(-) delete mode 100644 templates/terraform/custom_expand/binaryauthorization_attestor_name.erb delete mode 100644 templates/terraform/custom_expand/cloudscheduler_job_name.erb delete mode 100644 templates/terraform/custom_expand/computed_subscription_name.erb delete mode 100644 templates/terraform/custom_expand/monitoring_group_name.erb delete mode 100644 templates/terraform/custom_expand/redis_instance_name.erb delete mode 100644 templates/terraform/custom_expand/repository_name_from_short_name.go.erb create mode 100644 templates/terraform/custom_expand/shortname_to_url.go.erb delete mode 100644 templates/terraform/custom_expand/spanner_instance_config.go delete mode 100644 templates/terraform/custom_expand/url_map_only_set_string.go.erb diff --git a/products/binaryauthorization/terraform.yaml b/products/binaryauthorization/terraform.yaml index 7408351a5dc7..f2f06bdeabd0 100644 --- a/products/binaryauthorization/terraform.yaml +++ b/products/binaryauthorization/terraform.yaml @@ -38,7 +38,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides properties: name: !ruby/object:Overrides::Terraform::PropertyOverride custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb' - custom_expand: 'templates/terraform/custom_expand/binaryauthorization_attestor_name.erb' + custom_expand: 'templates/terraform/custom_expand/shortname_to_url.go.erb' attestationAuthorityNote.noteReference: !ruby/object:Overrides::Terraform::PropertyOverride custom_expand: 'templates/terraform/custom_expand/container_analysis_note.erb' diff_suppress_func: 'compareSelfLinkOrResourceName' diff --git a/products/cloudscheduler/terraform.yaml b/products/cloudscheduler/terraform.yaml index 943c4c74597d..334700bb06df 100644 --- a/products/cloudscheduler/terraform.yaml +++ b/products/cloudscheduler/terraform.yaml @@ -50,7 +50,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides job_name: "test-job" properties: name: !ruby/object:Overrides::Terraform::PropertyOverride - custom_expand: 'templates/terraform/custom_expand/cloudscheduler_job_name.erb' + custom_expand: 'templates/terraform/custom_expand/shortname_to_url.go.erb' custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb' httpTarget.headers: !ruby/object:Overrides::Terraform::PropertyOverride custom_flatten: 'templates/terraform/custom_flatten/http_headers.erb' diff --git a/products/compute/terraform.yaml b/products/compute/terraform.yaml index e235ddd315ae..89fc6e719f99 100644 --- a/products/compute/terraform.yaml +++ b/products/compute/terraform.yaml @@ -1939,7 +1939,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides id: !ruby/object:Overrides::Terraform::PropertyOverride name: "map_id" defaultService: !ruby/object:Overrides::Terraform::PropertyOverride - custom_expand: 'templates/terraform/custom_expand/url_map_only_set_string.go.erb' + # ResourceRef only supports 1 type and UrlMap has references to a BackendBucket or BackendService. + # Just read the self_link string instead of extracting the name and making a self_link out of it. + custom_expand: 'templates/terraform/custom_expand/resourceref_as_string.go.erb' description: The backend service or backend bucket to use when none of the given rules match. hostRules: !ruby/object:Overrides::Terraform::PropertyOverride name: "host_rule" @@ -1949,17 +1951,23 @@ overrides: !ruby/object:Overrides::ResourceOverrides pathMatchers: !ruby/object:Overrides::Terraform::PropertyOverride name: "path_matcher" pathMatchers.defaultService: !ruby/object:Overrides::Terraform::PropertyOverride - custom_expand: 'templates/terraform/custom_expand/url_map_only_set_string.go.erb' + # ResourceRef only supports 1 type and UrlMap has references to a BackendBucket or BackendService. + # Just read the self_link string instead of extracting the name and making a self_link out of it. + custom_expand: 'templates/terraform/custom_expand/resourceref_as_string.go.erb' description: The backend service or backend bucket to use when none of the given paths match. pathMatchers.pathRules: !ruby/object:Overrides::Terraform::PropertyOverride name: "path_rule" pathMatchers.pathRules.paths: !ruby/object:Overrides::Terraform::PropertyOverride is_set: true pathMatchers.pathRules.service: !ruby/object:Overrides::Terraform::PropertyOverride - custom_expand: 'templates/terraform/custom_expand/url_map_only_set_string.go.erb' + # ResourceRef only supports 1 type and UrlMap has references to a BackendBucket or BackendService. + # Just read the self_link string instead of extracting the name and making a self_link out of it. + custom_expand: 'templates/terraform/custom_expand/resourceref_as_string.go.erb' description: The backend service or backend bucket to use if any of the given paths match. tests.service: !ruby/object:Overrides::Terraform::PropertyOverride - custom_expand: 'templates/terraform/custom_expand/url_map_only_set_string.go.erb' + # ResourceRef only supports 1 type and UrlMap has references to a BackendBucket or BackendService. + # Just read the self_link string instead of extracting the name and making a self_link out of it. + custom_expand: 'templates/terraform/custom_expand/resourceref_as_string.go.erb' description: The backend service or backend bucket link that should be matched by this test. tests: !ruby/object:Overrides::Terraform::PropertyOverride name: "test" diff --git a/products/pubsub/terraform.yaml b/products/pubsub/terraform.yaml index 6c0d8fd52857..b4dcbffb8646 100644 --- a/products/pubsub/terraform.yaml +++ b/products/pubsub/terraform.yaml @@ -77,8 +77,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides * `path`: Path of the subscription in the format `projects/{project}/subscriptions/{name}` properties: name: !ruby/object:Overrides::Terraform::PropertyOverride - diff_suppress_func: 'comparePubsubSubscriptionBasename' - custom_expand: templates/terraform/custom_expand/computed_subscription_name.erb + custom_expand: templates/terraform/custom_expand/shortname_to_url.go.erb custom_flatten: templates/terraform/custom_flatten/name_from_self_link.erb topic: !ruby/object:Overrides::Terraform::PropertyOverride diff_suppress_func: 'compareSelfLinkOrResourceName' diff --git a/products/redis/terraform.yaml b/products/redis/terraform.yaml index 291474d603d1..5c0d7b428c75 100644 --- a/products/redis/terraform.yaml +++ b/products/redis/terraform.yaml @@ -43,7 +43,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides locationId: !ruby/object:Overrides::Terraform::PropertyOverride default_from_api: true name: !ruby/object:Overrides::Terraform::PropertyOverride - custom_expand: 'templates/terraform/custom_expand/redis_instance_name.erb' + custom_expand: 'templates/terraform/custom_expand/shortname_to_url.go.erb' custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb' redisVersion: !ruby/object:Overrides::Terraform::PropertyOverride default_from_api: true diff --git a/products/sourcerepo/terraform.yaml b/products/sourcerepo/terraform.yaml index a03836a963ac..c280265ce574 100644 --- a/products/sourcerepo/terraform.yaml +++ b/products/sourcerepo/terraform.yaml @@ -28,7 +28,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides repository_name: "my-repository" properties: name: !ruby/object:Overrides::Terraform::PropertyOverride - custom_expand: templates/terraform/custom_expand/repository_name_from_short_name.go.erb + custom_expand: templates/terraform/custom_expand/shortname_to_url.go.erb custom_flatten: templates/terraform/custom_flatten/repository_short_name_from_name.go.erb description: | Resource name of the repository, of the form `{{repo}}`. diff --git a/provider/terraform/sub_template.rb b/provider/terraform/sub_template.rb index acff1d4f3466..a4e38113d3d6 100644 --- a/provider/terraform/sub_template.rb +++ b/provider/terraform/sub_template.rb @@ -40,10 +40,11 @@ def build_flatten_method(prefix, property, object) # Transforms a Terraform schema representation of a property into a # representation used by the Cloud API. - def build_expand_method(prefix, property) + def build_expand_method(prefix, property, object) compile_template 'templates/terraform/expand_property_method.erb', prefix: prefix, - property: property + property: property, + object: object end def build_expand_resource_ref(var_name, property) diff --git a/templates/terraform/custom_expand/binaryauthorization_attestor_name.erb b/templates/terraform/custom_expand/binaryauthorization_attestor_name.erb deleted file mode 100644 index 490c24471c7e..000000000000 --- a/templates/terraform/custom_expand/binaryauthorization_attestor_name.erb +++ /dev/null @@ -1,17 +0,0 @@ -<%# The license inside this block applies to this file. - # Copyright 2019 Google Inc. - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. --%> -func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { - return replaceVars(d, config, "projects/{{project}}/attestors/{{name}}") -} diff --git a/templates/terraform/custom_expand/cloudscheduler_job_name.erb b/templates/terraform/custom_expand/cloudscheduler_job_name.erb deleted file mode 100644 index 09e969d101e0..000000000000 --- a/templates/terraform/custom_expand/cloudscheduler_job_name.erb +++ /dev/null @@ -1,35 +0,0 @@ -<%# # the license inside this if block pertains to this file - # Copyright 2018 Google Inc. - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. -#%> -func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { - var jobName string - project, err := getProject(d, config) - if err != nil { - return nil, err - } - - region, err := getRegion(d, config) - if err != nil { - return nil, err - } - - if v, ok := d.GetOk("name"); ok { - jobName = fmt.Sprintf("projects/%s/locations/%s/jobs/%s", project, region, v.(string)) - } else { - err := fmt.Errorf("The name is missing for the job cannot be empty") - return nil, err - } - - return jobName, nil -} diff --git a/templates/terraform/custom_expand/computed_subscription_name.erb b/templates/terraform/custom_expand/computed_subscription_name.erb deleted file mode 100644 index 569e688b0fc8..000000000000 --- a/templates/terraform/custom_expand/computed_subscription_name.erb +++ /dev/null @@ -1,36 +0,0 @@ -<%# # the license inside this if block pertains to this file - # Copyright 2018 Google Inc. - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. -#%> -func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { - project, err := getProject(d, config) - if err != nil { - return "", err - } - - subscription := d.Get("name").(string) - - re := regexp.MustCompile("projects\\/(.*)\\/subscriptions\\/(.*)") - match := re.FindStringSubmatch(subscription) - if len(match) == 3 { - // We need to preserve the behavior where the user passes the subscription name already in the long form, - // however we need it to be stored as the short form since it's used for the replaceVars in the URL. - // The unintuitive behavior is that if the user provides the long form, we use the project from there, not the one - // specified on the resource or provider. - // TODO(drebes): consider deprecating the long form behavior for 3.0 - d.Set("project", match[1]) - d.Set("name", match[2]) - return subscription, nil - } - return fmt.Sprintf("projects/%s/subscriptions/%s", project, subscription), nil -} diff --git a/templates/terraform/custom_expand/monitoring_group_name.erb b/templates/terraform/custom_expand/monitoring_group_name.erb deleted file mode 100644 index a08dd8f81523..000000000000 --- a/templates/terraform/custom_expand/monitoring_group_name.erb +++ /dev/null @@ -1,26 +0,0 @@ -<%# The license inside this block applies to this file. - # Copyright 2018 Google Inc. - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. --%> -func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { - project, err := getProject(d, config) - if err != nil { - return nil, err - } - - if v.(string) == "" { - return "", nil - } - - return fmt.Sprintf("projects/%s/groups/%s", project, v.(string)), nil -} \ No newline at end of file diff --git a/templates/terraform/custom_expand/redis_instance_name.erb b/templates/terraform/custom_expand/redis_instance_name.erb deleted file mode 100644 index 20c3b5d983cb..000000000000 --- a/templates/terraform/custom_expand/redis_instance_name.erb +++ /dev/null @@ -1,27 +0,0 @@ -<%# The license inside this block applies to this file. - # Copyright 2017 Google Inc. - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. --%> -func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { - project, err := getProject(d, config) - if err != nil { - return nil, err - } - - region, err := getRegion(d, config) - if err != nil { - return nil, err - } - - return fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, region, v.(string)), nil -} diff --git a/templates/terraform/custom_expand/repository_name_from_short_name.go.erb b/templates/terraform/custom_expand/repository_name_from_short_name.go.erb deleted file mode 100644 index 8cb062a9c936..000000000000 --- a/templates/terraform/custom_expand/repository_name_from_short_name.go.erb +++ /dev/null @@ -1,17 +0,0 @@ -<%# The license inside this block applies to this file. - # Copyright 2017 Google Inc. - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. --%> -func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { - return replaceVars(d, config, "projects/{{project}}/repos/{{name}}") -} diff --git a/templates/terraform/custom_expand/route_gateway.erb b/templates/terraform/custom_expand/route_gateway.erb index d4165dfdbd4d..d0d349dfb472 100644 --- a/templates/terraform/custom_expand/route_gateway.erb +++ b/templates/terraform/custom_expand/route_gateway.erb @@ -1,10 +1,6 @@ func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { if v == "default-internet-gateway" { - project, err := getProject(d, config) - if err != nil { - return nil, err - } - return fmt.Sprintf("projects/%s/global/gateways/default-internet-gateway", project), nil + return replaceVars(d, config, "projects/{{project}}/global/gateways/default-internet-gateway") } else { return v, nil } diff --git a/templates/terraform/custom_expand/shortname_to_url.go.erb b/templates/terraform/custom_expand/shortname_to_url.go.erb new file mode 100644 index 000000000000..2ee215313bd9 --- /dev/null +++ b/templates/terraform/custom_expand/shortname_to_url.go.erb @@ -0,0 +1,17 @@ +<%# # the license inside this if block pertains to this file + # Copyright 2019 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +#%> +func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return replaceVars(d, config, "<%= id_format(object) -%>") +} diff --git a/templates/terraform/custom_expand/spanner_instance_config.go b/templates/terraform/custom_expand/spanner_instance_config.go deleted file mode 100644 index 26707d2b3ca1..000000000000 --- a/templates/terraform/custom_expand/spanner_instance_config.go +++ /dev/null @@ -1,27 +0,0 @@ -<%- # the license inside this block applies to this file - # Copyright 2018 Google Inc. - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. --%> -func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { - r := regexp.MustCompile("projects/(.+)/notes/(.+)") - if r.MatchString(v.(string)) { - return v.(string), nil - } - - project, err := getProject(d, config) - if err != nil { - return nil, err - } - - return fmt.Sprintf("projects/%s/notes/%s", project, v.(string)), nil -} diff --git a/templates/terraform/custom_expand/url_map_only_set_string.go.erb b/templates/terraform/custom_expand/url_map_only_set_string.go.erb deleted file mode 100644 index 3f021c9cf97b..000000000000 --- a/templates/terraform/custom_expand/url_map_only_set_string.go.erb +++ /dev/null @@ -1,19 +0,0 @@ -<%# The license inside this block applies to this file. - # Copyright 2017 Google Inc. - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. --%> -// ResourceRef only supports 1 type and UrlMap has references to a BackendBucket or BackendService. Just read the self_link string -// instead of extracting the name and making a self_link out of it. -func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { - return v, nil -} diff --git a/templates/terraform/expand_property_method.erb b/templates/terraform/expand_property_method.erb index 4dc6b09518b5..63cbee02bd7c 100644 --- a/templates/terraform/expand_property_method.erb +++ b/templates/terraform/expand_property_method.erb @@ -15,7 +15,8 @@ <% if property.custom_expand -%> <%= lines(compile_template(property.custom_expand, prefix: prefix, - property: property)) -%> + property: property, + object: object)) -%> <% else -%> <%# Generate expanders for Maps %> @@ -176,7 +177,7 @@ func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d T <%# Map is a map from {key -> object} in the API, but Terraform can't represent that so we treat the key as a property of the object in Terraform schema. %> <% next if property.is_a?(Api::Type::Map) && prop.name == property.key_name -%> -<%= lines(build_expand_method(prefix + titlelize_property(property), prop), 1) -%> +<%= lines(build_expand_method(prefix + titlelize_property(property), prop, object), 1) -%> <% end -%> <% end -%> diff --git a/templates/terraform/objectlib/base.go.erb b/templates/terraform/objectlib/base.go.erb index 1f097d68ecf3..14018e5b4020 100644 --- a/templates/terraform/objectlib/base.go.erb +++ b/templates/terraform/objectlib/base.go.erb @@ -67,6 +67,6 @@ func resource<%= resource_name -%>Encoder(d TerraformResourceData, meta interfac <% end -%> <% object.settable_properties.each do |prop| -%> -<%= lines(build_expand_method(resource_name, prop), 1) -%> +<%= lines(build_expand_method(resource_name, prop, object), 1) -%> <% end -%> diff --git a/templates/terraform/resource.erb b/templates/terraform/resource.erb index 180b1f54af0b..8e2c54184cad 100644 --- a/templates/terraform/resource.erb +++ b/templates/terraform/resource.erb @@ -654,7 +654,7 @@ func resource<%= resource_name -%>Import(d *schema.ResourceData, meta interface{ <% end -%> <% object.settable_properties.each do |prop| -%> -<%= lines(build_expand_method(resource_name, prop), 1) -%> +<%= lines(build_expand_method(resource_name, prop, object), 1) -%> <% end -%> <% if object.custom_code.encoder -%> diff --git a/third_party/terraform/tests/resource_pubsub_subscription_test.go b/third_party/terraform/tests/resource_pubsub_subscription_test.go index 71e3cef79e57..96289ac04991 100644 --- a/third_party/terraform/tests/resource_pubsub_subscription_test.go +++ b/third_party/terraform/tests/resource_pubsub_subscription_test.go @@ -12,7 +12,7 @@ func TestAccPubsubSubscription_emptyTTL(t *testing.T) { t.Parallel() topic := fmt.Sprintf("tf-test-topic-%s", acctest.RandString(10)) - subscription := fmt.Sprintf("projects/%s/subscriptions/tf-test-sub-%s", getTestProjectFromEnv(), acctest.RandString(10)) + subscription := fmt.Sprintf("tf-test-sub-%s", acctest.RandString(10)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -32,11 +32,11 @@ func TestAccPubsubSubscription_emptyTTL(t *testing.T) { }) } -func TestAccPubsubSubscription_fullName(t *testing.T) { +func TestAccPubsubSubscription_basic(t *testing.T) { t.Parallel() topic := fmt.Sprintf("tf-test-topic-%s", acctest.RandString(10)) - subscription := fmt.Sprintf("projects/%s/subscriptions/tf-test-sub-%s", getTestProjectFromEnv(), acctest.RandString(10)) + subscription := fmt.Sprintf("tf-test-sub-%s", acctest.RandString(10)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -44,7 +44,7 @@ func TestAccPubsubSubscription_fullName(t *testing.T) { CheckDestroy: testAccCheckPubsubSubscriptionDestroy, Steps: []resource.TestStep{ { - Config: testAccPubsubSubscription_fullName(topic, subscription, "bar", 20), + Config: testAccPubsubSubscription_basic(topic, subscription, "bar", 20), }, { ResourceName: "google_pubsub_subscription.foo", @@ -69,28 +69,16 @@ func TestAccPubsubSubscription_update(t *testing.T) { CheckDestroy: testAccCheckPubsubSubscriptionDestroy, Steps: []resource.TestStep{ { - Config: testAccPubsubSubscription_fullName(topic, subscriptionLong, "bar", 20), + Config: testAccPubsubSubscription_basic(topic, subscriptionShort, "bar", 20), }, { ResourceName: "google_pubsub_subscription.foo", - ImportStateId: subscriptionLong, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccPubsubSubscription_fullName(topic, subscriptionLong, "baz", 30), - Check: resource.TestCheckResourceAttr( - "google_pubsub_subscription.foo", "path", subscriptionLong, - ), - }, - { - ResourceName: "google_pubsub_subscription.foo", - ImportStateId: subscriptionLong, + ImportStateId: subscriptionShort, ImportState: true, ImportStateVerify: true, }, { - Config: testAccPubsubSubscription_fullName(topic, subscriptionShort, "baz", 30), + Config: testAccPubsubSubscription_basic(topic, subscriptionShort, "baz", 30), Check: resource.TestCheckResourceAttr( "google_pubsub_subscription.foo", "path", subscriptionLong, ), @@ -109,7 +97,7 @@ func TestAccPubsubSubscription_push(t *testing.T) { t.Parallel() topicFoo := fmt.Sprintf("tf-test-topic-foo-%s", acctest.RandString(10)) - subscription := fmt.Sprintf("projects/%s/subscriptions/tf-test-topic-foo-%s", getTestProjectFromEnv(), acctest.RandString(10)) + subscription := fmt.Sprintf("tf-test-topic-foo-%s", acctest.RandString(10)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -183,7 +171,7 @@ resource "google_pubsub_subscription" "foo" { `, topicFoo, subscription) } -func testAccPubsubSubscription_fullName(topic, subscription, label string, deadline int) string { +func testAccPubsubSubscription_basic(topic, subscription, label string, deadline int) string { return fmt.Sprintf(` resource "google_pubsub_topic" "foo" { name = "%s" diff --git a/third_party/terraform/utils/pubsub_utils.go b/third_party/terraform/utils/pubsub_utils.go index 83573d211e26..592fc57bc309 100644 --- a/third_party/terraform/utils/pubsub_utils.go +++ b/third_party/terraform/utils/pubsub_utils.go @@ -3,18 +3,8 @@ package google import ( "fmt" "regexp" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func comparePubsubSubscriptionBasename(_, old, new string, _ *schema.ResourceData) bool { - if GetResourceNameFromSelfLink(old) == GetResourceNameFromSelfLink(new) { - return true - } - - return false -} - func getComputedSubscriptionName(project, subscription string) string { match, _ := regexp.MatchString("projects\\/.*\\/subscriptions\\/.*", subscription) if match {