From 4c7f4993a9929d5c094fb100d59021bb6f774aad Mon Sep 17 00:00:00 2001 From: upodroid Date: Fri, 11 Jun 2021 11:25:05 +0100 Subject: [PATCH 1/4] initial Dataset Co-authored-by: upodroid --- mmv1/products/vertexai/api.yaml | 105 ++++++++++++++++++ mmv1/products/vertexai/terraform.yaml | 45 ++++++++ .../examples/vertex_ai_dataset.tf.erb | 5 + 3 files changed, 155 insertions(+) create mode 100644 mmv1/products/vertexai/api.yaml create mode 100644 mmv1/products/vertexai/terraform.yaml create mode 100644 mmv1/templates/terraform/examples/vertex_ai_dataset.tf.erb diff --git a/mmv1/products/vertexai/api.yaml b/mmv1/products/vertexai/api.yaml new file mode 100644 index 000000000000..a56222bc3731 --- /dev/null +++ b/mmv1/products/vertexai/api.yaml @@ -0,0 +1,105 @@ +# 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. + +--- !ruby/object:Api::Product +name: VertexAI +display_name: Vertex AI +versions: + - !ruby/object:Api::Product::Version + name: ga + base_url: https://{{location}}-aiplatform.googleapis.com/v1/ + # - !ruby/object:Api::Product::Version + # name: beta + # base_url: https://{{location}}-aiplatform.googleapis.com/v1beta1/ +scopes: + - https://www.googleapis.com/auth/cloud-platform +objects: +# Vertex AI Datasets + - !ruby/object:Api::Resource + name: Dataset + base_url: projects/{{project}}/locations/{{region}}/datasets + self_link: '{{name}}' + update_verb: :PATCH + update_mask: true + references: !ruby/object:Api::Resource::ReferenceLinks + guides: + 'Official Documentation': + 'https://cloud.google.com/vertex-ai/docs' + api: 'https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.datasets' + async: !ruby/object:Api::OpAsync + operation: !ruby/object:Api::OpAsync::Operation + path: 'name' + base_url: '{{op_id}}' + wait_ms: 1000 + result: !ruby/object:Api::OpAsync::Result + path: 'response' + resource_inside_response: true + status: !ruby/object:Api::OpAsync::Status + path: 'done' + complete: True + allowed: + - True + - False + error: !ruby/object:Api::OpAsync::Error + path: 'error' + message: 'message' + description: |- + A collection of DataItems and Annotations on them. + parameters: + - !ruby/object:Api::Type::String + name: location + description: The location of the dataset. eg us-central1 + url_param_only: true + required: true + properties: + - !ruby/object:Api::Type::String + name: 'name' + description: The resource name of the Dataset. This value is set by Google. + output: true + - !ruby/object:Api::Type::String + name: 'displayName' + required: true + description: | + The user-defined name of the Dataset. The name can be up to 128 characters long and can be consist of any UTF-8 characters. + - !ruby/object:Api::Type::String + name: 'createTime' + output: true + description: | + The timestamp of when the workflow was created in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. + - !ruby/object:Api::Type::String + name: 'updateTime' + output: true + description: | + The timestamp of when the workflow was last updated in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. + - !ruby/object:Api::Type::KeyValuePairs + name: 'labels' + description: | + A set of key/value label pairs to assign to this Workflow. + - !ruby/object:Api::Type::NestedObject + name: 'encryptionSpec' + input: true + description: | + Customer-managed encryption key spec for a Dataset. If set, this Dataset and all sub-resources of this Dataset will be secured by this key. + properties: + - !ruby/object:Api::Type::String + name: 'kmsKeyName' + description: | + Required. The Cloud KMS resource identifier of the customer managed encryption key used to protect a resource. + Has the form: projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key. The key needs to be in the same region as where the resource is created. + input: true + - !ruby/object:Api::Type::String + name: 'metadataSchemaUri' + required: true + input: true + description: | + Points to a YAML file stored on Google Cloud Storage describing additional information about the Dataset. The schema is defined as an OpenAPI 3.0.2 Schema Object. The schema files that can be used here are found in gs://google-cloud-aiplatform/schema/dataset/metadata/. \ No newline at end of file diff --git a/mmv1/products/vertexai/terraform.yaml b/mmv1/products/vertexai/terraform.yaml new file mode 100644 index 000000000000..7437ae9fa1cf --- /dev/null +++ b/mmv1/products/vertexai/terraform.yaml @@ -0,0 +1,45 @@ +# Copyright 2021 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. + +--- !ruby/object:Provider::Terraform::Config +overrides: !ruby/object:Overrides::ResourceOverrides + Dataset: !ruby/object:Overrides::Terraform::ResourceOverride + autogen_async: true + id_format: '{{name}}' + timeouts: !ruby/object:Api::Timeouts + insert_minutes: 6 + update_minutes: 6 + delete_minutes: 10 + examples: + - !ruby/object:Provider::Terraform::Examples + name: "vertex_ai_dataset" + primary_resource_id: "dataset" + vars: + display_name: "terraform" + custom_code: !ruby/object:Provider::Terraform::CustomCode + encoder: templates/terraform/encoders/no_send_name.go.erb + post_create: templates/terraform/post_create/sleep.go.erb + decoder: templates/terraform/decoders/long_name_to_self_link.go.erb + properties: + name: !ruby/object:Overrides::Terraform::PropertyOverride + custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb' + labels: !ruby/object:Overrides::Terraform::PropertyOverride + default_from_api: true + + +# This is for copying files over +files: !ruby/object:Provider::Config::Files + # These files have templating (ERB) code that will be run. + # This is usually to add licensing info, autogeneration notices, etc. + compile: +<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> diff --git a/mmv1/templates/terraform/examples/vertex_ai_dataset.tf.erb b/mmv1/templates/terraform/examples/vertex_ai_dataset.tf.erb new file mode 100644 index 000000000000..6cc49d3809a1 --- /dev/null +++ b/mmv1/templates/terraform/examples/vertex_ai_dataset.tf.erb @@ -0,0 +1,5 @@ +resource "google_vertex_ai_dataset" "dataset" { + display_name = "<%= ctx[:vars]['display_name'] %>" + metadata_schema_uri = "gs://google-cloud-aiplatform/schema/dataset/metadata/image_1.0.0.yaml" + location = "us-central1" +} From 6a5cf824fca8ed18f7eef2a67c5be43f339674ad Mon Sep 17 00:00:00 2001 From: upodroid Date: Mon, 14 Jun 2021 12:30:25 +0100 Subject: [PATCH 2/4] pass d to OperationWaiters --- mmv1/products/vertexai/api.yaml | 10 ++--- mmv1/products/vertexai/terraform.yaml | 12 +++-- .../active_directory_domain_trust.go.erb | 2 +- .../custom_delete/appversion_delete.go.erb | 4 +- .../custom_delete/per_instance_config.go.erb | 4 +- .../region_per_instance_config.go.erb | 4 +- ...eplace_all_access_levels_empty_list.go.erb | 2 +- ...e_all_service_perimeters_empty_list.go.erb | 2 +- .../examples/vertex_ai_dataset.tf.erb | 2 +- mmv1/templates/terraform/operation.go.erb | 22 +++++++--- ...ute_backend_service_security_policy.go.erb | 2 +- .../compute_network_delete_default_route.erb | 2 +- .../terraform/post_create/labels.erb | 2 +- .../post_create/org_security_policy.go.erb | 2 +- .../org_security_policy_association.go.erb | 2 +- .../org_security_policy_rule.go.erb | 2 +- .../post_delete/org_security_policy.go.erb | 2 +- .../compute_per_instance_config.go.erb | 2 +- .../compute_region_per_instance_config.go.erb | 2 +- .../post_update/org_security_policy.go.erb | 2 +- .../terraform/pre_delete/detach_disk.erb | 2 +- .../privateca_certificate_authority.go.erb | 2 +- mmv1/templates/terraform/resource.erb | 10 ++--- .../resource_app_engine_application.go | 4 +- .../resource_compute_attached_disk.go | 4 +- .../resources/resource_compute_instance.go | 40 ++++++++--------- ...compute_instance_from_machine_image.go.erb | 2 +- ...resource_compute_instance_from_template.go | 2 +- .../resource_compute_instance_group.go | 12 ++--- ...urce_compute_instance_group_manager.go.erb | 14 +++--- .../resource_compute_instance_template.go.erb | 4 +- .../resource_compute_network_peering.go | 6 +-- ...ce_compute_project_default_network_tier.go | 2 +- .../resource_compute_project_metadata.go | 8 ++-- .../resource_compute_project_metadata_item.go | 10 ++--- ...mpute_region_instance_group_manager.go.erb | 10 ++--- .../resource_compute_router_interface.go | 4 +- .../resource_compute_security_policy.go.erb | 12 ++--- ...esource_compute_shared_vpc_host_project.go | 4 +- ...urce_compute_shared_vpc_service_project.go | 4 +- .../resources/resource_compute_target_pool.go | 14 +++--- .../resources/resource_google_folder.go | 4 +- .../resources/resource_google_project.go | 20 ++++----- .../resource_google_project_service.go | 2 +- .../resource_project_service_identity.go.erb | 2 +- .../resource_service_networking_connection.go | 6 +-- .../resource_sql_database_instance.go.erb | 12 ++--- .../resources/resource_sql_ssl_cert.go | 4 +- .../terraform/resources/resource_sql_user.go | 6 +-- .../resources/resource_usage_export_bucket.go | 4 +- .../resource_composer_environment_test.go.erb | 3 +- .../resource_compute_instance_migrate_test.go | 44 ++++++++++++------- .../tests/resource_compute_instance_test.go | 6 ++- ...resource_sql_database_instance_test.go.erb | 7 +-- .../terraform/utils/appengine_operation.go | 8 +++- .../terraform/utils/bootstrap_utils_test.go | 9 ++-- ...pute_instance_network_interface_helpers.go | 6 +-- .../terraform/utils/compute_operation.go.erb | 7 ++- .../utils/compute_shared_operation.go | 4 -- .../utils/deployment_manager_operation.go.erb | 4 +- .../utils/service_networking_operation.go | 5 ++- .../terraform/utils/serviceusage_batching.go | 10 ++--- .../terraform/utils/serviceusage_operation.go | 5 ++- .../terraform/utils/sqladmin_operation.go | 5 ++- 64 files changed, 237 insertions(+), 200 deletions(-) delete mode 100644 mmv1/third_party/terraform/utils/compute_shared_operation.go diff --git a/mmv1/products/vertexai/api.yaml b/mmv1/products/vertexai/api.yaml index a56222bc3731..3324192dd83f 100644 --- a/mmv1/products/vertexai/api.yaml +++ b/mmv1/products/vertexai/api.yaml @@ -17,10 +17,10 @@ display_name: Vertex AI versions: - !ruby/object:Api::Product::Version name: ga - base_url: https://{{location}}-aiplatform.googleapis.com/v1/ + base_url: https://{{region}}-aiplatform.googleapis.com/v1/ # - !ruby/object:Api::Product::Version # name: beta - # base_url: https://{{location}}-aiplatform.googleapis.com/v1beta1/ + # base_url: https://{{region}}-aiplatform.googleapis.com/v1beta1/ scopes: - https://www.googleapis.com/auth/cloud-platform objects: @@ -57,10 +57,10 @@ objects: A collection of DataItems and Annotations on them. parameters: - !ruby/object:Api::Type::String - name: location - description: The location of the dataset. eg us-central1 + name: region + description: The region of the dataset. eg us-central1 url_param_only: true - required: true + input: true properties: - !ruby/object:Api::Type::String name: 'name' diff --git a/mmv1/products/vertexai/terraform.yaml b/mmv1/products/vertexai/terraform.yaml index 7437ae9fa1cf..9a96715d2efb 100644 --- a/mmv1/products/vertexai/terraform.yaml +++ b/mmv1/products/vertexai/terraform.yaml @@ -16,6 +16,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides Dataset: !ruby/object:Overrides::Terraform::ResourceOverride autogen_async: true id_format: '{{name}}' + exclude_import: true + # import_format: ["projects/{{project}}/locations/{{region}}/datasets/{{name}}"] timeouts: !ruby/object:Api::Timeouts insert_minutes: 6 update_minutes: 6 @@ -23,19 +25,15 @@ overrides: !ruby/object:Overrides::ResourceOverrides examples: - !ruby/object:Provider::Terraform::Examples name: "vertex_ai_dataset" + # skip_import_test: true primary_resource_id: "dataset" vars: display_name: "terraform" - custom_code: !ruby/object:Provider::Terraform::CustomCode - encoder: templates/terraform/encoders/no_send_name.go.erb - post_create: templates/terraform/post_create/sleep.go.erb - decoder: templates/terraform/decoders/long_name_to_self_link.go.erb properties: - name: !ruby/object:Overrides::Terraform::PropertyOverride - custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb' labels: !ruby/object:Overrides::Terraform::PropertyOverride default_from_api: true - + region: !ruby/object:Overrides::Terraform::PropertyOverride + default_from_api: true # This is for copying files over files: !ruby/object:Provider::Config::Files diff --git a/mmv1/templates/terraform/custom_delete/active_directory_domain_trust.go.erb b/mmv1/templates/terraform/custom_delete/active_directory_domain_trust.go.erb index 0bacbeccb950..7ce571b8031e 100644 --- a/mmv1/templates/terraform/custom_delete/active_directory_domain_trust.go.erb +++ b/mmv1/templates/terraform/custom_delete/active_directory_domain_trust.go.erb @@ -61,7 +61,7 @@ } err = activeDirectoryOperationWaitTime( - config, res, project, "Deleting DomainTrust", userAgent, + d, config, res, project, "Deleting DomainTrust", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { diff --git a/mmv1/templates/terraform/custom_delete/appversion_delete.go.erb b/mmv1/templates/terraform/custom_delete/appversion_delete.go.erb index b94147861ed8..c9ffefefdbf4 100644 --- a/mmv1/templates/terraform/custom_delete/appversion_delete.go.erb +++ b/mmv1/templates/terraform/custom_delete/appversion_delete.go.erb @@ -28,7 +28,7 @@ if d.Get("delete_service_on_destroy") == true { return handleNotFoundError(err, d, "Service") } err = appEngineOperationWaitTime( - config, res, project, "Deleting Service", userAgent, + d, config, res, project, "Deleting Service", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { @@ -48,7 +48,7 @@ if d.Get("delete_service_on_destroy") == true { return handleNotFoundError(err, d, "AppVersion") } err = appEngineOperationWaitTime( - config, res, project, "Deleting AppVersion", userAgent, + d, config, res, project, "Deleting AppVersion", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { diff --git a/mmv1/templates/terraform/custom_delete/per_instance_config.go.erb b/mmv1/templates/terraform/custom_delete/per_instance_config.go.erb index a26ec6399e2d..639370350731 100644 --- a/mmv1/templates/terraform/custom_delete/per_instance_config.go.erb +++ b/mmv1/templates/terraform/custom_delete/per_instance_config.go.erb @@ -27,7 +27,7 @@ } err = computeOperationWaitTime( - config, res, project, "Deleting PerInstanceConfig", userAgent, + d, config, res, project, "Deleting PerInstanceConfig", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { @@ -59,7 +59,7 @@ } err = computeOperationWaitTime( - config, res, project, "Applying update to PerInstanceConfig", userAgent, + d, config, res, project, "Applying update to PerInstanceConfig", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return fmt.Errorf("Error deleting PerInstanceConfig %q: %s", d.Id(), err) diff --git a/mmv1/templates/terraform/custom_delete/region_per_instance_config.go.erb b/mmv1/templates/terraform/custom_delete/region_per_instance_config.go.erb index bb9c09db776b..a31e6d0f63a5 100644 --- a/mmv1/templates/terraform/custom_delete/region_per_instance_config.go.erb +++ b/mmv1/templates/terraform/custom_delete/region_per_instance_config.go.erb @@ -27,7 +27,7 @@ } err = computeOperationWaitTime( - config, res, project, "Deleting RegionPerInstanceConfig", userAgent, + d, config, res, project, "Deleting RegionPerInstanceConfig", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { @@ -59,7 +59,7 @@ } err = computeOperationWaitTime( - config, res, project, "Applying update to PerInstanceConfig", userAgent, + d, config, res, project, "Applying update to PerInstanceConfig", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { diff --git a/mmv1/templates/terraform/custom_delete/replace_all_access_levels_empty_list.go.erb b/mmv1/templates/terraform/custom_delete/replace_all_access_levels_empty_list.go.erb index 25c5e2f8c1b0..8a80b9caf8c1 100644 --- a/mmv1/templates/terraform/custom_delete/replace_all_access_levels_empty_list.go.erb +++ b/mmv1/templates/terraform/custom_delete/replace_all_access_levels_empty_list.go.erb @@ -16,7 +16,7 @@ if err != nil { } err = accessContextManagerOperationWaitTime( - config, res, "Updating AccessLevels", userAgent, + d, config, res, "Updating AccessLevels", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { diff --git a/mmv1/templates/terraform/custom_delete/replace_all_service_perimeters_empty_list.go.erb b/mmv1/templates/terraform/custom_delete/replace_all_service_perimeters_empty_list.go.erb index 452afec19731..59103e11f7ce 100644 --- a/mmv1/templates/terraform/custom_delete/replace_all_service_perimeters_empty_list.go.erb +++ b/mmv1/templates/terraform/custom_delete/replace_all_service_perimeters_empty_list.go.erb @@ -16,7 +16,7 @@ if err != nil { } err = accessContextManagerOperationWaitTime( - config, res, "Updating ServicePerimeters", userAgent, + d, config, res, "Updating ServicePerimeters", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { diff --git a/mmv1/templates/terraform/examples/vertex_ai_dataset.tf.erb b/mmv1/templates/terraform/examples/vertex_ai_dataset.tf.erb index 6cc49d3809a1..e5a5828cf0a2 100644 --- a/mmv1/templates/terraform/examples/vertex_ai_dataset.tf.erb +++ b/mmv1/templates/terraform/examples/vertex_ai_dataset.tf.erb @@ -1,5 +1,5 @@ resource "google_vertex_ai_dataset" "dataset" { display_name = "<%= ctx[:vars]['display_name'] %>" metadata_schema_uri = "gs://google-cloud-aiplatform/schema/dataset/metadata/image_1.0.0.yaml" - location = "us-central1" + region = "us-central1" } diff --git a/mmv1/templates/terraform/operation.go.erb b/mmv1/templates/terraform/operation.go.erb index 55dad8bcb4a0..4f2ee191510d 100644 --- a/mmv1/templates/terraform/operation.go.erb +++ b/mmv1/templates/terraform/operation.go.erb @@ -16,6 +16,7 @@ type <%= product_name -%>OperationWaiter struct { Project string <% end -%> CommonOperationWaiter + d *schema.ResourceData } func (w *<%= product_name -%>OperationWaiter) QueryOp() (interface{}, error) { @@ -25,16 +26,23 @@ func (w *<%= product_name -%>OperationWaiter) QueryOp() (interface{}, error) { // Returns the proper get. url := fmt.Sprintf("<%= [object.__product.base_url, async.operation.base_url].flatten.join.gsub('{{op_id}}', '%s') -%>", w.CommonOperationWaiter.Op.Name) - return sendRequest(w.Config, "GET", <% if has_project %>w.Project<% else %>""<% end %>, url, w.UserAgent, nil<%= object.error_retry_predicates ? ", " + object.error_retry_predicates.join(',') : "" -%>) + // This is for regional API endpoints like Vertex AI that need to infer the subdomain prefix in *.googleapis.com from d such as https://{{region}}-aiplatform.googleapis.com/v1/ + parsedUrl, err := replaceVars(w.d, w.Config, url) + if err != nil { + return nil, err + } + + return sendRequest(w.Config, "GET", <% if has_project %>w.Project<% else %>""<% end %>, parsedUrl, w.UserAgent, nil<%= object.error_retry_predicates ? ", " + object.error_retry_predicates.join(',') : "" -%>) } -func create<%= product_name %>Waiter(config *Config, op map[string]interface{}, <% if has_project -%> project, <% end -%> activity, userAgent string) (*<%=product_name%>OperationWaiter, error) { +func create<%= product_name %>Waiter(d *schema.ResourceData, config *Config, op map[string]interface{}, <% if has_project -%> project, <% end -%> activity, userAgent string) (*<%=product_name%>OperationWaiter, error) { w := &<%= product_name -%>OperationWaiter{ Config: config, UserAgent: userAgent, <% if has_project -%> - Project: project, + Project: project, <% end -%> + d: d, } if err := w.CommonOperationWaiter.SetOp(op); err != nil { return nil, err @@ -48,8 +56,8 @@ func create<%= product_name %>Waiter(config *Config, op map[string]interface{}, Might as well just nolint it so we can pass the linter checks. -%> // nolint: deadcode,unused -func <%= product_name.camelize(:lower) -%>OperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{},<% if has_project -%> project,<% end -%> activity, userAgent string, timeout time.Duration) error { - w, err := create<%= product_name %>Waiter(config, op, <% if has_project -%> project, <%end-%> activity, userAgent) +func <%= product_name.camelize(:lower) -%>OperationWaitTimeWithResponse(d *schema.ResourceData, config *Config, op map[string]interface{}, response *map[string]interface{},<% if has_project -%> project,<% end -%> activity, userAgent string, timeout time.Duration) error { + w, err := create<%= product_name %>Waiter(d, config, op, <% if has_project -%> project, <%end-%> activity, userAgent) if err != nil { return err } @@ -60,12 +68,12 @@ func <%= product_name.camelize(:lower) -%>OperationWaitTimeWithResponse(config * } <% end -%> -func <%= product_name.camelize(:lower) -%>OperationWaitTime(config *Config, op map[string]interface{}, <% if has_project -%> project,<% end -%> activity, userAgent string, timeout time.Duration) error { +func <%= product_name.camelize(:lower) -%>OperationWaitTime(d *schema.ResourceData, config *Config, op map[string]interface{}, <% if has_project -%> project,<% end -%> activity, userAgent string, timeout time.Duration) error { if val, ok := op["name"]; !ok || val == "" { // This was a synchronous call - there is no operation to wait for. return nil } - w, err := create<%= product_name %>Waiter(config, op, <% if has_project -%> project, <%end-%> activity, userAgent) + w, err := create<%= product_name %>Waiter(d, config, op, <% if has_project -%> project, <%end-%> activity, userAgent) if err != nil { // If w is nil, the op was synchronous. return err diff --git a/mmv1/templates/terraform/post_create/compute_backend_service_security_policy.go.erb b/mmv1/templates/terraform/post_create/compute_backend_service_security_policy.go.erb index 28008867463e..ffd9cf70f44a 100644 --- a/mmv1/templates/terraform/post_create/compute_backend_service_security_policy.go.erb +++ b/mmv1/templates/terraform/post_create/compute_backend_service_security_policy.go.erb @@ -12,7 +12,7 @@ if o, n := d.GetChange("security_policy"); o.(string) != n.(string) { return errwrap.Wrapf("Error setting Backend Service security policy: {{err}}", err) } // This uses the create timeout for simplicity, though technically this code appears in both create and update - waitErr := computeOperationWaitTime(config, op, project, "Setting Backend Service Security Policy", userAgent, d.Timeout(schema.TimeoutCreate)) + waitErr := computeOperationWaitTime(d, config, op, project, "Setting Backend Service Security Policy", userAgent, d.Timeout(schema.TimeoutCreate)) if waitErr != nil { return waitErr } diff --git a/mmv1/templates/terraform/post_create/compute_network_delete_default_route.erb b/mmv1/templates/terraform/post_create/compute_network_delete_default_route.erb index e26445b7c51a..6c25ef0624b2 100644 --- a/mmv1/templates/terraform/post_create/compute_network_delete_default_route.erb +++ b/mmv1/templates/terraform/post_create/compute_network_delete_default_route.erb @@ -19,7 +19,7 @@ if d.Get("delete_default_routes_on_create").(bool) { if err != nil { return fmt.Errorf("Error deleting route: %s", err) } - err = computeOperationWaitTime(config, op, project, "Deleting Route", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, project, "Deleting Route", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } diff --git a/mmv1/templates/terraform/post_create/labels.erb b/mmv1/templates/terraform/post_create/labels.erb index 7616dc339c00..93a96ce45d76 100644 --- a/mmv1/templates/terraform/post_create/labels.erb +++ b/mmv1/templates/terraform/post_create/labels.erb @@ -26,7 +26,7 @@ if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(v)) && (ok || } err = computeOperationWaitTime( - config, res, project, "Updating <%= resource_name -%> Labels", userAgent, + d, config, res, project, "Updating <%= resource_name -%> Labels", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { diff --git a/mmv1/templates/terraform/post_create/org_security_policy.go.erb b/mmv1/templates/terraform/post_create/org_security_policy.go.erb index fb84bf2e43cd..d0efc382373a 100644 --- a/mmv1/templates/terraform/post_create/org_security_policy.go.erb +++ b/mmv1/templates/terraform/post_create/org_security_policy.go.erb @@ -1,7 +1,7 @@ parent := d.Get("parent").(string) var opRes map[string]interface{} err = computeOrgOperationWaitTimeWithResponse( - config, res, &opRes, parent, "Creating OrganizationSecurityPolicy", userAgent, + d, config, res, &opRes, parent, "Creating OrganizationSecurityPolicy", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { diff --git a/mmv1/templates/terraform/post_create/org_security_policy_association.go.erb b/mmv1/templates/terraform/post_create/org_security_policy_association.go.erb index a6dc04d3061e..35f8102a5955 100644 --- a/mmv1/templates/terraform/post_create/org_security_policy_association.go.erb +++ b/mmv1/templates/terraform/post_create/org_security_policy_association.go.erb @@ -14,7 +14,7 @@ if err != nil { parent := flattenComputeOrganizationSecurityPolicyParent(policyRes["parent"], d, config) var opRes map[string]interface{} err = computeOrgOperationWaitTimeWithResponse( - config, res, &opRes, parent.(string), "Creating OrganizationSecurityPolicyAssociation", userAgent, + d, config, res, &opRes, parent.(string), "Creating OrganizationSecurityPolicyAssociation", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { diff --git a/mmv1/templates/terraform/post_create/org_security_policy_rule.go.erb b/mmv1/templates/terraform/post_create/org_security_policy_rule.go.erb index 9cc8a76ecf98..531add9cf625 100644 --- a/mmv1/templates/terraform/post_create/org_security_policy_rule.go.erb +++ b/mmv1/templates/terraform/post_create/org_security_policy_rule.go.erb @@ -14,7 +14,7 @@ if err != nil { parent := flattenComputeOrganizationSecurityPolicyParent(policyRes["parent"], d, config) var opRes map[string]interface{} err = computeOrgOperationWaitTimeWithResponse( - config, res, &opRes, parent.(string), "Creating OrganizationSecurityPolicyRule", userAgent, + d, config, res, &opRes, parent.(string), "Creating OrganizationSecurityPolicyRule", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { diff --git a/mmv1/templates/terraform/post_delete/org_security_policy.go.erb b/mmv1/templates/terraform/post_delete/org_security_policy.go.erb index 967d96451b00..a2c807ccf47c 100644 --- a/mmv1/templates/terraform/post_delete/org_security_policy.go.erb +++ b/mmv1/templates/terraform/post_delete/org_security_policy.go.erb @@ -1,7 +1,7 @@ parent := d.Get("parent").(string) var opRes map[string]interface{} err = computeOrgOperationWaitTimeWithResponse( - config, res, &opRes, parent, "Creating OrganizationSecurityPolicy", userAgent, + d, config, res, &opRes, parent, "Creating OrganizationSecurityPolicy", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { diff --git a/mmv1/templates/terraform/post_update/compute_per_instance_config.go.erb b/mmv1/templates/terraform/post_update/compute_per_instance_config.go.erb index 025d5b303291..cf9f0e579066 100644 --- a/mmv1/templates/terraform/post_update/compute_per_instance_config.go.erb +++ b/mmv1/templates/terraform/post_update/compute_per_instance_config.go.erb @@ -32,7 +32,7 @@ if err != nil { } err = computeOperationWaitTime( - config, res, project, "Applying update to PerInstanceConfig", userAgent, + d, config, res, project, "Applying update to PerInstanceConfig", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { diff --git a/mmv1/templates/terraform/post_update/compute_region_per_instance_config.go.erb b/mmv1/templates/terraform/post_update/compute_region_per_instance_config.go.erb index c66b31769a77..69e04b5811ca 100644 --- a/mmv1/templates/terraform/post_update/compute_region_per_instance_config.go.erb +++ b/mmv1/templates/terraform/post_update/compute_region_per_instance_config.go.erb @@ -32,7 +32,7 @@ if err != nil { } err = computeOperationWaitTime( - config, res, project, "Applying update to PerInstanceConfig", userAgent, + d, config, res, project, "Applying update to PerInstanceConfig", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { diff --git a/mmv1/templates/terraform/post_update/org_security_policy.go.erb b/mmv1/templates/terraform/post_update/org_security_policy.go.erb index 69193da7060e..e78e1fbf2e4d 100644 --- a/mmv1/templates/terraform/post_update/org_security_policy.go.erb +++ b/mmv1/templates/terraform/post_update/org_security_policy.go.erb @@ -1,7 +1,7 @@ parent := d.Get("parent").(string) var opRes map[string]interface{} err = computeOrgOperationWaitTimeWithResponse( - config, res, &opRes, parent, "Creating OrganizationSecurityPolicy", userAgent, + d, config, res, &opRes, parent, "Creating OrganizationSecurityPolicy", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { diff --git a/mmv1/templates/terraform/pre_delete/detach_disk.erb b/mmv1/templates/terraform/pre_delete/detach_disk.erb index 1e95467bc81e..718bae3dae47 100644 --- a/mmv1/templates/terraform/pre_delete/detach_disk.erb +++ b/mmv1/templates/terraform/pre_delete/detach_disk.erb @@ -41,7 +41,7 @@ if v, ok := readRes["users"].([]interface{}); ok { return fmt.Errorf("Error detaching disk %s from instance %s/%s/%s: %s", call.deviceName, call.project, call.zone, call.instance, err.Error()) } - err = computeOperationWaitTime(config, op, call.project, + err = computeOperationWaitTime(d, config, op, call.project, fmt.Sprintf("Detaching disk from %s/%s/%s", call.project, call.zone, call.instance), userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { if opErr, ok := err.(ComputeOperationError); ok && len(opErr.Errors) == 1 && opErr.Errors[0].Code == "RESOURCE_NOT_FOUND" { diff --git a/mmv1/templates/terraform/pre_delete/privateca_certificate_authority.go.erb b/mmv1/templates/terraform/pre_delete/privateca_certificate_authority.go.erb index ccb01d203f14..769836e20320 100644 --- a/mmv1/templates/terraform/pre_delete/privateca_certificate_authority.go.erb +++ b/mmv1/templates/terraform/pre_delete/privateca_certificate_authority.go.erb @@ -11,7 +11,7 @@ if d.Get("disable_on_delete").(bool) && d.Get("state").(string) == "ENABLED" { return err } - err = privatecaOperationWaitTime(config, disableRes, project, "Disabling CertificateAuthority", userAgent, d.Timeout(schema.TimeoutDelete)) + err = privatecaOperationWaitTime(d, config, disableRes, project, "Disabling CertificateAuthority", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/templates/terraform/resource.erb b/mmv1/templates/terraform/resource.erb index cc077c949d6d..85fff63a147f 100644 --- a/mmv1/templates/terraform/resource.erb +++ b/mmv1/templates/terraform/resource.erb @@ -261,7 +261,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ // identity fields and d.Id() before read var opRes map[string]interface{} err = <%= client_name_camel -%>OperationWaitTimeWithResponse( - config, res, &opRes, <% if has_project -%> project, <% end -%> "Creating <%= object.name -%>", userAgent, + d, config, res, &opRes, <% if has_project -%> project, <% end -%> "Creating <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { <% if object.custom_code.post_create_failure -%> @@ -311,7 +311,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ <% else -%> err = <%= client_name_camel -%>OperationWaitTime( - config, res, <% if has_project -%> project, <% end -%> "Creating <%= object.name -%>", userAgent, + d, config, res, <% if has_project -%> project, <% end -%> "Creating <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { @@ -688,7 +688,7 @@ if <%= props.map { |prop| "d.HasChange(\"#{prop.name.underscore}\")" }.join ' || <% if object.async&.allow?('update') -%> <% if object.async.is_a? Api::OpAsync-%> err = <%= client_name_camel -%>OperationWaitTime( - config, res, <% if has_project -%> project, <% end -%> "Updating <%= object.name -%>", userAgent, + d, config, res, <% if has_project -%> project, <% end -%> "Updating <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err @@ -786,7 +786,7 @@ if <%= props.map { |prop| "d.HasChange(\"#{prop.name.underscore}\")" }.join ' || <% if object.async&.allow?('update') -%> <% if object.async.is_a? Api::OpAsync -%> err = <%= client_name_camel -%>OperationWaitTime( - config, res, <% if has_project -%> project, <% end -%> "Updating <%= object.name -%>", userAgent, + d, config, res, <% if has_project -%> project, <% end -%> "Updating <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { @@ -900,7 +900,7 @@ func resource<%= resource_name -%>Delete(d *schema.ResourceData, meta interface{ } <% else -%> err = <%= client_name_camel -%>OperationWaitTime( - config, res, <% if has_project -%> project, <% end -%> "Deleting <%= object.name -%>", userAgent, + d, config, res, <% if has_project -%> project, <% end -%> "Deleting <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { diff --git a/mmv1/third_party/terraform/resources/resource_app_engine_application.go b/mmv1/third_party/terraform/resources/resource_app_engine_application.go index 3450939f9a64..8ea70b1877d4 100644 --- a/mmv1/third_party/terraform/resources/resource_app_engine_application.go +++ b/mmv1/third_party/terraform/resources/resource_app_engine_application.go @@ -230,7 +230,7 @@ func resourceAppEngineApplicationCreate(d *schema.ResourceData, meta interface{} d.SetId(project) // Wait for the operation to complete - waitErr := appEngineOperationWaitTime(config, op, project, "App Engine app to create", userAgent, d.Timeout(schema.TimeoutCreate)) + waitErr := appEngineOperationWaitTime(d, config, op, project, "App Engine app to create", userAgent, d.Timeout(schema.TimeoutCreate)) if waitErr != nil { d.SetId("") return waitErr @@ -338,7 +338,7 @@ func resourceAppEngineApplicationUpdate(d *schema.ResourceData, meta interface{} } // Wait for the operation to complete - waitErr := appEngineOperationWaitTime(config, op, pid, "App Engine app to update", userAgent, d.Timeout(schema.TimeoutUpdate)) + waitErr := appEngineOperationWaitTime(d, config, op, pid, "App Engine app to update", userAgent, d.Timeout(schema.TimeoutUpdate)) if waitErr != nil { return waitErr } diff --git a/mmv1/third_party/terraform/resources/resource_compute_attached_disk.go b/mmv1/third_party/terraform/resources/resource_compute_attached_disk.go index f1f50e5e1a5c..51a949c21b8f 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_attached_disk.go +++ b/mmv1/third_party/terraform/resources/resource_compute_attached_disk.go @@ -113,7 +113,7 @@ func resourceAttachedDiskCreate(d *schema.ResourceData, meta interface{}) error d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s/%s", zv.Project, zv.Zone, zv.Name, diskName)) - waitErr := computeOperationWaitTime(config, op, zv.Project, + waitErr := computeOperationWaitTime(d, config, op, zv.Project, "disk to attach", userAgent, d.Timeout(schema.TimeoutCreate)) if waitErr != nil { d.SetId("") @@ -214,7 +214,7 @@ func resourceAttachedDiskDelete(d *schema.ResourceData, meta interface{}) error return err } - waitErr := computeOperationWaitTime(config, op, zv.Project, + waitErr := computeOperationWaitTime(d, config, op, zv.Project, fmt.Sprintf("Detaching disk from %s", zv.Name), userAgent, d.Timeout(schema.TimeoutDelete)) if waitErr != nil { return waitErr diff --git a/mmv1/third_party/terraform/resources/resource_compute_instance.go b/mmv1/third_party/terraform/resources/resource_compute_instance.go index 39a2ce19f002..c0e73548c542 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_instance.go +++ b/mmv1/third_party/terraform/resources/resource_compute_instance.go @@ -972,7 +972,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, z, instance.Name)) // Wait for the operation to complete - waitErr := computeOperationWaitTime(config, op, project, "instance to create", userAgent, d.Timeout(schema.TimeoutCreate)) + waitErr := computeOperationWaitTime(d, config, op, project, "instance to create", userAgent, d.Timeout(schema.TimeoutCreate)) if waitErr != nil { // The resource didn't actually create d.SetId("") @@ -1296,7 +1296,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error updating metadata: %s", err) } - opErr := computeOperationWaitTime(config, op, project, "metadata to update", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "metadata to update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1322,7 +1322,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error updating tags: %s", err) } - opErr := computeOperationWaitTime(config, op, project, "tags to update", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "tags to update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1338,7 +1338,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error updating labels: %s", err) } - opErr := computeOperationWaitTime(config, op, project, "labels to update", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "labels to update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1359,7 +1359,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err } opErr := computeOperationWaitTime( - config, op, project, "scheduling policy update", userAgent, + d, config, op, project, "scheduling policy update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr @@ -1456,7 +1456,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return errwrap.Wrapf("Error removing alias_ip_range: {{err}}", err) } - opErr := computeOperationWaitTime(config, op, project, "updating alias ip ranges", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "updating alias ip ranges", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1477,7 +1477,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return errwrap.Wrapf("Error updating network interface: {{err}}", err) } - opErr := computeOperationWaitTime(config, op, project, "network interface to update", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "network interface to update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1578,7 +1578,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return errwrap.Wrapf("Error detaching disk: %s", err) } - opErr := computeOperationWaitTime(config, op, project, "detaching disk", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "detaching disk", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1593,7 +1593,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return errwrap.Wrapf("Error attaching disk : {{err}}", err) } - opErr := computeOperationWaitTime(config, op, project, "attaching disk", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "attaching disk", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1625,7 +1625,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error updating deletion protection flag: %s", err) } - opErr := computeOperationWaitTime(config, op, project, "deletion protection to update", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "deletion protection to update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1651,7 +1651,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err } } opErr := computeOperationWaitTime( - config, op, project, "updating status", userAgent, + d, config, op, project, "updating status", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr @@ -1677,7 +1677,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return errwrap.Wrapf("Error stopping instance: {{err}}", err) } - opErr := computeOperationWaitTime(config, op, project, "stopping instance", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "stopping instance", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1695,7 +1695,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return err } - opErr := computeOperationWaitTime(config, op, project, "updating machinetype", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "updating machinetype", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1716,7 +1716,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return err } - opErr := computeOperationWaitTime(config, op, project, "updating min cpu platform", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "updating min cpu platform", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1734,7 +1734,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return err } - opErr := computeOperationWaitTime(config, op, project, "updating service account", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "updating service account", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1749,7 +1749,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return fmt.Errorf("Error updating display device: %s", err) } - opErr := computeOperationWaitTime(config, op, project, "updating display device", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "updating display device", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1763,7 +1763,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error updating shielded vm config: %s", err) } - opErr := computeOperationWaitTime(config, op, project, + opErr := computeOperationWaitTime(d, config, op, project, "shielded vm config update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr @@ -1783,7 +1783,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err } opErr := computeOperationWaitTime( - config, op, project, "scheduling policy update", userAgent, + d, config, op, project, "scheduling policy update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr @@ -1812,7 +1812,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return errwrap.Wrapf("Error starting instance: {{err}}", err) } - opErr := computeOperationWaitTime(config, op, project, + opErr := computeOperationWaitTime(d, config, op, project, "starting instance", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr @@ -2045,7 +2045,7 @@ func resourceComputeInstanceDelete(d *schema.ResourceData, meta interface{}) err } // Wait for the operation to complete - opErr := computeOperationWaitTime(config, op, project, "instance to delete", userAgent, d.Timeout(schema.TimeoutDelete)) + opErr := computeOperationWaitTime(d, config, op, project, "instance to delete", userAgent, d.Timeout(schema.TimeoutDelete)) if opErr != nil { // Refresh operation to check status op, _ = config.NewComputeClient(userAgent).ZoneOperations.Get(project, zone, strconv.FormatUint(op.Id, 10)).Do() diff --git a/mmv1/third_party/terraform/resources/resource_compute_instance_from_machine_image.go.erb b/mmv1/third_party/terraform/resources/resource_compute_instance_from_machine_image.go.erb index 7b7c94c0a904..9a5b6bb588b9 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_instance_from_machine_image.go.erb +++ b/mmv1/third_party/terraform/resources/resource_compute_instance_from_machine_image.go.erb @@ -171,7 +171,7 @@ func resourceComputeInstanceFromMachineImageCreate(d *schema.ResourceData, meta d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, z, instance.Name)) // Wait for the operation to complete - waitErr := computeOperationWaitTime(config, op, project, + waitErr := computeOperationWaitTime(d, config, op, project, "instance to create",userAgent, d.Timeout(schema.TimeoutCreate)) if waitErr != nil { // The resource didn't actually create diff --git a/mmv1/third_party/terraform/resources/resource_compute_instance_from_template.go b/mmv1/third_party/terraform/resources/resource_compute_instance_from_template.go index 547cc59d87dc..2d552db54f80 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_instance_from_template.go +++ b/mmv1/third_party/terraform/resources/resource_compute_instance_from_template.go @@ -167,7 +167,7 @@ func resourceComputeInstanceFromTemplateCreate(d *schema.ResourceData, meta inte d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, z, instance.Name)) // Wait for the operation to complete - waitErr := computeOperationWaitTime(config, op, project, + waitErr := computeOperationWaitTime(d, config, op, project, "instance to create", userAgent, d.Timeout(schema.TimeoutCreate)) if waitErr != nil { // The resource didn't actually create diff --git a/mmv1/third_party/terraform/resources/resource_compute_instance_group.go b/mmv1/third_party/terraform/resources/resource_compute_instance_group.go index 65250b6ea565..04f90e6b05cc 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_instance_group.go +++ b/mmv1/third_party/terraform/resources/resource_compute_instance_group.go @@ -182,7 +182,7 @@ func resourceComputeInstanceGroupCreate(d *schema.ResourceData, meta interface{} d.SetId(fmt.Sprintf("projects/%s/zones/%s/instanceGroups/%s", project, zone, name)) // Wait for the operation to complete - err = computeOperationWaitTime(config, op, project, "Creating InstanceGroup", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, project, "Creating InstanceGroup", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { d.SetId("") return err @@ -216,7 +216,7 @@ func resourceComputeInstanceGroupCreate(d *schema.ResourceData, meta interface{} } // Wait for the operation to complete - err = computeOperationWaitTime(config, op, project, "Adding instances to InstanceGroup", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, project, "Adding instances to InstanceGroup", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -354,7 +354,7 @@ func resourceComputeInstanceGroupUpdate(d *schema.ResourceData, meta interface{} } } else { // Wait for the operation to complete - err = computeOperationWaitTime(config, removeOp, project, "Updating InstanceGroup", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, removeOp, project, "Updating InstanceGroup", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -375,7 +375,7 @@ func resourceComputeInstanceGroupUpdate(d *schema.ResourceData, meta interface{} } // Wait for the operation to complete - err = computeOperationWaitTime(config, addOp, project, "Updating InstanceGroup", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, addOp, project, "Updating InstanceGroup", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -396,7 +396,7 @@ func resourceComputeInstanceGroupUpdate(d *schema.ResourceData, meta interface{} return fmt.Errorf("Error updating named ports for InstanceGroup: %s", err) } - err = computeOperationWaitTime(config, op, project, "Updating InstanceGroup", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, "Updating InstanceGroup", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -429,7 +429,7 @@ func resourceComputeInstanceGroupDelete(d *schema.ResourceData, meta interface{} return fmt.Errorf("Error deleting InstanceGroup: %s", err) } - err = computeOperationWaitTime(config, op, project, "Deleting InstanceGroup", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(d, config, op, project, "Deleting InstanceGroup", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_compute_instance_group_manager.go.erb b/mmv1/third_party/terraform/resources/resource_compute_instance_group_manager.go.erb index 155c5428b6d3..7be3aa607dbc 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_instance_group_manager.go.erb +++ b/mmv1/third_party/terraform/resources/resource_compute_instance_group_manager.go.erb @@ -443,7 +443,7 @@ func resourceComputeInstanceGroupManagerCreate(d *schema.ResourceData, meta inte d.SetId(id) // Wait for the operation to complete - err = computeOperationWaitTime(config, op, project, "Creating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, project, "Creating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { // Check if the create operation failed because Terraform was prematurely terminated. If it was we can persist the // operation id to state so that a subsequent refresh of this resource will wait until the operation has terminated @@ -557,7 +557,7 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf if err := d.Set("operation", op.Name); err != nil { return fmt.Errorf("Error setting operation: %s", err) } - err = computeOperationWaitTime(config, op, project, "Creating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, project, "Creating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { // remove from state to allow refresh to finish log.Printf("[DEBUG] Resumed operation returned an error, removing from state: %s", err) @@ -705,7 +705,7 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte return fmt.Errorf("Error updating managed group instances: %s", err) } - err = computeOperationWaitTime(config, op, project, "Updating managed group instances", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, "Updating managed group instances", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -731,7 +731,7 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte } // Wait for the operation to complete: - err = computeOperationWaitTime(config, op, project, "Updating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, "Updating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -750,7 +750,7 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte } // Wait for the operation to complete - err = computeOperationWaitTime(config, op, project, "Updating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, "Updating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -791,7 +791,7 @@ func resourceComputeInstanceGroupManagerDelete(d *schema.ResourceData, meta inte currentSize := int64(d.Get("target_size").(int)) // Wait for the operation to complete - err = computeOperationWaitTime(config, op, project, "Deleting InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(d, config, op, project, "Deleting InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutDelete)) for err != nil && currentSize > 0 { if !strings.Contains(err.Error(), "timeout") { @@ -812,7 +812,7 @@ func resourceComputeInstanceGroupManagerDelete(d *schema.ResourceData, meta inte log.Printf("[INFO] timeout occurred, but instance group is shrinking (%d < %d)", instanceGroupSize, currentSize) currentSize = instanceGroupSize - err = computeOperationWaitTime(config, op, project, "Deleting InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(d, config, op, project, "Deleting InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutDelete)) } d.SetId("") diff --git a/mmv1/third_party/terraform/resources/resource_compute_instance_template.go.erb b/mmv1/third_party/terraform/resources/resource_compute_instance_template.go.erb index 7d92e73b9ffc..16d8a848bec1 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_instance_template.go.erb +++ b/mmv1/third_party/terraform/resources/resource_compute_instance_template.go.erb @@ -915,7 +915,7 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac // Store the ID now d.SetId(fmt.Sprintf("projects/%s/global/instanceTemplates/%s", project, instanceTemplate.Name)) - err = computeOperationWaitTime(config, op, project, "Creating Instance Template", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, project, "Creating Instance Template", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -1303,7 +1303,7 @@ func resourceComputeInstanceTemplateDelete(d *schema.ResourceData, meta interfac return fmt.Errorf("Error deleting instance template: %s", err) } - err = computeOperationWaitTime(config, op, project, "Deleting Instance Template", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(d, config, op, project, "Deleting Instance Template", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_compute_network_peering.go b/mmv1/third_party/terraform/resources/resource_compute_network_peering.go index 52e50c27f043..5dd9faf69538 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_network_peering.go +++ b/mmv1/third_party/terraform/resources/resource_compute_network_peering.go @@ -132,7 +132,7 @@ func resourceComputeNetworkPeeringCreate(d *schema.ResourceData, meta interface{ return fmt.Errorf("Error adding network peering: %s", err) } - err = computeOperationWaitTime(config, addOp, networkFieldValue.Project, "Adding Network Peering", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, addOp, networkFieldValue.Project, "Adding Network Peering", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -227,7 +227,7 @@ func resourceComputeNetworkPeeringUpdate(d *schema.ResourceData, meta interface{ return fmt.Errorf("Error updating network peering: %s", err) } - err = computeOperationWaitTime(config, updateOp, networkFieldValue.Project, "Updating Network Peering", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, updateOp, networkFieldValue.Project, "Updating Network Peering", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -273,7 +273,7 @@ func resourceComputeNetworkPeeringDelete(d *schema.ResourceData, meta interface{ return fmt.Errorf("Error removing peering `%s` from network `%s`: %s", name, networkFieldValue.Name, err) } } else { - err = computeOperationWaitTime(config, removeOp, networkFieldValue.Project, "Removing Network Peering", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(d, config, removeOp, networkFieldValue.Project, "Removing Network Peering", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_compute_project_default_network_tier.go b/mmv1/third_party/terraform/resources/resource_compute_project_default_network_tier.go index 2aed56fdcee8..b7479e51706a 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_project_default_network_tier.go +++ b/mmv1/third_party/terraform/resources/resource_compute_project_default_network_tier.go @@ -68,7 +68,7 @@ func resourceComputeProjectDefaultNetworkTierCreateOrUpdate(d *schema.ResourceDa } log.Printf("[DEBUG] SetDefaultNetworkTier: %d (%s)", op.Id, op.SelfLink) - err = computeOperationWaitTime(config, op, projectID, "SetDefaultNetworkTier", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, projectID, "SetDefaultNetworkTier", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return fmt.Errorf("SetDefaultNetworkTier failed: %s", err) } diff --git a/mmv1/third_party/terraform/resources/resource_compute_project_metadata.go b/mmv1/third_party/terraform/resources/resource_compute_project_metadata.go index be4158ab8b92..8ab984c00a9a 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_project_metadata.go +++ b/mmv1/third_party/terraform/resources/resource_compute_project_metadata.go @@ -62,7 +62,7 @@ func resourceComputeProjectMetadataCreateOrUpdate(d *schema.ResourceData, meta i Items: expandComputeMetadata(d.Get("metadata").(map[string]interface{})), } - err = resourceComputeProjectMetadataSet(projectID, userAgent, config, md, d.Timeout(schema.TimeoutCreate)) + err = resourceComputeProjectMetadataSet(projectID, userAgent, d, config, md, d.Timeout(schema.TimeoutCreate)) if err != nil { return fmt.Errorf("SetCommonInstanceMetadata failed: %s", err) } @@ -120,7 +120,7 @@ func resourceComputeProjectMetadataDelete(d *schema.ResourceData, meta interface } md := &compute.Metadata{} - err = resourceComputeProjectMetadataSet(projectID, userAgent, config, md, d.Timeout(schema.TimeoutDelete)) + err = resourceComputeProjectMetadataSet(projectID, userAgent, d, config, md, d.Timeout(schema.TimeoutDelete)) if err != nil { return fmt.Errorf("SetCommonInstanceMetadata failed: %s", err) } @@ -128,7 +128,7 @@ func resourceComputeProjectMetadataDelete(d *schema.ResourceData, meta interface return resourceComputeProjectMetadataRead(d, meta) } -func resourceComputeProjectMetadataSet(projectID, userAgent string, config *Config, md *compute.Metadata, timeout time.Duration) error { +func resourceComputeProjectMetadataSet(projectID, userAgent string, d *schema.ResourceData, config *Config, md *compute.Metadata, timeout time.Duration) error { createMD := func() error { log.Printf("[DEBUG] Loading project service: %s", projectID) project, err := config.NewComputeClient(userAgent).Projects.Get(projectID).Do() @@ -143,7 +143,7 @@ func resourceComputeProjectMetadataSet(projectID, userAgent string, config *Conf } log.Printf("[DEBUG] SetCommonMetadata: %d (%s)", op.Id, op.SelfLink) - return computeOperationWaitTime(config, op, project.Name, "SetCommonMetadata", userAgent, timeout) + return computeOperationWaitTime(d, config, op, project.Name, "SetCommonMetadata", userAgent, timeout) } err := MetadataRetryWrapper(createMD) diff --git a/mmv1/third_party/terraform/resources/resource_compute_project_metadata_item.go b/mmv1/third_party/terraform/resources/resource_compute_project_metadata_item.go index 48bc92e01a80..53c3bc200b6f 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_project_metadata_item.go +++ b/mmv1/third_party/terraform/resources/resource_compute_project_metadata_item.go @@ -71,7 +71,7 @@ func resourceComputeProjectMetadataItemCreate(d *schema.ResourceData, meta inter key := d.Get("key").(string) val := d.Get("value").(string) - err = updateComputeCommonInstanceMetadata(config, projectID, key, userAgent, &val, d.Timeout(schema.TimeoutCreate), failIfPresent) + err = updateComputeCommonInstanceMetadata(d, config, projectID, key, userAgent, &val, d.Timeout(schema.TimeoutCreate), failIfPresent) if err != nil { return err } @@ -137,7 +137,7 @@ func resourceComputeProjectMetadataItemUpdate(d *schema.ResourceData, meta inter _, n := d.GetChange("value") new := n.(string) - err = updateComputeCommonInstanceMetadata(config, projectID, key, userAgent, &new, d.Timeout(schema.TimeoutUpdate), overwritePresent) + err = updateComputeCommonInstanceMetadata(d, config, projectID, key, userAgent, &new, d.Timeout(schema.TimeoutUpdate), overwritePresent) if err != nil { return err } @@ -159,7 +159,7 @@ func resourceComputeProjectMetadataItemDelete(d *schema.ResourceData, meta inter key := d.Get("key").(string) - err = updateComputeCommonInstanceMetadata(config, projectID, key, userAgent, nil, d.Timeout(schema.TimeoutDelete), overwritePresent) + err = updateComputeCommonInstanceMetadata(d, config, projectID, key, userAgent, nil, d.Timeout(schema.TimeoutDelete), overwritePresent) if err != nil { return err } @@ -168,7 +168,7 @@ func resourceComputeProjectMetadataItemDelete(d *schema.ResourceData, meta inter return nil } -func updateComputeCommonInstanceMetadata(config *Config, projectID, key, userAgent string, afterVal *string, timeout time.Duration, failIfPresent metadataPresentBehavior) error { +func updateComputeCommonInstanceMetadata(d *schema.ResourceData, config *Config, projectID, key, userAgent string, afterVal *string, timeout time.Duration, failIfPresent metadataPresentBehavior) error { updateMD := func() error { lockName := fmt.Sprintf("projects/%s/commoninstancemetadata", projectID) mutexKV.Lock(lockName) @@ -220,7 +220,7 @@ func updateComputeCommonInstanceMetadata(config *Config, projectID, key, userAge log.Printf("[DEBUG] SetCommonInstanceMetadata: %d (%s)", op.Id, op.SelfLink) - return computeOperationWaitTime(config, op, project.Name, "SetCommonInstanceMetadata", userAgent, timeout) + return computeOperationWaitTime(d, config, op, project.Name, "SetCommonInstanceMetadata", userAgent, timeout) } return MetadataRetryWrapper(updateMD) diff --git a/mmv1/third_party/terraform/resources/resource_compute_region_instance_group_manager.go.erb b/mmv1/third_party/terraform/resources/resource_compute_region_instance_group_manager.go.erb index 6345bdfeae0d..db942ed54f19 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_region_instance_group_manager.go.erb +++ b/mmv1/third_party/terraform/resources/resource_compute_region_instance_group_manager.go.erb @@ -440,7 +440,7 @@ func resourceComputeRegionInstanceGroupManagerCreate(d *schema.ResourceData, met d.SetId(id) // Wait for the operation to complete - err = computeOperationWaitTime(config, op, project, "Creating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, project, "Creating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -655,7 +655,7 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met return fmt.Errorf("Error updating region managed group instances: %s", err) } - err = computeOperationWaitTime(config, op, project, "Updating region managed group instances", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, "Updating region managed group instances", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -677,7 +677,7 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met return fmt.Errorf("Error updating RegionInstanceGroupManager: %s", err) } - err = computeOperationWaitTime(config, op, project, "Updating RegionInstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, "Updating RegionInstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -694,7 +694,7 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met return fmt.Errorf("Error resizing RegionInstanceGroupManager: %s", err) } - err = computeOperationWaitTime(config, op, project, "Resizing RegionInstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, "Resizing RegionInstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -731,7 +731,7 @@ func resourceComputeRegionInstanceGroupManagerDelete(d *schema.ResourceData, met } // Wait for the operation to complete - err = computeOperationWaitTime(config, op, project, "Deleting RegionInstanceGroupManager", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(d, config, op, project, "Deleting RegionInstanceGroupManager", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return fmt.Errorf("Error waiting for delete to complete: %s", err) } diff --git a/mmv1/third_party/terraform/resources/resource_compute_router_interface.go b/mmv1/third_party/terraform/resources/resource_compute_router_interface.go index f3b7b3dd84e0..b88783e85585 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_router_interface.go +++ b/mmv1/third_party/terraform/resources/resource_compute_router_interface.go @@ -163,7 +163,7 @@ func resourceComputeRouterInterfaceCreate(d *schema.ResourceData, meta interface return fmt.Errorf("Error patching router %s/%s: %s", region, routerName, err) } d.SetId(fmt.Sprintf("%s/%s/%s", region, routerName, ifaceName)) - err = computeOperationWaitTime(config, op, project, "Patching router", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, project, "Patching router", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { d.SetId("") return fmt.Errorf("Error waiting to patch router %s/%s: %s", region, routerName, err) @@ -304,7 +304,7 @@ func resourceComputeRouterInterfaceDelete(d *schema.ResourceData, meta interface return fmt.Errorf("Error patching router %s/%s: %s", region, routerName, err) } - err = computeOperationWaitTime(config, op, project, "Patching router", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(d, config, op, project, "Patching router", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return fmt.Errorf("Error waiting to patch router %s/%s: %s", region, routerName, err) } diff --git a/mmv1/third_party/terraform/resources/resource_compute_security_policy.go.erb b/mmv1/third_party/terraform/resources/resource_compute_security_policy.go.erb index bfd1151e139e..a00175ea6ca4 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_security_policy.go.erb +++ b/mmv1/third_party/terraform/resources/resource_compute_security_policy.go.erb @@ -222,7 +222,7 @@ func resourceComputeSecurityPolicyCreate(d *schema.ResourceData, meta interface{ } d.SetId(id) - err = computeOperationWaitTime(config, op, project, fmt.Sprintf("Creating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, project, fmt.Sprintf("Creating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -296,7 +296,7 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{ return errwrap.Wrapf(fmt.Sprintf("Error updating SecurityPolicy %q: {{err}}", sp), err) } - err = computeOperationWaitTime(config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -324,7 +324,7 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{ return errwrap.Wrapf(fmt.Sprintf("Error updating SecurityPolicy %q: {{err}}", sp), err) } - err = computeOperationWaitTime(config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -336,7 +336,7 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{ return errwrap.Wrapf(fmt.Sprintf("Error updating SecurityPolicy %q: {{err}}", sp), err) } - err = computeOperationWaitTime(config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -353,7 +353,7 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{ return errwrap.Wrapf(fmt.Sprintf("Error updating SecurityPolicy %q: {{err}}", sp), err) } - err = computeOperationWaitTime(config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -382,7 +382,7 @@ func resourceComputeSecurityPolicyDelete(d *schema.ResourceData, meta interface{ return errwrap.Wrapf("Error deleting SecurityPolicy: {{err}}", err) } - err = computeOperationWaitTime(config, op, project, "Deleting SecurityPolicy", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(d, config, op, project, "Deleting SecurityPolicy", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_host_project.go b/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_host_project.go index 2c82fc1e3a3e..8fb86d0584e4 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_host_project.go +++ b/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_host_project.go @@ -49,7 +49,7 @@ func resourceComputeSharedVpcHostProjectCreate(d *schema.ResourceData, meta inte d.SetId(hostProject) - err = computeOperationWaitTime(config, op, hostProject, "Enabling Shared VPC Host", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, hostProject, "Enabling Shared VPC Host", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { d.SetId("") return err @@ -98,7 +98,7 @@ func resourceComputeSharedVpcHostProjectDelete(d *schema.ResourceData, meta inte return fmt.Errorf("Error disabling Shared VPC Host %q: %s", hostProject, err) } - err = computeOperationWaitTime(config, op, hostProject, "Disabling Shared VPC Host", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(d, config, op, hostProject, "Disabling Shared VPC Host", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_service_project.go b/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_service_project.go index 082d240842ba..2034f01fd3c4 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_service_project.go +++ b/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_service_project.go @@ -65,7 +65,7 @@ func resourceComputeSharedVpcServiceProjectCreate(d *schema.ResourceData, meta i if err != nil { return err } - err = computeOperationWaitTime(config, op, hostProject, "Enabling Shared VPC Resource", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, hostProject, "Enabling Shared VPC Resource", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -144,7 +144,7 @@ func disableXpnResource(d *schema.ResourceData, config *Config, hostProject, pro if err != nil { return err } - err = computeOperationWaitTime(config, op, hostProject, "Disabling Shared VPC Resource", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(d, config, op, hostProject, "Disabling Shared VPC Resource", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_compute_target_pool.go b/mmv1/third_party/terraform/resources/resource_compute_target_pool.go index a54dca0fb7fb..d202336d58dd 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_target_pool.go +++ b/mmv1/third_party/terraform/resources/resource_compute_target_pool.go @@ -235,7 +235,7 @@ func resourceComputeTargetPoolCreate(d *schema.ResourceData, meta interface{}) e } d.SetId(id) - err = computeOperationWaitTime(config, op, project, "Creating Target Pool", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, project, "Creating Target Pool", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -288,7 +288,7 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error updating health_check: %s", err) } - err = computeOperationWaitTime(config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -304,7 +304,7 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error updating health_check: %s", err) } - err = computeOperationWaitTime(config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -337,7 +337,7 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error updating instances: %s", err) } - err = computeOperationWaitTime(config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -352,7 +352,7 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e if err != nil { return fmt.Errorf("Error updating instances: %s", err) } - err = computeOperationWaitTime(config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -369,7 +369,7 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error updating backup_pool: %s", err) } - err = computeOperationWaitTime(config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(d, config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -476,7 +476,7 @@ func resourceComputeTargetPoolDelete(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error deleting TargetPool: %s", err) } - err = computeOperationWaitTime(config, op, project, "Deleting Target Pool", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(d, config, op, project, "Deleting Target Pool", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_google_folder.go b/mmv1/third_party/terraform/resources/resource_google_folder.go index edc049ef8b24..ce3842768d70 100644 --- a/mmv1/third_party/terraform/resources/resource_google_folder.go +++ b/mmv1/third_party/terraform/resources/resource_google_folder.go @@ -95,7 +95,7 @@ func resourceGoogleFolderCreate(d *schema.ResourceData, meta interface{}) error return err } - err = resourceManagerOperationWaitTime(config, opAsMap, "creating folder", userAgent, d.Timeout(schema.TimeoutCreate)) + err = resourceManagerOperationWaitTime(d, config, opAsMap, "creating folder", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return fmt.Errorf("Error creating folder '%s' in '%s': %s", displayName, parent, err) } @@ -195,7 +195,7 @@ func resourceGoogleFolderUpdate(d *schema.ResourceData, meta interface{}) error return err } - err = resourceManagerOperationWaitTime(config, opAsMap, "move folder", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = resourceManagerOperationWaitTime(d, config, opAsMap, "move folder", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return fmt.Errorf("Error moving folder '%s' to '%s': %s", displayName, newParent, err) } diff --git a/mmv1/third_party/terraform/resources/resource_google_project.go b/mmv1/third_party/terraform/resources/resource_google_project.go index 38aa6477b7f8..cf15d3ac500e 100644 --- a/mmv1/third_party/terraform/resources/resource_google_project.go +++ b/mmv1/third_party/terraform/resources/resource_google_project.go @@ -149,7 +149,7 @@ func resourceGoogleProjectCreate(d *schema.ResourceData, meta interface{}) error return err } - waitErr := resourceManagerOperationWaitTime(config, opAsMap, "creating folder", userAgent, d.Timeout(schema.TimeoutCreate)) + waitErr := resourceManagerOperationWaitTime(d, config, opAsMap, "creating folder", userAgent, d.Timeout(schema.TimeoutCreate)) if waitErr != nil { // The resource wasn't actually created d.SetId("") @@ -179,7 +179,7 @@ func resourceGoogleProjectCreate(d *schema.ResourceData, meta interface{}) error // a network and deleting it in the background. if !d.Get("auto_create_network").(bool) { // The compute API has to be enabled before we can delete a network. - if err = enableServiceUsageProjectServices([]string{"compute.googleapis.com"}, project.ProjectId, userAgent, config, d.Timeout(schema.TimeoutCreate)); err != nil { + if err = enableServiceUsageProjectServices([]string{"compute.googleapis.com"}, project.ProjectId, userAgent, d, config, d.Timeout(schema.TimeoutCreate)); err != nil { return errwrap.Wrapf("Error enabling the Compute Engine API required to delete the default network: {{err}} ", err) } @@ -498,7 +498,7 @@ func forceDeleteComputeNetwork(d *schema.ResourceData, config *Config, projectId if err != nil { return errwrap.Wrapf("Error deleting firewall: {{err}}", err) } - err = computeOperationWaitTime(config, op, projectId, "Deleting Firewall", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, projectId, "Deleting Firewall", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -508,7 +508,7 @@ func forceDeleteComputeNetwork(d *schema.ResourceData, config *Config, projectId paginate = token != "" } - return deleteComputeNetwork(projectId, networkName, userAgent, config) + return deleteComputeNetwork(projectId, networkName, userAgent, d, config) } func updateProjectBillingAccount(d *schema.ResourceData, config *Config, userAgent string) error { @@ -553,14 +553,14 @@ func updateProjectBillingAccount(d *schema.ResourceData, config *Config, userAge name, strings.TrimPrefix(ba.BillingAccountName, "billingAccounts/")) } -func deleteComputeNetwork(project, network, userAgent string, config *Config) error { +func deleteComputeNetwork(project, network, userAgent string, d *schema.ResourceData, config *Config) error { op, err := config.NewComputeClient(userAgent).Networks.Delete( project, network).Do() if err != nil { return errwrap.Wrapf("Error deleting network: {{err}}", err) } - err = computeOperationWaitTime(config, op, project, "Deleting Network", userAgent, 10*time.Minute) + err = computeOperationWaitTime(d, config, op, project, "Deleting Network", userAgent, 10*time.Minute) if err != nil { return err } @@ -580,7 +580,7 @@ func readGoogleProject(d *schema.ResourceData, config *Config, userAgent string) } // Enables services. WARNING: Use BatchRequestEnableServices for better batching if possible. -func enableServiceUsageProjectServices(services []string, project, userAgent string, config *Config, timeout time.Duration) error { +func enableServiceUsageProjectServices(services []string, project, userAgent string, d *schema.ResourceData, config *Config, timeout time.Duration) error { // ServiceUsage does not allow more than 20 services to be enabled per // batchEnable API call. See // https://cloud.google.com/service-usage/docs/reference/rest/v1/services/batchEnable @@ -595,7 +595,7 @@ func enableServiceUsageProjectServices(services []string, project, userAgent str return nil } - if err := doEnableServicesRequest(nextBatch, project, userAgent, config, timeout); err != nil { + if err := doEnableServicesRequest(nextBatch, project, userAgent, d, config, timeout); err != nil { return err } log.Printf("[DEBUG] Finished enabling next batch of %d project services: %+v", len(nextBatch), nextBatch) @@ -605,7 +605,7 @@ func enableServiceUsageProjectServices(services []string, project, userAgent str return waitForServiceUsageEnabledServices(services, project, userAgent, config, timeout) } -func doEnableServicesRequest(services []string, project, userAgent string, config *Config, timeout time.Duration) error { +func doEnableServicesRequest(services []string, project, userAgent string, d *schema.ResourceData, config *Config, timeout time.Duration) error { var op *serviceusage.Operation err := retryTimeDuration(func() error { @@ -628,7 +628,7 @@ func doEnableServicesRequest(services []string, project, userAgent string, confi return errwrap.Wrapf("failed to send enable services request: {{err}}", err) } // Poll for the API to return - waitErr := serviceUsageOperationWait(config, op, project, fmt.Sprintf("Enable Project %q Services: %+v", project, services), userAgent, timeout) + waitErr := serviceUsageOperationWait(d, config, op, project, fmt.Sprintf("Enable Project %q Services: %+v", project, services), userAgent, timeout) if waitErr != nil { return waitErr } diff --git a/mmv1/third_party/terraform/resources/resource_google_project_service.go b/mmv1/third_party/terraform/resources/resource_google_project_service.go index e89a6f4c1fd5..e8d6b64e7998 100644 --- a/mmv1/third_party/terraform/resources/resource_google_project_service.go +++ b/mmv1/third_party/terraform/resources/resource_google_project_service.go @@ -282,7 +282,7 @@ func disableServiceUsageProjectService(service, project string, d *schema.Resour return err } // Wait for the operation to complete - waitErr := serviceUsageOperationWait(config, sop, project, "api to disable", userAgent, d.Timeout(schema.TimeoutDelete)) + waitErr := serviceUsageOperationWait(d, config, sop, project, "api to disable", userAgent, d.Timeout(schema.TimeoutDelete)) if waitErr != nil { return waitErr } diff --git a/mmv1/third_party/terraform/resources/resource_project_service_identity.go.erb b/mmv1/third_party/terraform/resources/resource_project_service_identity.go.erb index 14bcec0f4624..e98b99bcba28 100644 --- a/mmv1/third_party/terraform/resources/resource_project_service_identity.go.erb +++ b/mmv1/third_party/terraform/resources/resource_project_service_identity.go.erb @@ -74,7 +74,7 @@ func resourceProjectServiceIdentityCreate(d *schema.ResourceData, meta interface var opRes map[string]interface{} err = serviceUsageOperationWaitTimeWithResponse( - config, res, &opRes, project, "Creating Service Identity", userAgent, + d, config, res, &opRes, project, "Creating Service Identity", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err diff --git a/mmv1/third_party/terraform/resources/resource_service_networking_connection.go b/mmv1/third_party/terraform/resources/resource_service_networking_connection.go index 122050e44f7e..c6e78a3d33a3 100644 --- a/mmv1/third_party/terraform/resources/resource_service_networking_connection.go +++ b/mmv1/third_party/terraform/resources/resource_service_networking_connection.go @@ -103,7 +103,7 @@ func resourceServiceNetworkingConnectionCreate(d *schema.ResourceData, meta inte return err } - if err := serviceNetworkingOperationWaitTime(config, op, "Create Service Networking Connection", userAgent, d.Timeout(schema.TimeoutCreate)); err != nil { + if err := serviceNetworkingOperationWaitTime(d, config, op, "Create Service Networking Connection", userAgent, d.Timeout(schema.TimeoutCreate)); err != nil { return err } @@ -201,7 +201,7 @@ func resourceServiceNetworkingConnectionUpdate(d *schema.ResourceData, meta inte if err != nil { return err } - if err := serviceNetworkingOperationWaitTime(config, op, "Update Service Networking Connection", userAgent, d.Timeout(schema.TimeoutUpdate)); err != nil { + if err := serviceNetworkingOperationWaitTime(d, config, op, "Update Service Networking Connection", userAgent, d.Timeout(schema.TimeoutUpdate)); err != nil { return err } } @@ -244,7 +244,7 @@ func resourceServiceNetworkingConnectionDelete(d *schema.ResourceData, meta inte } err = computeOperationWaitTime( - config, op, project, "Updating Network", userAgent, d.Timeout(schema.TimeoutDelete)) + d, config, op, project, "Updating Network", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_sql_database_instance.go.erb b/mmv1/third_party/terraform/resources/resource_sql_database_instance.go.erb index 12e8299572cf..29fa5d2af516 100644 --- a/mmv1/third_party/terraform/resources/resource_sql_database_instance.go.erb +++ b/mmv1/third_party/terraform/resources/resource_sql_database_instance.go.erb @@ -878,7 +878,7 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{}) } d.SetId(id) - err = sqlAdminOperationWaitTime(config, op, project, "Create Instance", userAgent, d.Timeout(schema.TimeoutCreate)) + err = sqlAdminOperationWaitTime(d, config, op, project, "Create Instance", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { d.SetId("") return err @@ -907,7 +907,7 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error, failed to update instance settings for %s: %s", instance.Name, err) } - err = sqlAdminOperationWaitTime(config, op, project, "Update Instance", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = sqlAdminOperationWaitTime(d, config, op, project, "Update Instance", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -935,7 +935,7 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{}) err = retry(func() error { op, err = config.NewSqlAdminClient(userAgent).Users.Delete(project, instance.Name).Host(u.Host).Name(u.Name).Do() if err == nil { - err = sqlAdminOperationWaitTime(config, op, project, "Delete default root User", userAgent, d.Timeout(schema.TimeoutCreate)) + err = sqlAdminOperationWaitTime(d, config, op, project, "Delete default root User", userAgent, d.Timeout(schema.TimeoutCreate)) } return err }) @@ -1286,7 +1286,7 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error, failed to update instance settings for %s: %s", instance.Name, err) } - err = sqlAdminOperationWaitTime(config, op, project, "Update Instance", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = sqlAdminOperationWaitTime(d, config, op, project, "Update Instance", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -1335,7 +1335,7 @@ func resourceSqlDatabaseInstanceDelete(d *schema.ResourceData, meta interface{}) if rerr != nil { return rerr } - err = sqlAdminOperationWaitTime(config, op, project, "Delete Instance", userAgent, d.Timeout(schema.TimeoutDelete)) + err = sqlAdminOperationWaitTime(d, config, op, project, "Delete Instance", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } @@ -1655,7 +1655,7 @@ func sqlDatabaseInstanceRestoreFromBackup(d *schema.ResourceData, config *Config return fmt.Errorf("Error, failed to restore instance from backup %s: %s", instanceId, err) } - err = sqlAdminOperationWaitTime(config, op, project, "Restore Backup", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = sqlAdminOperationWaitTime(d, config, op, project, "Restore Backup", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_sql_ssl_cert.go b/mmv1/third_party/terraform/resources/resource_sql_ssl_cert.go index 5ecc39256711..b8ba19548490 100644 --- a/mmv1/third_party/terraform/resources/resource_sql_ssl_cert.go +++ b/mmv1/third_party/terraform/resources/resource_sql_ssl_cert.go @@ -119,7 +119,7 @@ func resourceSqlSslCertCreate(d *schema.ResourceData, meta interface{}) error { "ssl cert %s into instance %s: %s", commonName, instance, err) } - err = sqlAdminOperationWaitTime(config, resp.Operation, project, "Create Ssl Cert", userAgent, d.Timeout(schema.TimeoutCreate)) + err = sqlAdminOperationWaitTime(d, config, resp.Operation, project, "Create Ssl Cert", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return fmt.Errorf("Error, failure waiting for creation of %q "+ "in %q: %s", commonName, instance, err) @@ -225,7 +225,7 @@ func resourceSqlSslCertDelete(d *schema.ResourceData, meta interface{}) error { instance, err) } - err = sqlAdminOperationWaitTime(config, op, project, "Delete Ssl Cert", userAgent, d.Timeout(schema.TimeoutDelete)) + err = sqlAdminOperationWaitTime(d, config, op, project, "Delete Ssl Cert", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return fmt.Errorf("Error, failure waiting for deletion of ssl cert %q "+ diff --git a/mmv1/third_party/terraform/resources/resource_sql_user.go b/mmv1/third_party/terraform/resources/resource_sql_user.go index 043aa9e22329..7d3d171563a9 100644 --- a/mmv1/third_party/terraform/resources/resource_sql_user.go +++ b/mmv1/third_party/terraform/resources/resource_sql_user.go @@ -135,7 +135,7 @@ func resourceSqlUserCreate(d *schema.ResourceData, meta interface{}) error { // for which user.Host is an empty string. That's okay. d.SetId(fmt.Sprintf("%s/%s/%s", user.Name, user.Host, user.Instance)) - err = sqlAdminOperationWaitTime(config, op, project, "Insert User", userAgent, d.Timeout(schema.TimeoutCreate)) + err = sqlAdminOperationWaitTime(d, config, op, project, "Insert User", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return fmt.Errorf("Error, failure waiting for insertion of %s "+ @@ -247,7 +247,7 @@ func resourceSqlUserUpdate(d *schema.ResourceData, meta interface{}) error { "user %s into user %s: %s", name, instance, err) } - err = sqlAdminOperationWaitTime(config, op, project, "Insert User", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = sqlAdminOperationWaitTime(d, config, op, project, "Insert User", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return fmt.Errorf("Error, failure waiting for update of %s "+ @@ -293,7 +293,7 @@ func resourceSqlUserDelete(d *schema.ResourceData, meta interface{}) error { return err } - if err := sqlAdminOperationWaitTime(config, op, project, "Delete User", userAgent, d.Timeout(schema.TimeoutDelete)); err != nil { + if err := sqlAdminOperationWaitTime(d, config, op, project, "Delete User", userAgent, d.Timeout(schema.TimeoutDelete)); err != nil { return err } return nil diff --git a/mmv1/third_party/terraform/resources/resource_usage_export_bucket.go b/mmv1/third_party/terraform/resources/resource_usage_export_bucket.go index d0066ed7e28d..ac725f147418 100644 --- a/mmv1/third_party/terraform/resources/resource_usage_export_bucket.go +++ b/mmv1/third_party/terraform/resources/resource_usage_export_bucket.go @@ -103,7 +103,7 @@ func resourceProjectUsageBucketCreate(d *schema.ResourceData, meta interface{}) return err } d.SetId(project) - err = computeOperationWaitTime(config, op, project, "Setting usage export bucket.", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(d, config, op, project, "Setting usage export bucket.", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { d.SetId("") return err @@ -133,7 +133,7 @@ func resourceProjectUsageBucketDelete(d *schema.ResourceData, meta interface{}) return err } - err = computeOperationWaitTime(config, op, project, + err = computeOperationWaitTime(d, config, op, project, "Setting usage export bucket to nil, automatically disabling usage export.", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err diff --git a/mmv1/third_party/terraform/tests/resource_composer_environment_test.go.erb b/mmv1/third_party/terraform/tests/resource_composer_environment_test.go.erb index 2335472668ab..51e9b5ed45de 100644 --- a/mmv1/third_party/terraform/tests/resource_composer_environment_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_composer_environment_test.go.erb @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "google.golang.org/api/composer/v1beta1" "google.golang.org/api/storage/v1" @@ -1190,7 +1191,7 @@ func testAccCheckClearComposerEnvironmentFirewalls(t *testing.T, networkName str continue } - waitErr := computeOperationWaitTime(config, op, config.Project, + waitErr := computeOperationWaitTime(&schema.ResourceData{}, config, op, config.Project, "Sweeping test composer environment firewalls", config.userAgent, 10) if waitErr != nil { allErrors = multierror.Append(allErrors, diff --git a/mmv1/third_party/terraform/tests/resource_compute_instance_migrate_test.go b/mmv1/third_party/terraform/tests/resource_compute_instance_migrate_test.go index af7a807ca356..d7f0ee139dff 100644 --- a/mmv1/third_party/terraform/tests/resource_compute_instance_migrate_test.go +++ b/mmv1/third_party/terraform/tests/resource_compute_instance_migrate_test.go @@ -11,6 +11,7 @@ import ( "google.golang.org/api/compute/v1" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) @@ -107,7 +108,8 @@ func TestAccComputeInstanceMigrateState(t *testing.T) { if err != nil { t.Fatalf("Error creating instance: %s", err) } - waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + d := &schema.ResourceData{} + waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -180,7 +182,8 @@ func TestAccComputeInstanceMigrateState_bootDisk(t *testing.T) { if err != nil { t.Fatalf("Error creating instance: %s", err) } - waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + d := &schema.ResourceData{} + waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -248,7 +251,8 @@ func TestAccComputeInstanceMigrateState_v4FixBootDisk(t *testing.T) { if err != nil { t.Fatalf("Error creating instance: %s", err) } - waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + d := &schema.ResourceData{} + waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -301,7 +305,8 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromSource(t *testing.T) { if err != nil { t.Fatalf("Error creating disk: %s", err) } - waitErr := computeOperationWaitTime(config, op, config.Project, "disk to create", config.userAgent, 4*time.Minute) + d := &schema.ResourceData{} + waitErr := computeOperationWaitTime(d, config, op, config.Project, "disk to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -333,7 +338,7 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromSource(t *testing.T) { if err != nil { t.Fatalf("Error creating instance: %s", err) } - waitErr = computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + waitErr = computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -382,7 +387,8 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromSource(t *testing.T if err != nil { t.Fatalf("Error creating disk: %s", err) } - waitErr := computeOperationWaitTime(config, op, config.Project, "disk to create", config.userAgent, 4*time.Minute) + d := &schema.ResourceData{} + waitErr := computeOperationWaitTime(d, config, op, config.Project, "disk to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -414,7 +420,7 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromSource(t *testing.T if err != nil { t.Fatalf("Error creating instance: %s", err) } - waitErr = computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + waitErr = computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -483,7 +489,8 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromEncryptionKey(t *testing if err != nil { t.Fatalf("Error creating instance: %s", err) } - waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + d := &schema.ResourceData{} + waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -552,7 +559,8 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromEncryptionKey(t *te if err != nil { t.Fatalf("Error creating instance: %s", err) } - waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + d := &schema.ResourceData{} + waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -623,7 +631,8 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromAutoDeleteAndImage(t *te if err != nil { t.Fatalf("Error creating instance: %s", err) } - waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + d := &schema.ResourceData{} + waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -696,7 +705,8 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromAutoDeleteAndImage( if err != nil { t.Fatalf("Error creating instance: %s", err) } - waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + d := &schema.ResourceData{} + waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -765,7 +775,8 @@ func TestAccComputeInstanceMigrateState_scratchDisk(t *testing.T) { if err != nil { t.Fatalf("Error creating instance: %s", err) } - waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + d := &schema.ResourceData{} + waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -830,7 +841,8 @@ func TestAccComputeInstanceMigrateState_v4FixScratchDisk(t *testing.T) { if err != nil { t.Fatalf("Error creating instance: %s", err) } - waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + d := &schema.ResourceData{} + waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -909,7 +921,8 @@ func cleanUpInstance(config *Config, instanceName, zone string) { } // Wait for the operation to complete - opErr := computeOperationWaitTime(config, op, config.Project, "instance to delete", config.userAgent, 4*time.Minute) + d := &schema.ResourceData{} + opErr := computeOperationWaitTime(d, config, op, config.Project, "instance to delete", config.userAgent, 4*time.Minute) if opErr != nil { log.Printf("[WARNING] Error deleting instance %q, dangling resources may exist: %s", instanceName, opErr) } @@ -923,7 +936,8 @@ func cleanUpDisk(config *Config, diskName, zone string) { } // Wait for the operation to complete - opErr := computeOperationWaitTime(config, op, config.Project, "disk to delete", config.userAgent, 4*time.Minute) + d := &schema.ResourceData{} + opErr := computeOperationWaitTime(d, config, op, config.Project, "disk to delete", config.userAgent, 4*time.Minute) if opErr != nil { log.Printf("[WARNING] Error deleting disk %q, dangling resources may exist: %s", diskName, opErr) } diff --git a/mmv1/third_party/terraform/tests/resource_compute_instance_test.go b/mmv1/third_party/terraform/tests/resource_compute_instance_test.go index 4fef38157016..a0b0bda80a38 100644 --- a/mmv1/third_party/terraform/tests/resource_compute_instance_test.go +++ b/mmv1/third_party/terraform/tests/resource_compute_instance_test.go @@ -12,6 +12,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" computeBeta "google.golang.org/api/compute/v0.beta" "google.golang.org/api/compute/v1" @@ -2165,7 +2166,8 @@ func testAccCheckComputeInstanceUpdateMachineType(t *testing.T, n string) resour if err != nil { return fmt.Errorf("Could not stop instance: %s", err) } - err = computeOperationWaitTime(config, op, config.Project, "Waiting on stop", config.userAgent, 20*time.Minute) + d := &schema.ResourceData{} + err = computeOperationWaitTime(d, config, op, config.Project, "Waiting on stop", config.userAgent, 20*time.Minute) if err != nil { return fmt.Errorf("Could not stop instance: %s", err) } @@ -2179,7 +2181,7 @@ func testAccCheckComputeInstanceUpdateMachineType(t *testing.T, n string) resour if err != nil { return fmt.Errorf("Could not change machine type: %s", err) } - err = computeOperationWaitTime(config, op, config.Project, "Waiting machine type change", config.userAgent, 20*time.Minute) + err = computeOperationWaitTime(d, config, op, config.Project, "Waiting machine type change", config.userAgent, 20*time.Minute) if err != nil { return fmt.Errorf("Could not change machine type: %s", err) } diff --git a/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go.erb b/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go.erb index 08ad48a2f9a7..ce756f02c4e7 100644 --- a/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go.erb @@ -9,6 +9,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" sqladmin "google.golang.org/api/sqladmin/v1beta4" ) @@ -105,7 +106,7 @@ func testSweepDatabases(region string) error { return nil } - err = sqlAdminOperationWaitTime(config, op, config.Project, "Stop Replica", config.userAgent, 10 * time.Minute) + err = sqlAdminOperationWaitTime(&schema.ResourceData{}, config, op, config.Project, "Stop Replica", config.userAgent, 10 * time.Minute) if err != nil { if strings.Contains(err.Error(), "does not exist") { log.Printf("Replication operation not found") @@ -137,7 +138,7 @@ func testSweepDatabases(region string) error { return nil } - err = sqlAdminOperationWaitTime(config, op, config.Project, "Delete Instance", config.userAgent, 10 * time.Minute) + err = sqlAdminOperationWaitTime(&schema.ResourceData{}, config, op, config.Project, "Delete Instance", config.userAgent, 10 * time.Minute) if err != nil { if strings.Contains(err.Error(), "does not exist") { log.Printf("SQL instance not found") @@ -262,7 +263,7 @@ func TestAccSqlDatabaseInstance_dontDeleteDefaultUserOnReplica(t *testing.T) { t.Errorf("Error while inserting root@%% user: %s", err) return } - err = sqlAdminOperationWaitTime(config, op, config.Project, "Waiting for user to insert", config.userAgent, 10 * time.Minute) + err = sqlAdminOperationWaitTime(&schema.ResourceData{}, config, op, config.Project, "Waiting for user to insert", config.userAgent, 10 * time.Minute) if err != nil { t.Errorf("Error while waiting for user insert operation to complete: %s", err.Error()) } diff --git a/mmv1/third_party/terraform/utils/appengine_operation.go b/mmv1/third_party/terraform/utils/appengine_operation.go index d6401b71d81d..2dd916269de2 100644 --- a/mmv1/third_party/terraform/utils/appengine_operation.go +++ b/mmv1/third_party/terraform/utils/appengine_operation.go @@ -6,6 +6,7 @@ import ( "regexp" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "google.golang.org/api/appengine/v1" ) @@ -17,6 +18,7 @@ type AppEngineOperationWaiter struct { Service *appengine.APIService AppId string CommonOperationWaiter + d *schema.ResourceData } func (w *AppEngineOperationWaiter) QueryOp() (interface{}, error) { @@ -30,7 +32,7 @@ func (w *AppEngineOperationWaiter) QueryOp() (interface{}, error) { return w.Service.Apps.Operations.Get(w.AppId, matches[1]).Do() } -func appEngineOperationWaitTimeWithResponse(config *Config, res interface{}, response *map[string]interface{}, appId, activity, userAgent string, timeout time.Duration) error { +func appEngineOperationWaitTimeWithResponse(d *schema.ResourceData, config *Config, res interface{}, response *map[string]interface{}, appId, activity, userAgent string, timeout time.Duration) error { op := &appengine.Operation{} err := Convert(res, op) if err != nil { @@ -40,6 +42,7 @@ func appEngineOperationWaitTimeWithResponse(config *Config, res interface{}, res w := &AppEngineOperationWaiter{ Service: config.NewAppEngineClient(userAgent), AppId: appId, + d: d, } if err := w.SetOp(op); err != nil { @@ -51,7 +54,7 @@ func appEngineOperationWaitTimeWithResponse(config *Config, res interface{}, res return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response) } -func appEngineOperationWaitTime(config *Config, res interface{}, appId, activity, userAgent string, timeout time.Duration) error { +func appEngineOperationWaitTime(d *schema.ResourceData, config *Config, res interface{}, appId, activity, userAgent string, timeout time.Duration) error { op := &appengine.Operation{} err := Convert(res, op) if err != nil { @@ -61,6 +64,7 @@ func appEngineOperationWaitTime(config *Config, res interface{}, appId, activity w := &AppEngineOperationWaiter{ Service: config.NewAppEngineClient(userAgent), AppId: appId, + d: d, } if err := w.SetOp(op); err != nil { diff --git a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go index 64b12dcff22d..b67413710a95 100644 --- a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go +++ b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go @@ -9,6 +9,7 @@ import ( "testing" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "google.golang.org/api/cloudkms/v1" cloudresourcemanager "google.golang.org/api/cloudresourcemanager/v1" "google.golang.org/api/iam/v1" @@ -246,7 +247,7 @@ func BootstrapSharedTestNetwork(t *testing.T, testId string) string { } log.Printf("[DEBUG] Waiting for network creation to finish") - err = computeOperationWaitTime(config, res, project, "Error bootstrapping shared test network", config.userAgent, 4*time.Minute) + err = computeOperationWaitTime(&schema.ResourceData{}, config, res, project, "Error bootstrapping shared test network", config.userAgent, 4*time.Minute) if err != nil { t.Fatalf("Error bootstrapping shared test network %q: %s", networkName, err) } @@ -302,7 +303,7 @@ func BootstrapServicePerimeterProjects(t *testing.T, desiredProjects int) []*clo t.Fatalf("Error bootstrapping shared test project: %s", err) } - err = resourceManagerOperationWaitTime(config, opAsMap, "creating project", config.userAgent, 4) + err = resourceManagerOperationWaitTime(&schema.ResourceData{}, config, opAsMap, "creating project", config.userAgent, 4) if err != nil { t.Fatalf("Error bootstrapping shared test project: %s", err) } @@ -395,7 +396,7 @@ func BootstrapSharedSQLInstanceBackupRun(t *testing.T) string { if err != nil { t.Fatalf("Error, failed to create instance %s: %s", bootstrapInstance.Name, err) } - err = sqlAdminOperationWaitTime(config, op, project, "Create Instance", config.userAgent, time.Duration(20)*time.Minute) + err = sqlAdminOperationWaitTime(&schema.ResourceData{}, config, op, project, "Create Instance", config.userAgent, time.Duration(20)*time.Minute) if err != nil { t.Fatalf("Error, failed to create instance %s: %s", bootstrapInstance.Name, err) } @@ -421,7 +422,7 @@ func BootstrapSharedSQLInstanceBackupRun(t *testing.T) string { if err != nil { t.Fatalf("Error, failed to create instance backup: %s", err) } - err = sqlAdminOperationWaitTime(config, op, project, "Backup Instance", config.userAgent, time.Duration(20)*time.Minute) + err = sqlAdminOperationWaitTime(&schema.ResourceData{}, config, op, project, "Backup Instance", config.userAgent, time.Duration(20)*time.Minute) if err != nil { t.Fatalf("Error, failed to create instance backup: %s", err) } diff --git a/mmv1/third_party/terraform/utils/compute_instance_network_interface_helpers.go b/mmv1/third_party/terraform/utils/compute_instance_network_interface_helpers.go index b8c72d4669a5..b7747c81c2ad 100644 --- a/mmv1/third_party/terraform/utils/compute_instance_network_interface_helpers.go +++ b/mmv1/third_party/terraform/utils/compute_instance_network_interface_helpers.go @@ -16,7 +16,7 @@ func computeInstanceDeleteAccessConfigs(d *schema.ResourceData, config *Config, if err != nil { return fmt.Errorf("Error deleting old access_config: %s", err) } - opErr := computeOperationWaitTime(config, op, project, "old access_config to delete", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "old access_config to delete", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -31,7 +31,7 @@ func computeInstanceAddAccessConfigs(d *schema.ResourceData, config *Config, ins if err != nil { return fmt.Errorf("Error adding new access_config: %s", err) } - opErr := computeOperationWaitTime(config, op, project, "new access_config to add", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "new access_config to add", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -65,7 +65,7 @@ func computeInstanceCreateUpdateWhileStoppedCall(d *schema.ResourceData, config if err != nil { return errwrap.Wrapf("Error updating network interface: {{err}}", err) } - opErr := computeOperationWaitTime(config, op, project, "network interface to update", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(d, config, op, project, "network interface to update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } diff --git a/mmv1/third_party/terraform/utils/compute_operation.go.erb b/mmv1/third_party/terraform/utils/compute_operation.go.erb index ddb422386a59..7da1e2afdb30 100644 --- a/mmv1/third_party/terraform/utils/compute_operation.go.erb +++ b/mmv1/third_party/terraform/utils/compute_operation.go.erb @@ -26,6 +26,7 @@ type ComputeOperationWaiter struct { <% unless version == 'ga' -%> Parent string <% end -%> + d *schema.ResourceData } func (w *ComputeOperationWaiter) State() string { @@ -110,7 +111,7 @@ func (w *ComputeOperationWaiter) TargetStates() []string { return []string{"DONE"} } -func computeOperationWaitTime(config *Config, res interface{}, project, activity, userAgent string, timeout time.Duration) error { +func computeOperationWaitTime(d *schema.ResourceData, config *Config, res interface{}, project, activity, userAgent string, timeout time.Duration) error { <% if version == 'ga' -%> op := &compute.Operation{} <% else -%> @@ -130,6 +131,7 @@ func computeOperationWaitTime(config *Config, res interface{}, project, activity Context: config.context, Op: op, Project: project, + d: d, } if err := w.SetOp(op); err != nil { @@ -139,7 +141,7 @@ func computeOperationWaitTime(config *Config, res interface{}, project, activity } <% unless version == 'ga' -%> -func computeOrgOperationWaitTimeWithResponse(config *Config, res interface{}, response *map[string]interface{}, parent, activity, userAgent string, timeout time.Duration) error { +func computeOrgOperationWaitTimeWithResponse(d *schema.ResourceData, config *Config, res interface{}, response *map[string]interface{}, parent, activity, userAgent string, timeout time.Duration) error { op := &computeBeta.Operation{} err := Convert(res, op) if err != nil { @@ -150,6 +152,7 @@ func computeOrgOperationWaitTimeWithResponse(config *Config, res interface{}, re Service: config.NewComputeBetaClient(userAgent), Op: op, Parent: parent, + d: d, } if err := w.SetOp(op); err != nil { diff --git a/mmv1/third_party/terraform/utils/compute_shared_operation.go b/mmv1/third_party/terraform/utils/compute_shared_operation.go deleted file mode 100644 index 4710ed024a9f..000000000000 --- a/mmv1/third_party/terraform/utils/compute_shared_operation.go +++ /dev/null @@ -1,4 +0,0 @@ -package google - -// Empty file so that the build will run tests on terraform-conversion mapper. -// File should be removed once the PR has been merged. diff --git a/mmv1/third_party/terraform/utils/deployment_manager_operation.go.erb b/mmv1/third_party/terraform/utils/deployment_manager_operation.go.erb index e1b0d6a360bb..1ad7cf07fabd 100644 --- a/mmv1/third_party/terraform/utils/deployment_manager_operation.go.erb +++ b/mmv1/third_party/terraform/utils/deployment_manager_operation.go.erb @@ -16,6 +16,7 @@ type DeploymentManagerOperationWaiter struct { Project string OperationUrl string ComputeOperationWaiter + d *schema.ResourceData } func (w *DeploymentManagerOperationWaiter) IsRetryable(error) bool { @@ -43,7 +44,7 @@ func (w *DeploymentManagerOperationWaiter) QueryOp() (interface{}, error) { } -func deploymentManagerOperationWaitTime(config *Config, resp interface{}, project, activity, userAgent string, timeout time.Duration) error { +func deploymentManagerOperationWaitTime(d *schema.ResourceData, config *Config, resp interface{}, project, activity, userAgent string, timeout time.Duration) error { <% if version == 'ga' -%> op := &compute.Operation{} <% else -%> @@ -61,6 +62,7 @@ func deploymentManagerOperationWaitTime(config *Config, resp interface{}, projec ComputeOperationWaiter: ComputeOperationWaiter{ Project: project, }, + d: d, } if err := w.SetOp(op); err != nil { return err diff --git a/mmv1/third_party/terraform/utils/service_networking_operation.go b/mmv1/third_party/terraform/utils/service_networking_operation.go index fa7695b36764..9e858de1f733 100644 --- a/mmv1/third_party/terraform/utils/service_networking_operation.go +++ b/mmv1/third_party/terraform/utils/service_networking_operation.go @@ -3,21 +3,24 @@ package google import ( "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "google.golang.org/api/servicenetworking/v1" ) type ServiceNetworkingOperationWaiter struct { Service *servicenetworking.APIService CommonOperationWaiter + d *schema.ResourceData } func (w *ServiceNetworkingOperationWaiter) QueryOp() (interface{}, error) { return w.Service.Operations.Get(w.Op.Name).Do() } -func serviceNetworkingOperationWaitTime(config *Config, op *servicenetworking.Operation, activity, userAgent string, timeout time.Duration) error { +func serviceNetworkingOperationWaitTime(d *schema.ResourceData, config *Config, op *servicenetworking.Operation, activity, userAgent string, timeout time.Duration) error { w := &ServiceNetworkingOperationWaiter{ Service: config.NewServiceNetworkingClient(userAgent), + d: d, } if err := w.SetOp(op); err != nil { diff --git a/mmv1/third_party/terraform/utils/serviceusage_batching.go b/mmv1/third_party/terraform/utils/serviceusage_batching.go index 9504e82153a9..7c7b36644622 100644 --- a/mmv1/third_party/terraform/utils/serviceusage_batching.go +++ b/mmv1/third_party/terraform/utils/serviceusage_batching.go @@ -31,7 +31,7 @@ func BatchRequestEnableService(service string, project string, d *schema.Resourc ResourceName: project, Body: []string{service}, CombineF: combineServiceUsageServicesBatches, - SendF: sendBatchFuncEnableServices(config, userAgent, d.Timeout(schema.TimeoutCreate)), + SendF: sendBatchFuncEnableServices(d, config, userAgent, d.Timeout(schema.TimeoutCreate)), DebugId: fmt.Sprintf("Enable Project Service %q for project %q", service, project), } @@ -52,10 +52,10 @@ func tryEnableRenamedService(service, altName string, project string, d *schema. // use a short timeout- failures are likely log.Printf("[DEBUG] attempting enabling service with user-specified name %s", service) - err = enableServiceUsageProjectServices([]string{service}, project, userAgent, config, 1*time.Minute) + err = enableServiceUsageProjectServices([]string{service}, project, userAgent, d, config, 1*time.Minute) if err != nil { log.Printf("[DEBUG] saw error %s. attempting alternate name %v", err, altName) - err2 := enableServiceUsageProjectServices([]string{altName}, project, userAgent, config, 1*time.Minute) + err2 := enableServiceUsageProjectServices([]string{altName}, project, userAgent, d, config, 1*time.Minute) if err2 != nil { return fmt.Errorf("Saw 2 subsequent errors attempting to enable a renamed service: %s / %s", err, err2) } @@ -97,13 +97,13 @@ func combineServiceUsageServicesBatches(srvsRaw interface{}, toAddRaw interface{ return append(srvs, toAdd...), nil } -func sendBatchFuncEnableServices(config *Config, userAgent string, timeout time.Duration) BatcherSendFunc { +func sendBatchFuncEnableServices(d *schema.ResourceData, config *Config, userAgent string, timeout time.Duration) BatcherSendFunc { return func(project string, toEnableRaw interface{}) (interface{}, error) { toEnable, ok := toEnableRaw.([]string) if !ok { return nil, fmt.Errorf("Expected batch body type to be []string, got %v. This is a provider error.", toEnableRaw) } - return nil, enableServiceUsageProjectServices(toEnable, project, userAgent, config, timeout) + return nil, enableServiceUsageProjectServices(toEnable, project, userAgent, d, config, timeout) } } diff --git a/mmv1/third_party/terraform/utils/serviceusage_operation.go b/mmv1/third_party/terraform/utils/serviceusage_operation.go index 6ed1c4cbd31b..12571a6c600c 100644 --- a/mmv1/third_party/terraform/utils/serviceusage_operation.go +++ b/mmv1/third_party/terraform/utils/serviceusage_operation.go @@ -4,11 +4,12 @@ import ( "encoding/json" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "google.golang.org/api/googleapi" "google.golang.org/api/serviceusage/v1" ) -func serviceUsageOperationWait(config *Config, op *serviceusage.Operation, project, activity, userAgent string, timeout time.Duration) error { +func serviceUsageOperationWait(d *schema.ResourceData, config *Config, op *serviceusage.Operation, project, activity, userAgent string, timeout time.Duration) error { // maintained for compatibility with old code that was written before the // autogenerated waiters. b, err := op.MarshalJSON() @@ -19,7 +20,7 @@ func serviceUsageOperationWait(config *Config, op *serviceusage.Operation, proje if err := json.Unmarshal(b, &m); err != nil { return err } - return serviceUsageOperationWaitTime(config, m, project, activity, userAgent, timeout) + return serviceUsageOperationWaitTime(d, config, m, project, activity, userAgent, timeout) } func handleServiceUsageRetryableError(err error) error { diff --git a/mmv1/third_party/terraform/utils/sqladmin_operation.go b/mmv1/third_party/terraform/utils/sqladmin_operation.go index e5010e5dc0e2..e53a2381468b 100644 --- a/mmv1/third_party/terraform/utils/sqladmin_operation.go +++ b/mmv1/third_party/terraform/utils/sqladmin_operation.go @@ -6,6 +6,7 @@ import ( "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" sqladmin "google.golang.org/api/sqladmin/v1beta4" ) @@ -13,6 +14,7 @@ type SqlAdminOperationWaiter struct { Service *sqladmin.Service Op *sqladmin.Operation Project string + d *schema.ResourceData } func (w *SqlAdminOperationWaiter) State() string { @@ -100,7 +102,7 @@ func (w *SqlAdminOperationWaiter) TargetStates() []string { return []string{"DONE"} } -func sqlAdminOperationWaitTime(config *Config, res interface{}, project, activity, userAgent string, timeout time.Duration) error { +func sqlAdminOperationWaitTime(d *schema.ResourceData, config *Config, res interface{}, project, activity, userAgent string, timeout time.Duration) error { op := &sqladmin.Operation{} err := Convert(res, op) if err != nil { @@ -111,6 +113,7 @@ func sqlAdminOperationWaitTime(config *Config, res interface{}, project, activit Service: config.NewSqlAdminClient(userAgent), Op: op, Project: project, + d: d, } if err := w.SetOp(op); err != nil { return err From 859db057e04c70dc87f76f31be78ad79ce25bef2 Mon Sep 17 00:00:00 2001 From: upodroid Date: Fri, 18 Jun 2021 19:10:14 +0100 Subject: [PATCH 3/4] fetch region from self_link --- README.md | 2 +- mmv1/products/vertexai/api.yaml | 6 +- mmv1/products/vertexai/terraform.yaml | 6 +- .../active_directory_domain_trust.go.erb | 2 +- .../custom_delete/appversion_delete.go.erb | 4 +- .../custom_delete/per_instance_config.go.erb | 4 +- .../region_per_instance_config.go.erb | 4 +- ...eplace_all_access_levels_empty_list.go.erb | 2 +- ...e_all_service_perimeters_empty_list.go.erb | 2 +- mmv1/templates/terraform/operation.go.erb | 22 ++---- ...ute_backend_service_security_policy.go.erb | 2 +- .../compute_network_delete_default_route.erb | 2 +- .../terraform/post_create/labels.erb | 2 +- .../post_create/org_security_policy.go.erb | 2 +- .../org_security_policy_association.go.erb | 2 +- .../org_security_policy_rule.go.erb | 2 +- .../post_delete/org_security_policy.go.erb | 2 +- .../compute_per_instance_config.go.erb | 2 +- .../compute_region_per_instance_config.go.erb | 2 +- .../post_update/org_security_policy.go.erb | 2 +- .../terraform/pre_delete/detach_disk.erb | 2 +- .../privateca_certificate_authority.go.erb | 2 +- mmv1/templates/terraform/resource.erb | 10 +-- .../resource_app_engine_application.go | 4 +- .../resource_compute_attached_disk.go | 4 +- .../resources/resource_compute_instance.go | 40 +++++------ ...compute_instance_from_machine_image.go.erb | 2 +- ...resource_compute_instance_from_template.go | 2 +- .../resource_compute_instance_group.go | 12 ++-- ...urce_compute_instance_group_manager.go.erb | 14 ++-- .../resource_compute_instance_template.go.erb | 4 +- .../resource_compute_network_peering.go | 6 +- ...ce_compute_project_default_network_tier.go | 2 +- .../resource_compute_project_metadata.go | 8 +-- .../resource_compute_project_metadata_item.go | 10 +-- ...mpute_region_instance_group_manager.go.erb | 10 +-- .../resource_compute_router_interface.go | 4 +- .../resource_compute_security_policy.go.erb | 12 ++-- ...esource_compute_shared_vpc_host_project.go | 4 +- ...urce_compute_shared_vpc_service_project.go | 4 +- .../resources/resource_compute_target_pool.go | 14 ++-- .../resources/resource_google_folder.go | 4 +- .../resources/resource_google_project.go | 20 +++--- .../resource_google_project_service.go | 2 +- .../resource_project_service_identity.go.erb | 2 +- .../resource_service_networking_connection.go | 6 +- .../resource_sql_database_instance.go.erb | 12 ++-- .../resources/resource_sql_ssl_cert.go | 4 +- .../terraform/resources/resource_sql_user.go | 6 +- .../resources/resource_usage_export_bucket.go | 4 +- .../resource_composer_environment_test.go.erb | 3 +- .../resource_compute_instance_migrate_test.go | 44 ++++-------- .../tests/resource_compute_instance_test.go | 6 +- ...resource_sql_database_instance_test.go.erb | 7 +- .../terraform/utils/appengine_operation.go | 8 +-- .../terraform/utils/bootstrap_utils_test.go | 9 ++- ...pute_instance_network_interface_helpers.go | 6 +- .../terraform/utils/compute_operation.go.erb | 7 +- .../utils/deployment_manager_operation.go.erb | 4 +- .../terraform/utils/self_link_helpers.go | 12 ++++ .../utils/service_networking_operation.go | 5 +- .../terraform/utils/serviceusage_batching.go | 10 +-- .../terraform/utils/serviceusage_operation.go | 5 +- .../terraform/utils/sqladmin_operation.go | 5 +- .../utils/vertex_ai_operation.go.erb | 69 +++++++++++++++++++ 65 files changed, 271 insertions(+), 233 deletions(-) create mode 100644 mmv1/third_party/terraform/utils/vertex_ai_operation.go.erb diff --git a/README.md b/README.md index 09e3e49f3b64..c473ae3fe87c 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ For Ansible and Inspec, wherever you have cloned those repositories. For example, to generate Terraform: ```bash -bundle exec compiler -a -v "ga" -e terraform -o "$GOPATH/src/github.com/hashicorp/terraform-provider-google" +bundle exec compiler -e terraform -o "$GOPATH/src/github.com/hashicorp/terraform-provider-google" -v "ga" -a ``` It's worth noting that Magic Modules will only generate new files when ran diff --git a/mmv1/products/vertexai/api.yaml b/mmv1/products/vertexai/api.yaml index 3324192dd83f..55ba55db5db9 100644 --- a/mmv1/products/vertexai/api.yaml +++ b/mmv1/products/vertexai/api.yaml @@ -18,9 +18,9 @@ versions: - !ruby/object:Api::Product::Version name: ga base_url: https://{{region}}-aiplatform.googleapis.com/v1/ - # - !ruby/object:Api::Product::Version - # name: beta - # base_url: https://{{region}}-aiplatform.googleapis.com/v1beta1/ + - !ruby/object:Api::Product::Version + name: beta + base_url: https://{{region}}-aiplatform.googleapis.com/v1beta1/ scopes: - https://www.googleapis.com/auth/cloud-platform objects: diff --git a/mmv1/products/vertexai/terraform.yaml b/mmv1/products/vertexai/terraform.yaml index 9a96715d2efb..751410b8207d 100644 --- a/mmv1/products/vertexai/terraform.yaml +++ b/mmv1/products/vertexai/terraform.yaml @@ -14,10 +14,10 @@ --- !ruby/object:Provider::Terraform::Config overrides: !ruby/object:Overrides::ResourceOverrides Dataset: !ruby/object:Overrides::Terraform::ResourceOverride - autogen_async: true + autogen_async: false id_format: '{{name}}' exclude_import: true - # import_format: ["projects/{{project}}/locations/{{region}}/datasets/{{name}}"] + skip_sweeper: true timeouts: !ruby/object:Api::Timeouts insert_minutes: 6 update_minutes: 6 @@ -25,7 +25,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides examples: - !ruby/object:Provider::Terraform::Examples name: "vertex_ai_dataset" - # skip_import_test: true + skip_import_test: true primary_resource_id: "dataset" vars: display_name: "terraform" diff --git a/mmv1/templates/terraform/custom_delete/active_directory_domain_trust.go.erb b/mmv1/templates/terraform/custom_delete/active_directory_domain_trust.go.erb index 7ce571b8031e..0bacbeccb950 100644 --- a/mmv1/templates/terraform/custom_delete/active_directory_domain_trust.go.erb +++ b/mmv1/templates/terraform/custom_delete/active_directory_domain_trust.go.erb @@ -61,7 +61,7 @@ } err = activeDirectoryOperationWaitTime( - d, config, res, project, "Deleting DomainTrust", userAgent, + config, res, project, "Deleting DomainTrust", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { diff --git a/mmv1/templates/terraform/custom_delete/appversion_delete.go.erb b/mmv1/templates/terraform/custom_delete/appversion_delete.go.erb index c9ffefefdbf4..b94147861ed8 100644 --- a/mmv1/templates/terraform/custom_delete/appversion_delete.go.erb +++ b/mmv1/templates/terraform/custom_delete/appversion_delete.go.erb @@ -28,7 +28,7 @@ if d.Get("delete_service_on_destroy") == true { return handleNotFoundError(err, d, "Service") } err = appEngineOperationWaitTime( - d, config, res, project, "Deleting Service", userAgent, + config, res, project, "Deleting Service", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { @@ -48,7 +48,7 @@ if d.Get("delete_service_on_destroy") == true { return handleNotFoundError(err, d, "AppVersion") } err = appEngineOperationWaitTime( - d, config, res, project, "Deleting AppVersion", userAgent, + config, res, project, "Deleting AppVersion", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { diff --git a/mmv1/templates/terraform/custom_delete/per_instance_config.go.erb b/mmv1/templates/terraform/custom_delete/per_instance_config.go.erb index 639370350731..a26ec6399e2d 100644 --- a/mmv1/templates/terraform/custom_delete/per_instance_config.go.erb +++ b/mmv1/templates/terraform/custom_delete/per_instance_config.go.erb @@ -27,7 +27,7 @@ } err = computeOperationWaitTime( - d, config, res, project, "Deleting PerInstanceConfig", userAgent, + config, res, project, "Deleting PerInstanceConfig", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { @@ -59,7 +59,7 @@ } err = computeOperationWaitTime( - d, config, res, project, "Applying update to PerInstanceConfig", userAgent, + config, res, project, "Applying update to PerInstanceConfig", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return fmt.Errorf("Error deleting PerInstanceConfig %q: %s", d.Id(), err) diff --git a/mmv1/templates/terraform/custom_delete/region_per_instance_config.go.erb b/mmv1/templates/terraform/custom_delete/region_per_instance_config.go.erb index a31e6d0f63a5..bb9c09db776b 100644 --- a/mmv1/templates/terraform/custom_delete/region_per_instance_config.go.erb +++ b/mmv1/templates/terraform/custom_delete/region_per_instance_config.go.erb @@ -27,7 +27,7 @@ } err = computeOperationWaitTime( - d, config, res, project, "Deleting RegionPerInstanceConfig", userAgent, + config, res, project, "Deleting RegionPerInstanceConfig", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { @@ -59,7 +59,7 @@ } err = computeOperationWaitTime( - d, config, res, project, "Applying update to PerInstanceConfig", userAgent, + config, res, project, "Applying update to PerInstanceConfig", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { diff --git a/mmv1/templates/terraform/custom_delete/replace_all_access_levels_empty_list.go.erb b/mmv1/templates/terraform/custom_delete/replace_all_access_levels_empty_list.go.erb index 8a80b9caf8c1..25c5e2f8c1b0 100644 --- a/mmv1/templates/terraform/custom_delete/replace_all_access_levels_empty_list.go.erb +++ b/mmv1/templates/terraform/custom_delete/replace_all_access_levels_empty_list.go.erb @@ -16,7 +16,7 @@ if err != nil { } err = accessContextManagerOperationWaitTime( - d, config, res, "Updating AccessLevels", userAgent, + config, res, "Updating AccessLevels", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { diff --git a/mmv1/templates/terraform/custom_delete/replace_all_service_perimeters_empty_list.go.erb b/mmv1/templates/terraform/custom_delete/replace_all_service_perimeters_empty_list.go.erb index 59103e11f7ce..452afec19731 100644 --- a/mmv1/templates/terraform/custom_delete/replace_all_service_perimeters_empty_list.go.erb +++ b/mmv1/templates/terraform/custom_delete/replace_all_service_perimeters_empty_list.go.erb @@ -16,7 +16,7 @@ if err != nil { } err = accessContextManagerOperationWaitTime( - d, config, res, "Updating ServicePerimeters", userAgent, + config, res, "Updating ServicePerimeters", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { diff --git a/mmv1/templates/terraform/operation.go.erb b/mmv1/templates/terraform/operation.go.erb index 4f2ee191510d..55dad8bcb4a0 100644 --- a/mmv1/templates/terraform/operation.go.erb +++ b/mmv1/templates/terraform/operation.go.erb @@ -16,7 +16,6 @@ type <%= product_name -%>OperationWaiter struct { Project string <% end -%> CommonOperationWaiter - d *schema.ResourceData } func (w *<%= product_name -%>OperationWaiter) QueryOp() (interface{}, error) { @@ -26,23 +25,16 @@ func (w *<%= product_name -%>OperationWaiter) QueryOp() (interface{}, error) { // Returns the proper get. url := fmt.Sprintf("<%= [object.__product.base_url, async.operation.base_url].flatten.join.gsub('{{op_id}}', '%s') -%>", w.CommonOperationWaiter.Op.Name) - // This is for regional API endpoints like Vertex AI that need to infer the subdomain prefix in *.googleapis.com from d such as https://{{region}}-aiplatform.googleapis.com/v1/ - parsedUrl, err := replaceVars(w.d, w.Config, url) - if err != nil { - return nil, err - } - - return sendRequest(w.Config, "GET", <% if has_project %>w.Project<% else %>""<% end %>, parsedUrl, w.UserAgent, nil<%= object.error_retry_predicates ? ", " + object.error_retry_predicates.join(',') : "" -%>) + return sendRequest(w.Config, "GET", <% if has_project %>w.Project<% else %>""<% end %>, url, w.UserAgent, nil<%= object.error_retry_predicates ? ", " + object.error_retry_predicates.join(',') : "" -%>) } -func create<%= product_name %>Waiter(d *schema.ResourceData, config *Config, op map[string]interface{}, <% if has_project -%> project, <% end -%> activity, userAgent string) (*<%=product_name%>OperationWaiter, error) { +func create<%= product_name %>Waiter(config *Config, op map[string]interface{}, <% if has_project -%> project, <% end -%> activity, userAgent string) (*<%=product_name%>OperationWaiter, error) { w := &<%= product_name -%>OperationWaiter{ Config: config, UserAgent: userAgent, <% if has_project -%> - Project: project, + Project: project, <% end -%> - d: d, } if err := w.CommonOperationWaiter.SetOp(op); err != nil { return nil, err @@ -56,8 +48,8 @@ func create<%= product_name %>Waiter(d *schema.ResourceData, config *Config, op Might as well just nolint it so we can pass the linter checks. -%> // nolint: deadcode,unused -func <%= product_name.camelize(:lower) -%>OperationWaitTimeWithResponse(d *schema.ResourceData, config *Config, op map[string]interface{}, response *map[string]interface{},<% if has_project -%> project,<% end -%> activity, userAgent string, timeout time.Duration) error { - w, err := create<%= product_name %>Waiter(d, config, op, <% if has_project -%> project, <%end-%> activity, userAgent) +func <%= product_name.camelize(:lower) -%>OperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{},<% if has_project -%> project,<% end -%> activity, userAgent string, timeout time.Duration) error { + w, err := create<%= product_name %>Waiter(config, op, <% if has_project -%> project, <%end-%> activity, userAgent) if err != nil { return err } @@ -68,12 +60,12 @@ func <%= product_name.camelize(:lower) -%>OperationWaitTimeWithResponse(d *schem } <% end -%> -func <%= product_name.camelize(:lower) -%>OperationWaitTime(d *schema.ResourceData, config *Config, op map[string]interface{}, <% if has_project -%> project,<% end -%> activity, userAgent string, timeout time.Duration) error { +func <%= product_name.camelize(:lower) -%>OperationWaitTime(config *Config, op map[string]interface{}, <% if has_project -%> project,<% end -%> activity, userAgent string, timeout time.Duration) error { if val, ok := op["name"]; !ok || val == "" { // This was a synchronous call - there is no operation to wait for. return nil } - w, err := create<%= product_name %>Waiter(d, config, op, <% if has_project -%> project, <%end-%> activity, userAgent) + w, err := create<%= product_name %>Waiter(config, op, <% if has_project -%> project, <%end-%> activity, userAgent) if err != nil { // If w is nil, the op was synchronous. return err diff --git a/mmv1/templates/terraform/post_create/compute_backend_service_security_policy.go.erb b/mmv1/templates/terraform/post_create/compute_backend_service_security_policy.go.erb index ffd9cf70f44a..28008867463e 100644 --- a/mmv1/templates/terraform/post_create/compute_backend_service_security_policy.go.erb +++ b/mmv1/templates/terraform/post_create/compute_backend_service_security_policy.go.erb @@ -12,7 +12,7 @@ if o, n := d.GetChange("security_policy"); o.(string) != n.(string) { return errwrap.Wrapf("Error setting Backend Service security policy: {{err}}", err) } // This uses the create timeout for simplicity, though technically this code appears in both create and update - waitErr := computeOperationWaitTime(d, config, op, project, "Setting Backend Service Security Policy", userAgent, d.Timeout(schema.TimeoutCreate)) + waitErr := computeOperationWaitTime(config, op, project, "Setting Backend Service Security Policy", userAgent, d.Timeout(schema.TimeoutCreate)) if waitErr != nil { return waitErr } diff --git a/mmv1/templates/terraform/post_create/compute_network_delete_default_route.erb b/mmv1/templates/terraform/post_create/compute_network_delete_default_route.erb index 6c25ef0624b2..e26445b7c51a 100644 --- a/mmv1/templates/terraform/post_create/compute_network_delete_default_route.erb +++ b/mmv1/templates/terraform/post_create/compute_network_delete_default_route.erb @@ -19,7 +19,7 @@ if d.Get("delete_default_routes_on_create").(bool) { if err != nil { return fmt.Errorf("Error deleting route: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Deleting Route", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, project, "Deleting Route", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } diff --git a/mmv1/templates/terraform/post_create/labels.erb b/mmv1/templates/terraform/post_create/labels.erb index 93a96ce45d76..7616dc339c00 100644 --- a/mmv1/templates/terraform/post_create/labels.erb +++ b/mmv1/templates/terraform/post_create/labels.erb @@ -26,7 +26,7 @@ if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(v)) && (ok || } err = computeOperationWaitTime( - d, config, res, project, "Updating <%= resource_name -%> Labels", userAgent, + config, res, project, "Updating <%= resource_name -%> Labels", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { diff --git a/mmv1/templates/terraform/post_create/org_security_policy.go.erb b/mmv1/templates/terraform/post_create/org_security_policy.go.erb index d0efc382373a..fb84bf2e43cd 100644 --- a/mmv1/templates/terraform/post_create/org_security_policy.go.erb +++ b/mmv1/templates/terraform/post_create/org_security_policy.go.erb @@ -1,7 +1,7 @@ parent := d.Get("parent").(string) var opRes map[string]interface{} err = computeOrgOperationWaitTimeWithResponse( - d, config, res, &opRes, parent, "Creating OrganizationSecurityPolicy", userAgent, + config, res, &opRes, parent, "Creating OrganizationSecurityPolicy", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { diff --git a/mmv1/templates/terraform/post_create/org_security_policy_association.go.erb b/mmv1/templates/terraform/post_create/org_security_policy_association.go.erb index 35f8102a5955..a6dc04d3061e 100644 --- a/mmv1/templates/terraform/post_create/org_security_policy_association.go.erb +++ b/mmv1/templates/terraform/post_create/org_security_policy_association.go.erb @@ -14,7 +14,7 @@ if err != nil { parent := flattenComputeOrganizationSecurityPolicyParent(policyRes["parent"], d, config) var opRes map[string]interface{} err = computeOrgOperationWaitTimeWithResponse( - d, config, res, &opRes, parent.(string), "Creating OrganizationSecurityPolicyAssociation", userAgent, + config, res, &opRes, parent.(string), "Creating OrganizationSecurityPolicyAssociation", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { diff --git a/mmv1/templates/terraform/post_create/org_security_policy_rule.go.erb b/mmv1/templates/terraform/post_create/org_security_policy_rule.go.erb index 531add9cf625..9cc8a76ecf98 100644 --- a/mmv1/templates/terraform/post_create/org_security_policy_rule.go.erb +++ b/mmv1/templates/terraform/post_create/org_security_policy_rule.go.erb @@ -14,7 +14,7 @@ if err != nil { parent := flattenComputeOrganizationSecurityPolicyParent(policyRes["parent"], d, config) var opRes map[string]interface{} err = computeOrgOperationWaitTimeWithResponse( - d, config, res, &opRes, parent.(string), "Creating OrganizationSecurityPolicyRule", userAgent, + config, res, &opRes, parent.(string), "Creating OrganizationSecurityPolicyRule", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { diff --git a/mmv1/templates/terraform/post_delete/org_security_policy.go.erb b/mmv1/templates/terraform/post_delete/org_security_policy.go.erb index a2c807ccf47c..967d96451b00 100644 --- a/mmv1/templates/terraform/post_delete/org_security_policy.go.erb +++ b/mmv1/templates/terraform/post_delete/org_security_policy.go.erb @@ -1,7 +1,7 @@ parent := d.Get("parent").(string) var opRes map[string]interface{} err = computeOrgOperationWaitTimeWithResponse( - d, config, res, &opRes, parent, "Creating OrganizationSecurityPolicy", userAgent, + config, res, &opRes, parent, "Creating OrganizationSecurityPolicy", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { diff --git a/mmv1/templates/terraform/post_update/compute_per_instance_config.go.erb b/mmv1/templates/terraform/post_update/compute_per_instance_config.go.erb index cf9f0e579066..025d5b303291 100644 --- a/mmv1/templates/terraform/post_update/compute_per_instance_config.go.erb +++ b/mmv1/templates/terraform/post_update/compute_per_instance_config.go.erb @@ -32,7 +32,7 @@ if err != nil { } err = computeOperationWaitTime( - d, config, res, project, "Applying update to PerInstanceConfig", userAgent, + config, res, project, "Applying update to PerInstanceConfig", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { diff --git a/mmv1/templates/terraform/post_update/compute_region_per_instance_config.go.erb b/mmv1/templates/terraform/post_update/compute_region_per_instance_config.go.erb index 69e04b5811ca..c66b31769a77 100644 --- a/mmv1/templates/terraform/post_update/compute_region_per_instance_config.go.erb +++ b/mmv1/templates/terraform/post_update/compute_region_per_instance_config.go.erb @@ -32,7 +32,7 @@ if err != nil { } err = computeOperationWaitTime( - d, config, res, project, "Applying update to PerInstanceConfig", userAgent, + config, res, project, "Applying update to PerInstanceConfig", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { diff --git a/mmv1/templates/terraform/post_update/org_security_policy.go.erb b/mmv1/templates/terraform/post_update/org_security_policy.go.erb index e78e1fbf2e4d..69193da7060e 100644 --- a/mmv1/templates/terraform/post_update/org_security_policy.go.erb +++ b/mmv1/templates/terraform/post_update/org_security_policy.go.erb @@ -1,7 +1,7 @@ parent := d.Get("parent").(string) var opRes map[string]interface{} err = computeOrgOperationWaitTimeWithResponse( - d, config, res, &opRes, parent, "Creating OrganizationSecurityPolicy", userAgent, + config, res, &opRes, parent, "Creating OrganizationSecurityPolicy", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { diff --git a/mmv1/templates/terraform/pre_delete/detach_disk.erb b/mmv1/templates/terraform/pre_delete/detach_disk.erb index 718bae3dae47..1e95467bc81e 100644 --- a/mmv1/templates/terraform/pre_delete/detach_disk.erb +++ b/mmv1/templates/terraform/pre_delete/detach_disk.erb @@ -41,7 +41,7 @@ if v, ok := readRes["users"].([]interface{}); ok { return fmt.Errorf("Error detaching disk %s from instance %s/%s/%s: %s", call.deviceName, call.project, call.zone, call.instance, err.Error()) } - err = computeOperationWaitTime(d, config, op, call.project, + err = computeOperationWaitTime(config, op, call.project, fmt.Sprintf("Detaching disk from %s/%s/%s", call.project, call.zone, call.instance), userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { if opErr, ok := err.(ComputeOperationError); ok && len(opErr.Errors) == 1 && opErr.Errors[0].Code == "RESOURCE_NOT_FOUND" { diff --git a/mmv1/templates/terraform/pre_delete/privateca_certificate_authority.go.erb b/mmv1/templates/terraform/pre_delete/privateca_certificate_authority.go.erb index 769836e20320..ccb01d203f14 100644 --- a/mmv1/templates/terraform/pre_delete/privateca_certificate_authority.go.erb +++ b/mmv1/templates/terraform/pre_delete/privateca_certificate_authority.go.erb @@ -11,7 +11,7 @@ if d.Get("disable_on_delete").(bool) && d.Get("state").(string) == "ENABLED" { return err } - err = privatecaOperationWaitTime(d, config, disableRes, project, "Disabling CertificateAuthority", userAgent, d.Timeout(schema.TimeoutDelete)) + err = privatecaOperationWaitTime(config, disableRes, project, "Disabling CertificateAuthority", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/templates/terraform/resource.erb b/mmv1/templates/terraform/resource.erb index 85fff63a147f..cc077c949d6d 100644 --- a/mmv1/templates/terraform/resource.erb +++ b/mmv1/templates/terraform/resource.erb @@ -261,7 +261,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ // identity fields and d.Id() before read var opRes map[string]interface{} err = <%= client_name_camel -%>OperationWaitTimeWithResponse( - d, config, res, &opRes, <% if has_project -%> project, <% end -%> "Creating <%= object.name -%>", userAgent, + config, res, &opRes, <% if has_project -%> project, <% end -%> "Creating <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { <% if object.custom_code.post_create_failure -%> @@ -311,7 +311,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ <% else -%> err = <%= client_name_camel -%>OperationWaitTime( - d, config, res, <% if has_project -%> project, <% end -%> "Creating <%= object.name -%>", userAgent, + config, res, <% if has_project -%> project, <% end -%> "Creating <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { @@ -688,7 +688,7 @@ if <%= props.map { |prop| "d.HasChange(\"#{prop.name.underscore}\")" }.join ' || <% if object.async&.allow?('update') -%> <% if object.async.is_a? Api::OpAsync-%> err = <%= client_name_camel -%>OperationWaitTime( - d, config, res, <% if has_project -%> project, <% end -%> "Updating <%= object.name -%>", userAgent, + config, res, <% if has_project -%> project, <% end -%> "Updating <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err @@ -786,7 +786,7 @@ if <%= props.map { |prop| "d.HasChange(\"#{prop.name.underscore}\")" }.join ' || <% if object.async&.allow?('update') -%> <% if object.async.is_a? Api::OpAsync -%> err = <%= client_name_camel -%>OperationWaitTime( - d, config, res, <% if has_project -%> project, <% end -%> "Updating <%= object.name -%>", userAgent, + config, res, <% if has_project -%> project, <% end -%> "Updating <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { @@ -900,7 +900,7 @@ func resource<%= resource_name -%>Delete(d *schema.ResourceData, meta interface{ } <% else -%> err = <%= client_name_camel -%>OperationWaitTime( - d, config, res, <% if has_project -%> project, <% end -%> "Deleting <%= object.name -%>", userAgent, + config, res, <% if has_project -%> project, <% end -%> "Deleting <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { diff --git a/mmv1/third_party/terraform/resources/resource_app_engine_application.go b/mmv1/third_party/terraform/resources/resource_app_engine_application.go index 8ea70b1877d4..3450939f9a64 100644 --- a/mmv1/third_party/terraform/resources/resource_app_engine_application.go +++ b/mmv1/third_party/terraform/resources/resource_app_engine_application.go @@ -230,7 +230,7 @@ func resourceAppEngineApplicationCreate(d *schema.ResourceData, meta interface{} d.SetId(project) // Wait for the operation to complete - waitErr := appEngineOperationWaitTime(d, config, op, project, "App Engine app to create", userAgent, d.Timeout(schema.TimeoutCreate)) + waitErr := appEngineOperationWaitTime(config, op, project, "App Engine app to create", userAgent, d.Timeout(schema.TimeoutCreate)) if waitErr != nil { d.SetId("") return waitErr @@ -338,7 +338,7 @@ func resourceAppEngineApplicationUpdate(d *schema.ResourceData, meta interface{} } // Wait for the operation to complete - waitErr := appEngineOperationWaitTime(d, config, op, pid, "App Engine app to update", userAgent, d.Timeout(schema.TimeoutUpdate)) + waitErr := appEngineOperationWaitTime(config, op, pid, "App Engine app to update", userAgent, d.Timeout(schema.TimeoutUpdate)) if waitErr != nil { return waitErr } diff --git a/mmv1/third_party/terraform/resources/resource_compute_attached_disk.go b/mmv1/third_party/terraform/resources/resource_compute_attached_disk.go index 51a949c21b8f..f1f50e5e1a5c 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_attached_disk.go +++ b/mmv1/third_party/terraform/resources/resource_compute_attached_disk.go @@ -113,7 +113,7 @@ func resourceAttachedDiskCreate(d *schema.ResourceData, meta interface{}) error d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s/%s", zv.Project, zv.Zone, zv.Name, diskName)) - waitErr := computeOperationWaitTime(d, config, op, zv.Project, + waitErr := computeOperationWaitTime(config, op, zv.Project, "disk to attach", userAgent, d.Timeout(schema.TimeoutCreate)) if waitErr != nil { d.SetId("") @@ -214,7 +214,7 @@ func resourceAttachedDiskDelete(d *schema.ResourceData, meta interface{}) error return err } - waitErr := computeOperationWaitTime(d, config, op, zv.Project, + waitErr := computeOperationWaitTime(config, op, zv.Project, fmt.Sprintf("Detaching disk from %s", zv.Name), userAgent, d.Timeout(schema.TimeoutDelete)) if waitErr != nil { return waitErr diff --git a/mmv1/third_party/terraform/resources/resource_compute_instance.go b/mmv1/third_party/terraform/resources/resource_compute_instance.go index c0e73548c542..39a2ce19f002 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_instance.go +++ b/mmv1/third_party/terraform/resources/resource_compute_instance.go @@ -972,7 +972,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, z, instance.Name)) // Wait for the operation to complete - waitErr := computeOperationWaitTime(d, config, op, project, "instance to create", userAgent, d.Timeout(schema.TimeoutCreate)) + waitErr := computeOperationWaitTime(config, op, project, "instance to create", userAgent, d.Timeout(schema.TimeoutCreate)) if waitErr != nil { // The resource didn't actually create d.SetId("") @@ -1296,7 +1296,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error updating metadata: %s", err) } - opErr := computeOperationWaitTime(d, config, op, project, "metadata to update", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "metadata to update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1322,7 +1322,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error updating tags: %s", err) } - opErr := computeOperationWaitTime(d, config, op, project, "tags to update", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "tags to update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1338,7 +1338,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error updating labels: %s", err) } - opErr := computeOperationWaitTime(d, config, op, project, "labels to update", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "labels to update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1359,7 +1359,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err } opErr := computeOperationWaitTime( - d, config, op, project, "scheduling policy update", userAgent, + config, op, project, "scheduling policy update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr @@ -1456,7 +1456,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return errwrap.Wrapf("Error removing alias_ip_range: {{err}}", err) } - opErr := computeOperationWaitTime(d, config, op, project, "updating alias ip ranges", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "updating alias ip ranges", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1477,7 +1477,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return errwrap.Wrapf("Error updating network interface: {{err}}", err) } - opErr := computeOperationWaitTime(d, config, op, project, "network interface to update", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "network interface to update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1578,7 +1578,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return errwrap.Wrapf("Error detaching disk: %s", err) } - opErr := computeOperationWaitTime(d, config, op, project, "detaching disk", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "detaching disk", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1593,7 +1593,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return errwrap.Wrapf("Error attaching disk : {{err}}", err) } - opErr := computeOperationWaitTime(d, config, op, project, "attaching disk", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "attaching disk", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1625,7 +1625,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error updating deletion protection flag: %s", err) } - opErr := computeOperationWaitTime(d, config, op, project, "deletion protection to update", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "deletion protection to update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1651,7 +1651,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err } } opErr := computeOperationWaitTime( - d, config, op, project, "updating status", userAgent, + config, op, project, "updating status", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr @@ -1677,7 +1677,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return errwrap.Wrapf("Error stopping instance: {{err}}", err) } - opErr := computeOperationWaitTime(d, config, op, project, "stopping instance", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "stopping instance", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1695,7 +1695,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return err } - opErr := computeOperationWaitTime(d, config, op, project, "updating machinetype", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "updating machinetype", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1716,7 +1716,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return err } - opErr := computeOperationWaitTime(d, config, op, project, "updating min cpu platform", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "updating min cpu platform", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1734,7 +1734,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return err } - opErr := computeOperationWaitTime(d, config, op, project, "updating service account", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "updating service account", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1749,7 +1749,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { return fmt.Errorf("Error updating display device: %s", err) } - opErr := computeOperationWaitTime(d, config, op, project, "updating display device", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "updating display device", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -1763,7 +1763,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error updating shielded vm config: %s", err) } - opErr := computeOperationWaitTime(d, config, op, project, + opErr := computeOperationWaitTime(config, op, project, "shielded vm config update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr @@ -1783,7 +1783,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err } opErr := computeOperationWaitTime( - d, config, op, project, "scheduling policy update", userAgent, + config, op, project, "scheduling policy update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr @@ -1812,7 +1812,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err return errwrap.Wrapf("Error starting instance: {{err}}", err) } - opErr := computeOperationWaitTime(d, config, op, project, + opErr := computeOperationWaitTime(config, op, project, "starting instance", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr @@ -2045,7 +2045,7 @@ func resourceComputeInstanceDelete(d *schema.ResourceData, meta interface{}) err } // Wait for the operation to complete - opErr := computeOperationWaitTime(d, config, op, project, "instance to delete", userAgent, d.Timeout(schema.TimeoutDelete)) + opErr := computeOperationWaitTime(config, op, project, "instance to delete", userAgent, d.Timeout(schema.TimeoutDelete)) if opErr != nil { // Refresh operation to check status op, _ = config.NewComputeClient(userAgent).ZoneOperations.Get(project, zone, strconv.FormatUint(op.Id, 10)).Do() diff --git a/mmv1/third_party/terraform/resources/resource_compute_instance_from_machine_image.go.erb b/mmv1/third_party/terraform/resources/resource_compute_instance_from_machine_image.go.erb index 9a5b6bb588b9..7b7c94c0a904 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_instance_from_machine_image.go.erb +++ b/mmv1/third_party/terraform/resources/resource_compute_instance_from_machine_image.go.erb @@ -171,7 +171,7 @@ func resourceComputeInstanceFromMachineImageCreate(d *schema.ResourceData, meta d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, z, instance.Name)) // Wait for the operation to complete - waitErr := computeOperationWaitTime(d, config, op, project, + waitErr := computeOperationWaitTime(config, op, project, "instance to create",userAgent, d.Timeout(schema.TimeoutCreate)) if waitErr != nil { // The resource didn't actually create diff --git a/mmv1/third_party/terraform/resources/resource_compute_instance_from_template.go b/mmv1/third_party/terraform/resources/resource_compute_instance_from_template.go index 2d552db54f80..547cc59d87dc 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_instance_from_template.go +++ b/mmv1/third_party/terraform/resources/resource_compute_instance_from_template.go @@ -167,7 +167,7 @@ func resourceComputeInstanceFromTemplateCreate(d *schema.ResourceData, meta inte d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, z, instance.Name)) // Wait for the operation to complete - waitErr := computeOperationWaitTime(d, config, op, project, + waitErr := computeOperationWaitTime(config, op, project, "instance to create", userAgent, d.Timeout(schema.TimeoutCreate)) if waitErr != nil { // The resource didn't actually create diff --git a/mmv1/third_party/terraform/resources/resource_compute_instance_group.go b/mmv1/third_party/terraform/resources/resource_compute_instance_group.go index 04f90e6b05cc..65250b6ea565 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_instance_group.go +++ b/mmv1/third_party/terraform/resources/resource_compute_instance_group.go @@ -182,7 +182,7 @@ func resourceComputeInstanceGroupCreate(d *schema.ResourceData, meta interface{} d.SetId(fmt.Sprintf("projects/%s/zones/%s/instanceGroups/%s", project, zone, name)) // Wait for the operation to complete - err = computeOperationWaitTime(d, config, op, project, "Creating InstanceGroup", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, project, "Creating InstanceGroup", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { d.SetId("") return err @@ -216,7 +216,7 @@ func resourceComputeInstanceGroupCreate(d *schema.ResourceData, meta interface{} } // Wait for the operation to complete - err = computeOperationWaitTime(d, config, op, project, "Adding instances to InstanceGroup", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, project, "Adding instances to InstanceGroup", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -354,7 +354,7 @@ func resourceComputeInstanceGroupUpdate(d *schema.ResourceData, meta interface{} } } else { // Wait for the operation to complete - err = computeOperationWaitTime(d, config, removeOp, project, "Updating InstanceGroup", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, removeOp, project, "Updating InstanceGroup", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -375,7 +375,7 @@ func resourceComputeInstanceGroupUpdate(d *schema.ResourceData, meta interface{} } // Wait for the operation to complete - err = computeOperationWaitTime(d, config, addOp, project, "Updating InstanceGroup", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, addOp, project, "Updating InstanceGroup", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -396,7 +396,7 @@ func resourceComputeInstanceGroupUpdate(d *schema.ResourceData, meta interface{} return fmt.Errorf("Error updating named ports for InstanceGroup: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Updating InstanceGroup", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, "Updating InstanceGroup", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -429,7 +429,7 @@ func resourceComputeInstanceGroupDelete(d *schema.ResourceData, meta interface{} return fmt.Errorf("Error deleting InstanceGroup: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Deleting InstanceGroup", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(config, op, project, "Deleting InstanceGroup", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_compute_instance_group_manager.go.erb b/mmv1/third_party/terraform/resources/resource_compute_instance_group_manager.go.erb index 7be3aa607dbc..155c5428b6d3 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_instance_group_manager.go.erb +++ b/mmv1/third_party/terraform/resources/resource_compute_instance_group_manager.go.erb @@ -443,7 +443,7 @@ func resourceComputeInstanceGroupManagerCreate(d *schema.ResourceData, meta inte d.SetId(id) // Wait for the operation to complete - err = computeOperationWaitTime(d, config, op, project, "Creating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, project, "Creating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { // Check if the create operation failed because Terraform was prematurely terminated. If it was we can persist the // operation id to state so that a subsequent refresh of this resource will wait until the operation has terminated @@ -557,7 +557,7 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf if err := d.Set("operation", op.Name); err != nil { return fmt.Errorf("Error setting operation: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Creating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, project, "Creating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { // remove from state to allow refresh to finish log.Printf("[DEBUG] Resumed operation returned an error, removing from state: %s", err) @@ -705,7 +705,7 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte return fmt.Errorf("Error updating managed group instances: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Updating managed group instances", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, "Updating managed group instances", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -731,7 +731,7 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte } // Wait for the operation to complete: - err = computeOperationWaitTime(d, config, op, project, "Updating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, "Updating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -750,7 +750,7 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte } // Wait for the operation to complete - err = computeOperationWaitTime(d, config, op, project, "Updating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, "Updating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -791,7 +791,7 @@ func resourceComputeInstanceGroupManagerDelete(d *schema.ResourceData, meta inte currentSize := int64(d.Get("target_size").(int)) // Wait for the operation to complete - err = computeOperationWaitTime(d, config, op, project, "Deleting InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(config, op, project, "Deleting InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutDelete)) for err != nil && currentSize > 0 { if !strings.Contains(err.Error(), "timeout") { @@ -812,7 +812,7 @@ func resourceComputeInstanceGroupManagerDelete(d *schema.ResourceData, meta inte log.Printf("[INFO] timeout occurred, but instance group is shrinking (%d < %d)", instanceGroupSize, currentSize) currentSize = instanceGroupSize - err = computeOperationWaitTime(d, config, op, project, "Deleting InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(config, op, project, "Deleting InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutDelete)) } d.SetId("") diff --git a/mmv1/third_party/terraform/resources/resource_compute_instance_template.go.erb b/mmv1/third_party/terraform/resources/resource_compute_instance_template.go.erb index 16d8a848bec1..7d92e73b9ffc 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_instance_template.go.erb +++ b/mmv1/third_party/terraform/resources/resource_compute_instance_template.go.erb @@ -915,7 +915,7 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac // Store the ID now d.SetId(fmt.Sprintf("projects/%s/global/instanceTemplates/%s", project, instanceTemplate.Name)) - err = computeOperationWaitTime(d, config, op, project, "Creating Instance Template", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, project, "Creating Instance Template", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -1303,7 +1303,7 @@ func resourceComputeInstanceTemplateDelete(d *schema.ResourceData, meta interfac return fmt.Errorf("Error deleting instance template: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Deleting Instance Template", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(config, op, project, "Deleting Instance Template", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_compute_network_peering.go b/mmv1/third_party/terraform/resources/resource_compute_network_peering.go index 5dd9faf69538..52e50c27f043 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_network_peering.go +++ b/mmv1/third_party/terraform/resources/resource_compute_network_peering.go @@ -132,7 +132,7 @@ func resourceComputeNetworkPeeringCreate(d *schema.ResourceData, meta interface{ return fmt.Errorf("Error adding network peering: %s", err) } - err = computeOperationWaitTime(d, config, addOp, networkFieldValue.Project, "Adding Network Peering", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, addOp, networkFieldValue.Project, "Adding Network Peering", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -227,7 +227,7 @@ func resourceComputeNetworkPeeringUpdate(d *schema.ResourceData, meta interface{ return fmt.Errorf("Error updating network peering: %s", err) } - err = computeOperationWaitTime(d, config, updateOp, networkFieldValue.Project, "Updating Network Peering", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, updateOp, networkFieldValue.Project, "Updating Network Peering", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -273,7 +273,7 @@ func resourceComputeNetworkPeeringDelete(d *schema.ResourceData, meta interface{ return fmt.Errorf("Error removing peering `%s` from network `%s`: %s", name, networkFieldValue.Name, err) } } else { - err = computeOperationWaitTime(d, config, removeOp, networkFieldValue.Project, "Removing Network Peering", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(config, removeOp, networkFieldValue.Project, "Removing Network Peering", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_compute_project_default_network_tier.go b/mmv1/third_party/terraform/resources/resource_compute_project_default_network_tier.go index b7479e51706a..2aed56fdcee8 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_project_default_network_tier.go +++ b/mmv1/third_party/terraform/resources/resource_compute_project_default_network_tier.go @@ -68,7 +68,7 @@ func resourceComputeProjectDefaultNetworkTierCreateOrUpdate(d *schema.ResourceDa } log.Printf("[DEBUG] SetDefaultNetworkTier: %d (%s)", op.Id, op.SelfLink) - err = computeOperationWaitTime(d, config, op, projectID, "SetDefaultNetworkTier", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, projectID, "SetDefaultNetworkTier", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return fmt.Errorf("SetDefaultNetworkTier failed: %s", err) } diff --git a/mmv1/third_party/terraform/resources/resource_compute_project_metadata.go b/mmv1/third_party/terraform/resources/resource_compute_project_metadata.go index 8ab984c00a9a..be4158ab8b92 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_project_metadata.go +++ b/mmv1/third_party/terraform/resources/resource_compute_project_metadata.go @@ -62,7 +62,7 @@ func resourceComputeProjectMetadataCreateOrUpdate(d *schema.ResourceData, meta i Items: expandComputeMetadata(d.Get("metadata").(map[string]interface{})), } - err = resourceComputeProjectMetadataSet(projectID, userAgent, d, config, md, d.Timeout(schema.TimeoutCreate)) + err = resourceComputeProjectMetadataSet(projectID, userAgent, config, md, d.Timeout(schema.TimeoutCreate)) if err != nil { return fmt.Errorf("SetCommonInstanceMetadata failed: %s", err) } @@ -120,7 +120,7 @@ func resourceComputeProjectMetadataDelete(d *schema.ResourceData, meta interface } md := &compute.Metadata{} - err = resourceComputeProjectMetadataSet(projectID, userAgent, d, config, md, d.Timeout(schema.TimeoutDelete)) + err = resourceComputeProjectMetadataSet(projectID, userAgent, config, md, d.Timeout(schema.TimeoutDelete)) if err != nil { return fmt.Errorf("SetCommonInstanceMetadata failed: %s", err) } @@ -128,7 +128,7 @@ func resourceComputeProjectMetadataDelete(d *schema.ResourceData, meta interface return resourceComputeProjectMetadataRead(d, meta) } -func resourceComputeProjectMetadataSet(projectID, userAgent string, d *schema.ResourceData, config *Config, md *compute.Metadata, timeout time.Duration) error { +func resourceComputeProjectMetadataSet(projectID, userAgent string, config *Config, md *compute.Metadata, timeout time.Duration) error { createMD := func() error { log.Printf("[DEBUG] Loading project service: %s", projectID) project, err := config.NewComputeClient(userAgent).Projects.Get(projectID).Do() @@ -143,7 +143,7 @@ func resourceComputeProjectMetadataSet(projectID, userAgent string, d *schema.Re } log.Printf("[DEBUG] SetCommonMetadata: %d (%s)", op.Id, op.SelfLink) - return computeOperationWaitTime(d, config, op, project.Name, "SetCommonMetadata", userAgent, timeout) + return computeOperationWaitTime(config, op, project.Name, "SetCommonMetadata", userAgent, timeout) } err := MetadataRetryWrapper(createMD) diff --git a/mmv1/third_party/terraform/resources/resource_compute_project_metadata_item.go b/mmv1/third_party/terraform/resources/resource_compute_project_metadata_item.go index 53c3bc200b6f..48bc92e01a80 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_project_metadata_item.go +++ b/mmv1/third_party/terraform/resources/resource_compute_project_metadata_item.go @@ -71,7 +71,7 @@ func resourceComputeProjectMetadataItemCreate(d *schema.ResourceData, meta inter key := d.Get("key").(string) val := d.Get("value").(string) - err = updateComputeCommonInstanceMetadata(d, config, projectID, key, userAgent, &val, d.Timeout(schema.TimeoutCreate), failIfPresent) + err = updateComputeCommonInstanceMetadata(config, projectID, key, userAgent, &val, d.Timeout(schema.TimeoutCreate), failIfPresent) if err != nil { return err } @@ -137,7 +137,7 @@ func resourceComputeProjectMetadataItemUpdate(d *schema.ResourceData, meta inter _, n := d.GetChange("value") new := n.(string) - err = updateComputeCommonInstanceMetadata(d, config, projectID, key, userAgent, &new, d.Timeout(schema.TimeoutUpdate), overwritePresent) + err = updateComputeCommonInstanceMetadata(config, projectID, key, userAgent, &new, d.Timeout(schema.TimeoutUpdate), overwritePresent) if err != nil { return err } @@ -159,7 +159,7 @@ func resourceComputeProjectMetadataItemDelete(d *schema.ResourceData, meta inter key := d.Get("key").(string) - err = updateComputeCommonInstanceMetadata(d, config, projectID, key, userAgent, nil, d.Timeout(schema.TimeoutDelete), overwritePresent) + err = updateComputeCommonInstanceMetadata(config, projectID, key, userAgent, nil, d.Timeout(schema.TimeoutDelete), overwritePresent) if err != nil { return err } @@ -168,7 +168,7 @@ func resourceComputeProjectMetadataItemDelete(d *schema.ResourceData, meta inter return nil } -func updateComputeCommonInstanceMetadata(d *schema.ResourceData, config *Config, projectID, key, userAgent string, afterVal *string, timeout time.Duration, failIfPresent metadataPresentBehavior) error { +func updateComputeCommonInstanceMetadata(config *Config, projectID, key, userAgent string, afterVal *string, timeout time.Duration, failIfPresent metadataPresentBehavior) error { updateMD := func() error { lockName := fmt.Sprintf("projects/%s/commoninstancemetadata", projectID) mutexKV.Lock(lockName) @@ -220,7 +220,7 @@ func updateComputeCommonInstanceMetadata(d *schema.ResourceData, config *Config, log.Printf("[DEBUG] SetCommonInstanceMetadata: %d (%s)", op.Id, op.SelfLink) - return computeOperationWaitTime(d, config, op, project.Name, "SetCommonInstanceMetadata", userAgent, timeout) + return computeOperationWaitTime(config, op, project.Name, "SetCommonInstanceMetadata", userAgent, timeout) } return MetadataRetryWrapper(updateMD) diff --git a/mmv1/third_party/terraform/resources/resource_compute_region_instance_group_manager.go.erb b/mmv1/third_party/terraform/resources/resource_compute_region_instance_group_manager.go.erb index db942ed54f19..6345bdfeae0d 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_region_instance_group_manager.go.erb +++ b/mmv1/third_party/terraform/resources/resource_compute_region_instance_group_manager.go.erb @@ -440,7 +440,7 @@ func resourceComputeRegionInstanceGroupManagerCreate(d *schema.ResourceData, met d.SetId(id) // Wait for the operation to complete - err = computeOperationWaitTime(d, config, op, project, "Creating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, project, "Creating InstanceGroupManager", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -655,7 +655,7 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met return fmt.Errorf("Error updating region managed group instances: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Updating region managed group instances", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, "Updating region managed group instances", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -677,7 +677,7 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met return fmt.Errorf("Error updating RegionInstanceGroupManager: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Updating RegionInstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, "Updating RegionInstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -694,7 +694,7 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met return fmt.Errorf("Error resizing RegionInstanceGroupManager: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Resizing RegionInstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, "Resizing RegionInstanceGroupManager", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -731,7 +731,7 @@ func resourceComputeRegionInstanceGroupManagerDelete(d *schema.ResourceData, met } // Wait for the operation to complete - err = computeOperationWaitTime(d, config, op, project, "Deleting RegionInstanceGroupManager", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(config, op, project, "Deleting RegionInstanceGroupManager", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return fmt.Errorf("Error waiting for delete to complete: %s", err) } diff --git a/mmv1/third_party/terraform/resources/resource_compute_router_interface.go b/mmv1/third_party/terraform/resources/resource_compute_router_interface.go index b88783e85585..f3b7b3dd84e0 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_router_interface.go +++ b/mmv1/third_party/terraform/resources/resource_compute_router_interface.go @@ -163,7 +163,7 @@ func resourceComputeRouterInterfaceCreate(d *schema.ResourceData, meta interface return fmt.Errorf("Error patching router %s/%s: %s", region, routerName, err) } d.SetId(fmt.Sprintf("%s/%s/%s", region, routerName, ifaceName)) - err = computeOperationWaitTime(d, config, op, project, "Patching router", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, project, "Patching router", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { d.SetId("") return fmt.Errorf("Error waiting to patch router %s/%s: %s", region, routerName, err) @@ -304,7 +304,7 @@ func resourceComputeRouterInterfaceDelete(d *schema.ResourceData, meta interface return fmt.Errorf("Error patching router %s/%s: %s", region, routerName, err) } - err = computeOperationWaitTime(d, config, op, project, "Patching router", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(config, op, project, "Patching router", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return fmt.Errorf("Error waiting to patch router %s/%s: %s", region, routerName, err) } diff --git a/mmv1/third_party/terraform/resources/resource_compute_security_policy.go.erb b/mmv1/third_party/terraform/resources/resource_compute_security_policy.go.erb index a00175ea6ca4..bfd1151e139e 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_security_policy.go.erb +++ b/mmv1/third_party/terraform/resources/resource_compute_security_policy.go.erb @@ -222,7 +222,7 @@ func resourceComputeSecurityPolicyCreate(d *schema.ResourceData, meta interface{ } d.SetId(id) - err = computeOperationWaitTime(d, config, op, project, fmt.Sprintf("Creating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, project, fmt.Sprintf("Creating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -296,7 +296,7 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{ return errwrap.Wrapf(fmt.Sprintf("Error updating SecurityPolicy %q: {{err}}", sp), err) } - err = computeOperationWaitTime(d, config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -324,7 +324,7 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{ return errwrap.Wrapf(fmt.Sprintf("Error updating SecurityPolicy %q: {{err}}", sp), err) } - err = computeOperationWaitTime(d, config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -336,7 +336,7 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{ return errwrap.Wrapf(fmt.Sprintf("Error updating SecurityPolicy %q: {{err}}", sp), err) } - err = computeOperationWaitTime(d, config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -353,7 +353,7 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{ return errwrap.Wrapf(fmt.Sprintf("Error updating SecurityPolicy %q: {{err}}", sp), err) } - err = computeOperationWaitTime(d, config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, fmt.Sprintf("Updating SecurityPolicy %q", sp), userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -382,7 +382,7 @@ func resourceComputeSecurityPolicyDelete(d *schema.ResourceData, meta interface{ return errwrap.Wrapf("Error deleting SecurityPolicy: {{err}}", err) } - err = computeOperationWaitTime(d, config, op, project, "Deleting SecurityPolicy", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(config, op, project, "Deleting SecurityPolicy", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_host_project.go b/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_host_project.go index 8fb86d0584e4..2c82fc1e3a3e 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_host_project.go +++ b/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_host_project.go @@ -49,7 +49,7 @@ func resourceComputeSharedVpcHostProjectCreate(d *schema.ResourceData, meta inte d.SetId(hostProject) - err = computeOperationWaitTime(d, config, op, hostProject, "Enabling Shared VPC Host", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, hostProject, "Enabling Shared VPC Host", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { d.SetId("") return err @@ -98,7 +98,7 @@ func resourceComputeSharedVpcHostProjectDelete(d *schema.ResourceData, meta inte return fmt.Errorf("Error disabling Shared VPC Host %q: %s", hostProject, err) } - err = computeOperationWaitTime(d, config, op, hostProject, "Disabling Shared VPC Host", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(config, op, hostProject, "Disabling Shared VPC Host", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_service_project.go b/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_service_project.go index 2034f01fd3c4..082d240842ba 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_service_project.go +++ b/mmv1/third_party/terraform/resources/resource_compute_shared_vpc_service_project.go @@ -65,7 +65,7 @@ func resourceComputeSharedVpcServiceProjectCreate(d *schema.ResourceData, meta i if err != nil { return err } - err = computeOperationWaitTime(d, config, op, hostProject, "Enabling Shared VPC Resource", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, hostProject, "Enabling Shared VPC Resource", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -144,7 +144,7 @@ func disableXpnResource(d *schema.ResourceData, config *Config, hostProject, pro if err != nil { return err } - err = computeOperationWaitTime(d, config, op, hostProject, "Disabling Shared VPC Resource", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(config, op, hostProject, "Disabling Shared VPC Resource", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_compute_target_pool.go b/mmv1/third_party/terraform/resources/resource_compute_target_pool.go index d202336d58dd..a54dca0fb7fb 100644 --- a/mmv1/third_party/terraform/resources/resource_compute_target_pool.go +++ b/mmv1/third_party/terraform/resources/resource_compute_target_pool.go @@ -235,7 +235,7 @@ func resourceComputeTargetPoolCreate(d *schema.ResourceData, meta interface{}) e } d.SetId(id) - err = computeOperationWaitTime(d, config, op, project, "Creating Target Pool", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, project, "Creating Target Pool", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -288,7 +288,7 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error updating health_check: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -304,7 +304,7 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error updating health_check: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -337,7 +337,7 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error updating instances: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -352,7 +352,7 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e if err != nil { return fmt.Errorf("Error updating instances: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -369,7 +369,7 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error updating backup_pool: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = computeOperationWaitTime(config, op, project, "Updating Target Pool", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -476,7 +476,7 @@ func resourceComputeTargetPoolDelete(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error deleting TargetPool: %s", err) } - err = computeOperationWaitTime(d, config, op, project, "Deleting Target Pool", userAgent, d.Timeout(schema.TimeoutDelete)) + err = computeOperationWaitTime(config, op, project, "Deleting Target Pool", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_google_folder.go b/mmv1/third_party/terraform/resources/resource_google_folder.go index ce3842768d70..edc049ef8b24 100644 --- a/mmv1/third_party/terraform/resources/resource_google_folder.go +++ b/mmv1/third_party/terraform/resources/resource_google_folder.go @@ -95,7 +95,7 @@ func resourceGoogleFolderCreate(d *schema.ResourceData, meta interface{}) error return err } - err = resourceManagerOperationWaitTime(d, config, opAsMap, "creating folder", userAgent, d.Timeout(schema.TimeoutCreate)) + err = resourceManagerOperationWaitTime(config, opAsMap, "creating folder", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return fmt.Errorf("Error creating folder '%s' in '%s': %s", displayName, parent, err) } @@ -195,7 +195,7 @@ func resourceGoogleFolderUpdate(d *schema.ResourceData, meta interface{}) error return err } - err = resourceManagerOperationWaitTime(d, config, opAsMap, "move folder", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = resourceManagerOperationWaitTime(config, opAsMap, "move folder", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return fmt.Errorf("Error moving folder '%s' to '%s': %s", displayName, newParent, err) } diff --git a/mmv1/third_party/terraform/resources/resource_google_project.go b/mmv1/third_party/terraform/resources/resource_google_project.go index cf15d3ac500e..38aa6477b7f8 100644 --- a/mmv1/third_party/terraform/resources/resource_google_project.go +++ b/mmv1/third_party/terraform/resources/resource_google_project.go @@ -149,7 +149,7 @@ func resourceGoogleProjectCreate(d *schema.ResourceData, meta interface{}) error return err } - waitErr := resourceManagerOperationWaitTime(d, config, opAsMap, "creating folder", userAgent, d.Timeout(schema.TimeoutCreate)) + waitErr := resourceManagerOperationWaitTime(config, opAsMap, "creating folder", userAgent, d.Timeout(schema.TimeoutCreate)) if waitErr != nil { // The resource wasn't actually created d.SetId("") @@ -179,7 +179,7 @@ func resourceGoogleProjectCreate(d *schema.ResourceData, meta interface{}) error // a network and deleting it in the background. if !d.Get("auto_create_network").(bool) { // The compute API has to be enabled before we can delete a network. - if err = enableServiceUsageProjectServices([]string{"compute.googleapis.com"}, project.ProjectId, userAgent, d, config, d.Timeout(schema.TimeoutCreate)); err != nil { + if err = enableServiceUsageProjectServices([]string{"compute.googleapis.com"}, project.ProjectId, userAgent, config, d.Timeout(schema.TimeoutCreate)); err != nil { return errwrap.Wrapf("Error enabling the Compute Engine API required to delete the default network: {{err}} ", err) } @@ -498,7 +498,7 @@ func forceDeleteComputeNetwork(d *schema.ResourceData, config *Config, projectId if err != nil { return errwrap.Wrapf("Error deleting firewall: {{err}}", err) } - err = computeOperationWaitTime(d, config, op, projectId, "Deleting Firewall", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, projectId, "Deleting Firewall", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err } @@ -508,7 +508,7 @@ func forceDeleteComputeNetwork(d *schema.ResourceData, config *Config, projectId paginate = token != "" } - return deleteComputeNetwork(projectId, networkName, userAgent, d, config) + return deleteComputeNetwork(projectId, networkName, userAgent, config) } func updateProjectBillingAccount(d *schema.ResourceData, config *Config, userAgent string) error { @@ -553,14 +553,14 @@ func updateProjectBillingAccount(d *schema.ResourceData, config *Config, userAge name, strings.TrimPrefix(ba.BillingAccountName, "billingAccounts/")) } -func deleteComputeNetwork(project, network, userAgent string, d *schema.ResourceData, config *Config) error { +func deleteComputeNetwork(project, network, userAgent string, config *Config) error { op, err := config.NewComputeClient(userAgent).Networks.Delete( project, network).Do() if err != nil { return errwrap.Wrapf("Error deleting network: {{err}}", err) } - err = computeOperationWaitTime(d, config, op, project, "Deleting Network", userAgent, 10*time.Minute) + err = computeOperationWaitTime(config, op, project, "Deleting Network", userAgent, 10*time.Minute) if err != nil { return err } @@ -580,7 +580,7 @@ func readGoogleProject(d *schema.ResourceData, config *Config, userAgent string) } // Enables services. WARNING: Use BatchRequestEnableServices for better batching if possible. -func enableServiceUsageProjectServices(services []string, project, userAgent string, d *schema.ResourceData, config *Config, timeout time.Duration) error { +func enableServiceUsageProjectServices(services []string, project, userAgent string, config *Config, timeout time.Duration) error { // ServiceUsage does not allow more than 20 services to be enabled per // batchEnable API call. See // https://cloud.google.com/service-usage/docs/reference/rest/v1/services/batchEnable @@ -595,7 +595,7 @@ func enableServiceUsageProjectServices(services []string, project, userAgent str return nil } - if err := doEnableServicesRequest(nextBatch, project, userAgent, d, config, timeout); err != nil { + if err := doEnableServicesRequest(nextBatch, project, userAgent, config, timeout); err != nil { return err } log.Printf("[DEBUG] Finished enabling next batch of %d project services: %+v", len(nextBatch), nextBatch) @@ -605,7 +605,7 @@ func enableServiceUsageProjectServices(services []string, project, userAgent str return waitForServiceUsageEnabledServices(services, project, userAgent, config, timeout) } -func doEnableServicesRequest(services []string, project, userAgent string, d *schema.ResourceData, config *Config, timeout time.Duration) error { +func doEnableServicesRequest(services []string, project, userAgent string, config *Config, timeout time.Duration) error { var op *serviceusage.Operation err := retryTimeDuration(func() error { @@ -628,7 +628,7 @@ func doEnableServicesRequest(services []string, project, userAgent string, d *sc return errwrap.Wrapf("failed to send enable services request: {{err}}", err) } // Poll for the API to return - waitErr := serviceUsageOperationWait(d, config, op, project, fmt.Sprintf("Enable Project %q Services: %+v", project, services), userAgent, timeout) + waitErr := serviceUsageOperationWait(config, op, project, fmt.Sprintf("Enable Project %q Services: %+v", project, services), userAgent, timeout) if waitErr != nil { return waitErr } diff --git a/mmv1/third_party/terraform/resources/resource_google_project_service.go b/mmv1/third_party/terraform/resources/resource_google_project_service.go index e8d6b64e7998..e89a6f4c1fd5 100644 --- a/mmv1/third_party/terraform/resources/resource_google_project_service.go +++ b/mmv1/third_party/terraform/resources/resource_google_project_service.go @@ -282,7 +282,7 @@ func disableServiceUsageProjectService(service, project string, d *schema.Resour return err } // Wait for the operation to complete - waitErr := serviceUsageOperationWait(d, config, sop, project, "api to disable", userAgent, d.Timeout(schema.TimeoutDelete)) + waitErr := serviceUsageOperationWait(config, sop, project, "api to disable", userAgent, d.Timeout(schema.TimeoutDelete)) if waitErr != nil { return waitErr } diff --git a/mmv1/third_party/terraform/resources/resource_project_service_identity.go.erb b/mmv1/third_party/terraform/resources/resource_project_service_identity.go.erb index e98b99bcba28..14bcec0f4624 100644 --- a/mmv1/third_party/terraform/resources/resource_project_service_identity.go.erb +++ b/mmv1/third_party/terraform/resources/resource_project_service_identity.go.erb @@ -74,7 +74,7 @@ func resourceProjectServiceIdentityCreate(d *schema.ResourceData, meta interface var opRes map[string]interface{} err = serviceUsageOperationWaitTimeWithResponse( - d, config, res, &opRes, project, "Creating Service Identity", userAgent, + config, res, &opRes, project, "Creating Service Identity", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err diff --git a/mmv1/third_party/terraform/resources/resource_service_networking_connection.go b/mmv1/third_party/terraform/resources/resource_service_networking_connection.go index c6e78a3d33a3..122050e44f7e 100644 --- a/mmv1/third_party/terraform/resources/resource_service_networking_connection.go +++ b/mmv1/third_party/terraform/resources/resource_service_networking_connection.go @@ -103,7 +103,7 @@ func resourceServiceNetworkingConnectionCreate(d *schema.ResourceData, meta inte return err } - if err := serviceNetworkingOperationWaitTime(d, config, op, "Create Service Networking Connection", userAgent, d.Timeout(schema.TimeoutCreate)); err != nil { + if err := serviceNetworkingOperationWaitTime(config, op, "Create Service Networking Connection", userAgent, d.Timeout(schema.TimeoutCreate)); err != nil { return err } @@ -201,7 +201,7 @@ func resourceServiceNetworkingConnectionUpdate(d *schema.ResourceData, meta inte if err != nil { return err } - if err := serviceNetworkingOperationWaitTime(d, config, op, "Update Service Networking Connection", userAgent, d.Timeout(schema.TimeoutUpdate)); err != nil { + if err := serviceNetworkingOperationWaitTime(config, op, "Update Service Networking Connection", userAgent, d.Timeout(schema.TimeoutUpdate)); err != nil { return err } } @@ -244,7 +244,7 @@ func resourceServiceNetworkingConnectionDelete(d *schema.ResourceData, meta inte } err = computeOperationWaitTime( - d, config, op, project, "Updating Network", userAgent, d.Timeout(schema.TimeoutDelete)) + config, op, project, "Updating Network", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_sql_database_instance.go.erb b/mmv1/third_party/terraform/resources/resource_sql_database_instance.go.erb index 29fa5d2af516..12e8299572cf 100644 --- a/mmv1/third_party/terraform/resources/resource_sql_database_instance.go.erb +++ b/mmv1/third_party/terraform/resources/resource_sql_database_instance.go.erb @@ -878,7 +878,7 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{}) } d.SetId(id) - err = sqlAdminOperationWaitTime(d, config, op, project, "Create Instance", userAgent, d.Timeout(schema.TimeoutCreate)) + err = sqlAdminOperationWaitTime(config, op, project, "Create Instance", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { d.SetId("") return err @@ -907,7 +907,7 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error, failed to update instance settings for %s: %s", instance.Name, err) } - err = sqlAdminOperationWaitTime(d, config, op, project, "Update Instance", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = sqlAdminOperationWaitTime(config, op, project, "Update Instance", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -935,7 +935,7 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{}) err = retry(func() error { op, err = config.NewSqlAdminClient(userAgent).Users.Delete(project, instance.Name).Host(u.Host).Name(u.Name).Do() if err == nil { - err = sqlAdminOperationWaitTime(d, config, op, project, "Delete default root User", userAgent, d.Timeout(schema.TimeoutCreate)) + err = sqlAdminOperationWaitTime(config, op, project, "Delete default root User", userAgent, d.Timeout(schema.TimeoutCreate)) } return err }) @@ -1286,7 +1286,7 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error, failed to update instance settings for %s: %s", instance.Name, err) } - err = sqlAdminOperationWaitTime(d, config, op, project, "Update Instance", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = sqlAdminOperationWaitTime(config, op, project, "Update Instance", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } @@ -1335,7 +1335,7 @@ func resourceSqlDatabaseInstanceDelete(d *schema.ResourceData, meta interface{}) if rerr != nil { return rerr } - err = sqlAdminOperationWaitTime(d, config, op, project, "Delete Instance", userAgent, d.Timeout(schema.TimeoutDelete)) + err = sqlAdminOperationWaitTime(config, op, project, "Delete Instance", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err } @@ -1655,7 +1655,7 @@ func sqlDatabaseInstanceRestoreFromBackup(d *schema.ResourceData, config *Config return fmt.Errorf("Error, failed to restore instance from backup %s: %s", instanceId, err) } - err = sqlAdminOperationWaitTime(d, config, op, project, "Restore Backup", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = sqlAdminOperationWaitTime(config, op, project, "Restore Backup", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } diff --git a/mmv1/third_party/terraform/resources/resource_sql_ssl_cert.go b/mmv1/third_party/terraform/resources/resource_sql_ssl_cert.go index b8ba19548490..5ecc39256711 100644 --- a/mmv1/third_party/terraform/resources/resource_sql_ssl_cert.go +++ b/mmv1/third_party/terraform/resources/resource_sql_ssl_cert.go @@ -119,7 +119,7 @@ func resourceSqlSslCertCreate(d *schema.ResourceData, meta interface{}) error { "ssl cert %s into instance %s: %s", commonName, instance, err) } - err = sqlAdminOperationWaitTime(d, config, resp.Operation, project, "Create Ssl Cert", userAgent, d.Timeout(schema.TimeoutCreate)) + err = sqlAdminOperationWaitTime(config, resp.Operation, project, "Create Ssl Cert", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return fmt.Errorf("Error, failure waiting for creation of %q "+ "in %q: %s", commonName, instance, err) @@ -225,7 +225,7 @@ func resourceSqlSslCertDelete(d *schema.ResourceData, meta interface{}) error { instance, err) } - err = sqlAdminOperationWaitTime(d, config, op, project, "Delete Ssl Cert", userAgent, d.Timeout(schema.TimeoutDelete)) + err = sqlAdminOperationWaitTime(config, op, project, "Delete Ssl Cert", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return fmt.Errorf("Error, failure waiting for deletion of ssl cert %q "+ diff --git a/mmv1/third_party/terraform/resources/resource_sql_user.go b/mmv1/third_party/terraform/resources/resource_sql_user.go index 7d3d171563a9..043aa9e22329 100644 --- a/mmv1/third_party/terraform/resources/resource_sql_user.go +++ b/mmv1/third_party/terraform/resources/resource_sql_user.go @@ -135,7 +135,7 @@ func resourceSqlUserCreate(d *schema.ResourceData, meta interface{}) error { // for which user.Host is an empty string. That's okay. d.SetId(fmt.Sprintf("%s/%s/%s", user.Name, user.Host, user.Instance)) - err = sqlAdminOperationWaitTime(d, config, op, project, "Insert User", userAgent, d.Timeout(schema.TimeoutCreate)) + err = sqlAdminOperationWaitTime(config, op, project, "Insert User", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return fmt.Errorf("Error, failure waiting for insertion of %s "+ @@ -247,7 +247,7 @@ func resourceSqlUserUpdate(d *schema.ResourceData, meta interface{}) error { "user %s into user %s: %s", name, instance, err) } - err = sqlAdminOperationWaitTime(d, config, op, project, "Insert User", userAgent, d.Timeout(schema.TimeoutUpdate)) + err = sqlAdminOperationWaitTime(config, op, project, "Insert User", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return fmt.Errorf("Error, failure waiting for update of %s "+ @@ -293,7 +293,7 @@ func resourceSqlUserDelete(d *schema.ResourceData, meta interface{}) error { return err } - if err := sqlAdminOperationWaitTime(d, config, op, project, "Delete User", userAgent, d.Timeout(schema.TimeoutDelete)); err != nil { + if err := sqlAdminOperationWaitTime(config, op, project, "Delete User", userAgent, d.Timeout(schema.TimeoutDelete)); err != nil { return err } return nil diff --git a/mmv1/third_party/terraform/resources/resource_usage_export_bucket.go b/mmv1/third_party/terraform/resources/resource_usage_export_bucket.go index ac725f147418..d0066ed7e28d 100644 --- a/mmv1/third_party/terraform/resources/resource_usage_export_bucket.go +++ b/mmv1/third_party/terraform/resources/resource_usage_export_bucket.go @@ -103,7 +103,7 @@ func resourceProjectUsageBucketCreate(d *schema.ResourceData, meta interface{}) return err } d.SetId(project) - err = computeOperationWaitTime(d, config, op, project, "Setting usage export bucket.", userAgent, d.Timeout(schema.TimeoutCreate)) + err = computeOperationWaitTime(config, op, project, "Setting usage export bucket.", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { d.SetId("") return err @@ -133,7 +133,7 @@ func resourceProjectUsageBucketDelete(d *schema.ResourceData, meta interface{}) return err } - err = computeOperationWaitTime(d, config, op, project, + err = computeOperationWaitTime(config, op, project, "Setting usage export bucket to nil, automatically disabling usage export.", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { return err diff --git a/mmv1/third_party/terraform/tests/resource_composer_environment_test.go.erb b/mmv1/third_party/terraform/tests/resource_composer_environment_test.go.erb index 51e9b5ed45de..2335472668ab 100644 --- a/mmv1/third_party/terraform/tests/resource_composer_environment_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_composer_environment_test.go.erb @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "google.golang.org/api/composer/v1beta1" "google.golang.org/api/storage/v1" @@ -1191,7 +1190,7 @@ func testAccCheckClearComposerEnvironmentFirewalls(t *testing.T, networkName str continue } - waitErr := computeOperationWaitTime(&schema.ResourceData{}, config, op, config.Project, + waitErr := computeOperationWaitTime(config, op, config.Project, "Sweeping test composer environment firewalls", config.userAgent, 10) if waitErr != nil { allErrors = multierror.Append(allErrors, diff --git a/mmv1/third_party/terraform/tests/resource_compute_instance_migrate_test.go b/mmv1/third_party/terraform/tests/resource_compute_instance_migrate_test.go index d7f0ee139dff..af7a807ca356 100644 --- a/mmv1/third_party/terraform/tests/resource_compute_instance_migrate_test.go +++ b/mmv1/third_party/terraform/tests/resource_compute_instance_migrate_test.go @@ -11,7 +11,6 @@ import ( "google.golang.org/api/compute/v1" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) @@ -108,8 +107,7 @@ func TestAccComputeInstanceMigrateState(t *testing.T) { if err != nil { t.Fatalf("Error creating instance: %s", err) } - d := &schema.ResourceData{} - waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -182,8 +180,7 @@ func TestAccComputeInstanceMigrateState_bootDisk(t *testing.T) { if err != nil { t.Fatalf("Error creating instance: %s", err) } - d := &schema.ResourceData{} - waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -251,8 +248,7 @@ func TestAccComputeInstanceMigrateState_v4FixBootDisk(t *testing.T) { if err != nil { t.Fatalf("Error creating instance: %s", err) } - d := &schema.ResourceData{} - waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -305,8 +301,7 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromSource(t *testing.T) { if err != nil { t.Fatalf("Error creating disk: %s", err) } - d := &schema.ResourceData{} - waitErr := computeOperationWaitTime(d, config, op, config.Project, "disk to create", config.userAgent, 4*time.Minute) + waitErr := computeOperationWaitTime(config, op, config.Project, "disk to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -338,7 +333,7 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromSource(t *testing.T) { if err != nil { t.Fatalf("Error creating instance: %s", err) } - waitErr = computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + waitErr = computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -387,8 +382,7 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromSource(t *testing.T if err != nil { t.Fatalf("Error creating disk: %s", err) } - d := &schema.ResourceData{} - waitErr := computeOperationWaitTime(d, config, op, config.Project, "disk to create", config.userAgent, 4*time.Minute) + waitErr := computeOperationWaitTime(config, op, config.Project, "disk to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -420,7 +414,7 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromSource(t *testing.T if err != nil { t.Fatalf("Error creating instance: %s", err) } - waitErr = computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + waitErr = computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -489,8 +483,7 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromEncryptionKey(t *testing if err != nil { t.Fatalf("Error creating instance: %s", err) } - d := &schema.ResourceData{} - waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -559,8 +552,7 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromEncryptionKey(t *te if err != nil { t.Fatalf("Error creating instance: %s", err) } - d := &schema.ResourceData{} - waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -631,8 +623,7 @@ func TestAccComputeInstanceMigrateState_attachedDiskFromAutoDeleteAndImage(t *te if err != nil { t.Fatalf("Error creating instance: %s", err) } - d := &schema.ResourceData{} - waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -705,8 +696,7 @@ func TestAccComputeInstanceMigrateState_v4FixAttachedDiskFromAutoDeleteAndImage( if err != nil { t.Fatalf("Error creating instance: %s", err) } - d := &schema.ResourceData{} - waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -775,8 +765,7 @@ func TestAccComputeInstanceMigrateState_scratchDisk(t *testing.T) { if err != nil { t.Fatalf("Error creating instance: %s", err) } - d := &schema.ResourceData{} - waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -841,8 +830,7 @@ func TestAccComputeInstanceMigrateState_v4FixScratchDisk(t *testing.T) { if err != nil { t.Fatalf("Error creating instance: %s", err) } - d := &schema.ResourceData{} - waitErr := computeOperationWaitTime(d, config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) + waitErr := computeOperationWaitTime(config, op, config.Project, "instance to create", config.userAgent, 4*time.Minute) if waitErr != nil { t.Fatal(waitErr) } @@ -921,8 +909,7 @@ func cleanUpInstance(config *Config, instanceName, zone string) { } // Wait for the operation to complete - d := &schema.ResourceData{} - opErr := computeOperationWaitTime(d, config, op, config.Project, "instance to delete", config.userAgent, 4*time.Minute) + opErr := computeOperationWaitTime(config, op, config.Project, "instance to delete", config.userAgent, 4*time.Minute) if opErr != nil { log.Printf("[WARNING] Error deleting instance %q, dangling resources may exist: %s", instanceName, opErr) } @@ -936,8 +923,7 @@ func cleanUpDisk(config *Config, diskName, zone string) { } // Wait for the operation to complete - d := &schema.ResourceData{} - opErr := computeOperationWaitTime(d, config, op, config.Project, "disk to delete", config.userAgent, 4*time.Minute) + opErr := computeOperationWaitTime(config, op, config.Project, "disk to delete", config.userAgent, 4*time.Minute) if opErr != nil { log.Printf("[WARNING] Error deleting disk %q, dangling resources may exist: %s", diskName, opErr) } diff --git a/mmv1/third_party/terraform/tests/resource_compute_instance_test.go b/mmv1/third_party/terraform/tests/resource_compute_instance_test.go index a0b0bda80a38..4fef38157016 100644 --- a/mmv1/third_party/terraform/tests/resource_compute_instance_test.go +++ b/mmv1/third_party/terraform/tests/resource_compute_instance_test.go @@ -12,7 +12,6 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" computeBeta "google.golang.org/api/compute/v0.beta" "google.golang.org/api/compute/v1" @@ -2166,8 +2165,7 @@ func testAccCheckComputeInstanceUpdateMachineType(t *testing.T, n string) resour if err != nil { return fmt.Errorf("Could not stop instance: %s", err) } - d := &schema.ResourceData{} - err = computeOperationWaitTime(d, config, op, config.Project, "Waiting on stop", config.userAgent, 20*time.Minute) + err = computeOperationWaitTime(config, op, config.Project, "Waiting on stop", config.userAgent, 20*time.Minute) if err != nil { return fmt.Errorf("Could not stop instance: %s", err) } @@ -2181,7 +2179,7 @@ func testAccCheckComputeInstanceUpdateMachineType(t *testing.T, n string) resour if err != nil { return fmt.Errorf("Could not change machine type: %s", err) } - err = computeOperationWaitTime(d, config, op, config.Project, "Waiting machine type change", config.userAgent, 20*time.Minute) + err = computeOperationWaitTime(config, op, config.Project, "Waiting machine type change", config.userAgent, 20*time.Minute) if err != nil { return fmt.Errorf("Could not change machine type: %s", err) } diff --git a/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go.erb b/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go.erb index ce756f02c4e7..08ad48a2f9a7 100644 --- a/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go.erb @@ -9,7 +9,6 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" sqladmin "google.golang.org/api/sqladmin/v1beta4" ) @@ -106,7 +105,7 @@ func testSweepDatabases(region string) error { return nil } - err = sqlAdminOperationWaitTime(&schema.ResourceData{}, config, op, config.Project, "Stop Replica", config.userAgent, 10 * time.Minute) + err = sqlAdminOperationWaitTime(config, op, config.Project, "Stop Replica", config.userAgent, 10 * time.Minute) if err != nil { if strings.Contains(err.Error(), "does not exist") { log.Printf("Replication operation not found") @@ -138,7 +137,7 @@ func testSweepDatabases(region string) error { return nil } - err = sqlAdminOperationWaitTime(&schema.ResourceData{}, config, op, config.Project, "Delete Instance", config.userAgent, 10 * time.Minute) + err = sqlAdminOperationWaitTime(config, op, config.Project, "Delete Instance", config.userAgent, 10 * time.Minute) if err != nil { if strings.Contains(err.Error(), "does not exist") { log.Printf("SQL instance not found") @@ -263,7 +262,7 @@ func TestAccSqlDatabaseInstance_dontDeleteDefaultUserOnReplica(t *testing.T) { t.Errorf("Error while inserting root@%% user: %s", err) return } - err = sqlAdminOperationWaitTime(&schema.ResourceData{}, config, op, config.Project, "Waiting for user to insert", config.userAgent, 10 * time.Minute) + err = sqlAdminOperationWaitTime(config, op, config.Project, "Waiting for user to insert", config.userAgent, 10 * time.Minute) if err != nil { t.Errorf("Error while waiting for user insert operation to complete: %s", err.Error()) } diff --git a/mmv1/third_party/terraform/utils/appengine_operation.go b/mmv1/third_party/terraform/utils/appengine_operation.go index 2dd916269de2..d6401b71d81d 100644 --- a/mmv1/third_party/terraform/utils/appengine_operation.go +++ b/mmv1/third_party/terraform/utils/appengine_operation.go @@ -6,7 +6,6 @@ import ( "regexp" "time" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "google.golang.org/api/appengine/v1" ) @@ -18,7 +17,6 @@ type AppEngineOperationWaiter struct { Service *appengine.APIService AppId string CommonOperationWaiter - d *schema.ResourceData } func (w *AppEngineOperationWaiter) QueryOp() (interface{}, error) { @@ -32,7 +30,7 @@ func (w *AppEngineOperationWaiter) QueryOp() (interface{}, error) { return w.Service.Apps.Operations.Get(w.AppId, matches[1]).Do() } -func appEngineOperationWaitTimeWithResponse(d *schema.ResourceData, config *Config, res interface{}, response *map[string]interface{}, appId, activity, userAgent string, timeout time.Duration) error { +func appEngineOperationWaitTimeWithResponse(config *Config, res interface{}, response *map[string]interface{}, appId, activity, userAgent string, timeout time.Duration) error { op := &appengine.Operation{} err := Convert(res, op) if err != nil { @@ -42,7 +40,6 @@ func appEngineOperationWaitTimeWithResponse(d *schema.ResourceData, config *Conf w := &AppEngineOperationWaiter{ Service: config.NewAppEngineClient(userAgent), AppId: appId, - d: d, } if err := w.SetOp(op); err != nil { @@ -54,7 +51,7 @@ func appEngineOperationWaitTimeWithResponse(d *schema.ResourceData, config *Conf return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response) } -func appEngineOperationWaitTime(d *schema.ResourceData, config *Config, res interface{}, appId, activity, userAgent string, timeout time.Duration) error { +func appEngineOperationWaitTime(config *Config, res interface{}, appId, activity, userAgent string, timeout time.Duration) error { op := &appengine.Operation{} err := Convert(res, op) if err != nil { @@ -64,7 +61,6 @@ func appEngineOperationWaitTime(d *schema.ResourceData, config *Config, res inte w := &AppEngineOperationWaiter{ Service: config.NewAppEngineClient(userAgent), AppId: appId, - d: d, } if err := w.SetOp(op); err != nil { diff --git a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go index b67413710a95..64b12dcff22d 100644 --- a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go +++ b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go @@ -9,7 +9,6 @@ import ( "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "google.golang.org/api/cloudkms/v1" cloudresourcemanager "google.golang.org/api/cloudresourcemanager/v1" "google.golang.org/api/iam/v1" @@ -247,7 +246,7 @@ func BootstrapSharedTestNetwork(t *testing.T, testId string) string { } log.Printf("[DEBUG] Waiting for network creation to finish") - err = computeOperationWaitTime(&schema.ResourceData{}, config, res, project, "Error bootstrapping shared test network", config.userAgent, 4*time.Minute) + err = computeOperationWaitTime(config, res, project, "Error bootstrapping shared test network", config.userAgent, 4*time.Minute) if err != nil { t.Fatalf("Error bootstrapping shared test network %q: %s", networkName, err) } @@ -303,7 +302,7 @@ func BootstrapServicePerimeterProjects(t *testing.T, desiredProjects int) []*clo t.Fatalf("Error bootstrapping shared test project: %s", err) } - err = resourceManagerOperationWaitTime(&schema.ResourceData{}, config, opAsMap, "creating project", config.userAgent, 4) + err = resourceManagerOperationWaitTime(config, opAsMap, "creating project", config.userAgent, 4) if err != nil { t.Fatalf("Error bootstrapping shared test project: %s", err) } @@ -396,7 +395,7 @@ func BootstrapSharedSQLInstanceBackupRun(t *testing.T) string { if err != nil { t.Fatalf("Error, failed to create instance %s: %s", bootstrapInstance.Name, err) } - err = sqlAdminOperationWaitTime(&schema.ResourceData{}, config, op, project, "Create Instance", config.userAgent, time.Duration(20)*time.Minute) + err = sqlAdminOperationWaitTime(config, op, project, "Create Instance", config.userAgent, time.Duration(20)*time.Minute) if err != nil { t.Fatalf("Error, failed to create instance %s: %s", bootstrapInstance.Name, err) } @@ -422,7 +421,7 @@ func BootstrapSharedSQLInstanceBackupRun(t *testing.T) string { if err != nil { t.Fatalf("Error, failed to create instance backup: %s", err) } - err = sqlAdminOperationWaitTime(&schema.ResourceData{}, config, op, project, "Backup Instance", config.userAgent, time.Duration(20)*time.Minute) + err = sqlAdminOperationWaitTime(config, op, project, "Backup Instance", config.userAgent, time.Duration(20)*time.Minute) if err != nil { t.Fatalf("Error, failed to create instance backup: %s", err) } diff --git a/mmv1/third_party/terraform/utils/compute_instance_network_interface_helpers.go b/mmv1/third_party/terraform/utils/compute_instance_network_interface_helpers.go index b7747c81c2ad..b8c72d4669a5 100644 --- a/mmv1/third_party/terraform/utils/compute_instance_network_interface_helpers.go +++ b/mmv1/third_party/terraform/utils/compute_instance_network_interface_helpers.go @@ -16,7 +16,7 @@ func computeInstanceDeleteAccessConfigs(d *schema.ResourceData, config *Config, if err != nil { return fmt.Errorf("Error deleting old access_config: %s", err) } - opErr := computeOperationWaitTime(d, config, op, project, "old access_config to delete", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "old access_config to delete", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -31,7 +31,7 @@ func computeInstanceAddAccessConfigs(d *schema.ResourceData, config *Config, ins if err != nil { return fmt.Errorf("Error adding new access_config: %s", err) } - opErr := computeOperationWaitTime(d, config, op, project, "new access_config to add", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "new access_config to add", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } @@ -65,7 +65,7 @@ func computeInstanceCreateUpdateWhileStoppedCall(d *schema.ResourceData, config if err != nil { return errwrap.Wrapf("Error updating network interface: {{err}}", err) } - opErr := computeOperationWaitTime(d, config, op, project, "network interface to update", userAgent, d.Timeout(schema.TimeoutUpdate)) + opErr := computeOperationWaitTime(config, op, project, "network interface to update", userAgent, d.Timeout(schema.TimeoutUpdate)) if opErr != nil { return opErr } diff --git a/mmv1/third_party/terraform/utils/compute_operation.go.erb b/mmv1/third_party/terraform/utils/compute_operation.go.erb index 7da1e2afdb30..ddb422386a59 100644 --- a/mmv1/third_party/terraform/utils/compute_operation.go.erb +++ b/mmv1/third_party/terraform/utils/compute_operation.go.erb @@ -26,7 +26,6 @@ type ComputeOperationWaiter struct { <% unless version == 'ga' -%> Parent string <% end -%> - d *schema.ResourceData } func (w *ComputeOperationWaiter) State() string { @@ -111,7 +110,7 @@ func (w *ComputeOperationWaiter) TargetStates() []string { return []string{"DONE"} } -func computeOperationWaitTime(d *schema.ResourceData, config *Config, res interface{}, project, activity, userAgent string, timeout time.Duration) error { +func computeOperationWaitTime(config *Config, res interface{}, project, activity, userAgent string, timeout time.Duration) error { <% if version == 'ga' -%> op := &compute.Operation{} <% else -%> @@ -131,7 +130,6 @@ func computeOperationWaitTime(d *schema.ResourceData, config *Config, res interf Context: config.context, Op: op, Project: project, - d: d, } if err := w.SetOp(op); err != nil { @@ -141,7 +139,7 @@ func computeOperationWaitTime(d *schema.ResourceData, config *Config, res interf } <% unless version == 'ga' -%> -func computeOrgOperationWaitTimeWithResponse(d *schema.ResourceData, config *Config, res interface{}, response *map[string]interface{}, parent, activity, userAgent string, timeout time.Duration) error { +func computeOrgOperationWaitTimeWithResponse(config *Config, res interface{}, response *map[string]interface{}, parent, activity, userAgent string, timeout time.Duration) error { op := &computeBeta.Operation{} err := Convert(res, op) if err != nil { @@ -152,7 +150,6 @@ func computeOrgOperationWaitTimeWithResponse(d *schema.ResourceData, config *Con Service: config.NewComputeBetaClient(userAgent), Op: op, Parent: parent, - d: d, } if err := w.SetOp(op); err != nil { diff --git a/mmv1/third_party/terraform/utils/deployment_manager_operation.go.erb b/mmv1/third_party/terraform/utils/deployment_manager_operation.go.erb index 1ad7cf07fabd..e1b0d6a360bb 100644 --- a/mmv1/third_party/terraform/utils/deployment_manager_operation.go.erb +++ b/mmv1/third_party/terraform/utils/deployment_manager_operation.go.erb @@ -16,7 +16,6 @@ type DeploymentManagerOperationWaiter struct { Project string OperationUrl string ComputeOperationWaiter - d *schema.ResourceData } func (w *DeploymentManagerOperationWaiter) IsRetryable(error) bool { @@ -44,7 +43,7 @@ func (w *DeploymentManagerOperationWaiter) QueryOp() (interface{}, error) { } -func deploymentManagerOperationWaitTime(d *schema.ResourceData, config *Config, resp interface{}, project, activity, userAgent string, timeout time.Duration) error { +func deploymentManagerOperationWaitTime(config *Config, resp interface{}, project, activity, userAgent string, timeout time.Duration) error { <% if version == 'ga' -%> op := &compute.Operation{} <% else -%> @@ -62,7 +61,6 @@ func deploymentManagerOperationWaitTime(d *schema.ResourceData, config *Config, ComputeOperationWaiter: ComputeOperationWaiter{ Project: project, }, - d: d, } if err := w.SetOp(op); err != nil { return err diff --git a/mmv1/third_party/terraform/utils/self_link_helpers.go b/mmv1/third_party/terraform/utils/self_link_helpers.go index fdc054abbf09..7115bbd7863d 100644 --- a/mmv1/third_party/terraform/utils/self_link_helpers.go +++ b/mmv1/third_party/terraform/utils/self_link_helpers.go @@ -169,3 +169,15 @@ func GetRegionFromRegionSelfLink(selfLink string) string { } return selfLink } + +// This function supports selflinks that have regions and locations in their paths +func GetRegionFromRegionalSelfLink(selfLink string) string { + re := regexp.MustCompile("projects/[a-zA-Z0-9-]*/[locations/regions]+/([a-zA-Z0-9-]*)") + switch { + case re.MatchString(selfLink): + if res := re.FindStringSubmatch(selfLink); len(res) == 2 && res[1] != "" { + return res[1] + } + } + return selfLink +} diff --git a/mmv1/third_party/terraform/utils/service_networking_operation.go b/mmv1/third_party/terraform/utils/service_networking_operation.go index 9e858de1f733..fa7695b36764 100644 --- a/mmv1/third_party/terraform/utils/service_networking_operation.go +++ b/mmv1/third_party/terraform/utils/service_networking_operation.go @@ -3,24 +3,21 @@ package google import ( "time" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "google.golang.org/api/servicenetworking/v1" ) type ServiceNetworkingOperationWaiter struct { Service *servicenetworking.APIService CommonOperationWaiter - d *schema.ResourceData } func (w *ServiceNetworkingOperationWaiter) QueryOp() (interface{}, error) { return w.Service.Operations.Get(w.Op.Name).Do() } -func serviceNetworkingOperationWaitTime(d *schema.ResourceData, config *Config, op *servicenetworking.Operation, activity, userAgent string, timeout time.Duration) error { +func serviceNetworkingOperationWaitTime(config *Config, op *servicenetworking.Operation, activity, userAgent string, timeout time.Duration) error { w := &ServiceNetworkingOperationWaiter{ Service: config.NewServiceNetworkingClient(userAgent), - d: d, } if err := w.SetOp(op); err != nil { diff --git a/mmv1/third_party/terraform/utils/serviceusage_batching.go b/mmv1/third_party/terraform/utils/serviceusage_batching.go index 7c7b36644622..9504e82153a9 100644 --- a/mmv1/third_party/terraform/utils/serviceusage_batching.go +++ b/mmv1/third_party/terraform/utils/serviceusage_batching.go @@ -31,7 +31,7 @@ func BatchRequestEnableService(service string, project string, d *schema.Resourc ResourceName: project, Body: []string{service}, CombineF: combineServiceUsageServicesBatches, - SendF: sendBatchFuncEnableServices(d, config, userAgent, d.Timeout(schema.TimeoutCreate)), + SendF: sendBatchFuncEnableServices(config, userAgent, d.Timeout(schema.TimeoutCreate)), DebugId: fmt.Sprintf("Enable Project Service %q for project %q", service, project), } @@ -52,10 +52,10 @@ func tryEnableRenamedService(service, altName string, project string, d *schema. // use a short timeout- failures are likely log.Printf("[DEBUG] attempting enabling service with user-specified name %s", service) - err = enableServiceUsageProjectServices([]string{service}, project, userAgent, d, config, 1*time.Minute) + err = enableServiceUsageProjectServices([]string{service}, project, userAgent, config, 1*time.Minute) if err != nil { log.Printf("[DEBUG] saw error %s. attempting alternate name %v", err, altName) - err2 := enableServiceUsageProjectServices([]string{altName}, project, userAgent, d, config, 1*time.Minute) + err2 := enableServiceUsageProjectServices([]string{altName}, project, userAgent, config, 1*time.Minute) if err2 != nil { return fmt.Errorf("Saw 2 subsequent errors attempting to enable a renamed service: %s / %s", err, err2) } @@ -97,13 +97,13 @@ func combineServiceUsageServicesBatches(srvsRaw interface{}, toAddRaw interface{ return append(srvs, toAdd...), nil } -func sendBatchFuncEnableServices(d *schema.ResourceData, config *Config, userAgent string, timeout time.Duration) BatcherSendFunc { +func sendBatchFuncEnableServices(config *Config, userAgent string, timeout time.Duration) BatcherSendFunc { return func(project string, toEnableRaw interface{}) (interface{}, error) { toEnable, ok := toEnableRaw.([]string) if !ok { return nil, fmt.Errorf("Expected batch body type to be []string, got %v. This is a provider error.", toEnableRaw) } - return nil, enableServiceUsageProjectServices(toEnable, project, userAgent, d, config, timeout) + return nil, enableServiceUsageProjectServices(toEnable, project, userAgent, config, timeout) } } diff --git a/mmv1/third_party/terraform/utils/serviceusage_operation.go b/mmv1/third_party/terraform/utils/serviceusage_operation.go index 12571a6c600c..6ed1c4cbd31b 100644 --- a/mmv1/third_party/terraform/utils/serviceusage_operation.go +++ b/mmv1/third_party/terraform/utils/serviceusage_operation.go @@ -4,12 +4,11 @@ import ( "encoding/json" "time" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "google.golang.org/api/googleapi" "google.golang.org/api/serviceusage/v1" ) -func serviceUsageOperationWait(d *schema.ResourceData, config *Config, op *serviceusage.Operation, project, activity, userAgent string, timeout time.Duration) error { +func serviceUsageOperationWait(config *Config, op *serviceusage.Operation, project, activity, userAgent string, timeout time.Duration) error { // maintained for compatibility with old code that was written before the // autogenerated waiters. b, err := op.MarshalJSON() @@ -20,7 +19,7 @@ func serviceUsageOperationWait(d *schema.ResourceData, config *Config, op *servi if err := json.Unmarshal(b, &m); err != nil { return err } - return serviceUsageOperationWaitTime(d, config, m, project, activity, userAgent, timeout) + return serviceUsageOperationWaitTime(config, m, project, activity, userAgent, timeout) } func handleServiceUsageRetryableError(err error) error { diff --git a/mmv1/third_party/terraform/utils/sqladmin_operation.go b/mmv1/third_party/terraform/utils/sqladmin_operation.go index e53a2381468b..e5010e5dc0e2 100644 --- a/mmv1/third_party/terraform/utils/sqladmin_operation.go +++ b/mmv1/third_party/terraform/utils/sqladmin_operation.go @@ -6,7 +6,6 @@ import ( "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" sqladmin "google.golang.org/api/sqladmin/v1beta4" ) @@ -14,7 +13,6 @@ type SqlAdminOperationWaiter struct { Service *sqladmin.Service Op *sqladmin.Operation Project string - d *schema.ResourceData } func (w *SqlAdminOperationWaiter) State() string { @@ -102,7 +100,7 @@ func (w *SqlAdminOperationWaiter) TargetStates() []string { return []string{"DONE"} } -func sqlAdminOperationWaitTime(d *schema.ResourceData, config *Config, res interface{}, project, activity, userAgent string, timeout time.Duration) error { +func sqlAdminOperationWaitTime(config *Config, res interface{}, project, activity, userAgent string, timeout time.Duration) error { op := &sqladmin.Operation{} err := Convert(res, op) if err != nil { @@ -113,7 +111,6 @@ func sqlAdminOperationWaitTime(d *schema.ResourceData, config *Config, res inter Service: config.NewSqlAdminClient(userAgent), Op: op, Project: project, - d: d, } if err := w.SetOp(op); err != nil { return err diff --git a/mmv1/third_party/terraform/utils/vertex_ai_operation.go.erb b/mmv1/third_party/terraform/utils/vertex_ai_operation.go.erb new file mode 100644 index 000000000000..b6be4d89f731 --- /dev/null +++ b/mmv1/third_party/terraform/utils/vertex_ai_operation.go.erb @@ -0,0 +1,69 @@ +<% autogen_exception -%> +package google + +import ( + "encoding/json" + "fmt" + "time" +) + +type VertexAIOperationWaiter struct { + Config *Config + UserAgent string + Project string + CommonOperationWaiter +} + +func (w *VertexAIOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } + + region := GetRegionFromRegionalSelfLink(w.CommonOperationWaiter.Op.Name) + + // Returns the proper get. +<% if version == 'ga' -%> + url := fmt.Sprintf("https://%s-aiplatform.googleapis.com/v1/%s", region, w.CommonOperationWaiter.Op.Name) +<% else -%> + url := fmt.Sprintf("https://%s-aiplatform.googleapis.com/v1beta1/%s", region, w.CommonOperationWaiter.Op.Name) +<% end -%> + + return sendRequest(w.Config, "GET", w.Project, url, w.UserAgent, nil) +} + +func createVertexAIWaiter(config *Config, op map[string]interface{}, project, activity, userAgent string) (*VertexAIOperationWaiter, error) { + w := &VertexAIOperationWaiter{ + Config: config, + UserAgent: userAgent, + Project: project, + } + if err := w.CommonOperationWaiter.SetOp(op); err != nil { + return nil, err + } + return w, nil +} + +// nolint: deadcode,unused +func vertexAIOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error { + w, err := createVertexAIWaiter(config, op, project, activity, userAgent) + if err != nil { + return err + } + if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil { + return err + } + return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response) +} + +func vertexAIOperationWaitTime(config *Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error { + if val, ok := op["name"]; !ok || val == "" { + // This was a synchronous call - there is no operation to wait for. + return nil + } + w, err := createVertexAIWaiter(config, op, project, activity, userAgent) + if err != nil { + // If w is nil, the op was synchronous. + return err + } + return OperationWait(w, activity, timeout, config.PollInterval) +} From 3da30b0e688b55f214366888c205ca7bf548ffb6 Mon Sep 17 00:00:00 2001 From: upodroid Date: Fri, 18 Jun 2021 22:07:09 +0100 Subject: [PATCH 4/4] fix regex and add test --- .../terraform/utils/compute_shared_operation.go | 4 ++++ .../third_party/terraform/utils/self_link_helpers.go | 2 +- .../terraform/utils/self_link_helpers_test.go | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 mmv1/third_party/terraform/utils/compute_shared_operation.go diff --git a/mmv1/third_party/terraform/utils/compute_shared_operation.go b/mmv1/third_party/terraform/utils/compute_shared_operation.go new file mode 100644 index 000000000000..4710ed024a9f --- /dev/null +++ b/mmv1/third_party/terraform/utils/compute_shared_operation.go @@ -0,0 +1,4 @@ +package google + +// Empty file so that the build will run tests on terraform-conversion mapper. +// File should be removed once the PR has been merged. diff --git a/mmv1/third_party/terraform/utils/self_link_helpers.go b/mmv1/third_party/terraform/utils/self_link_helpers.go index 7115bbd7863d..16767600e565 100644 --- a/mmv1/third_party/terraform/utils/self_link_helpers.go +++ b/mmv1/third_party/terraform/utils/self_link_helpers.go @@ -172,7 +172,7 @@ func GetRegionFromRegionSelfLink(selfLink string) string { // This function supports selflinks that have regions and locations in their paths func GetRegionFromRegionalSelfLink(selfLink string) string { - re := regexp.MustCompile("projects/[a-zA-Z0-9-]*/[locations/regions]+/([a-zA-Z0-9-]*)") + re := regexp.MustCompile("projects/[a-zA-Z0-9-]*/(?:locations|regions)/([a-zA-Z0-9-]*)") switch { case re.MatchString(selfLink): if res := re.FindStringSubmatch(selfLink); len(res) == 2 && res[1] != "" { diff --git a/mmv1/third_party/terraform/utils/self_link_helpers_test.go b/mmv1/third_party/terraform/utils/self_link_helpers_test.go index a9b674344731..172b0adcc7dc 100644 --- a/mmv1/third_party/terraform/utils/self_link_helpers_test.go +++ b/mmv1/third_party/terraform/utils/self_link_helpers_test.go @@ -122,3 +122,15 @@ func TestGetRegionFromRegionSelfLink(t *testing.T) { } } } + +func TestGetRegionFromRegionalSelfLink(t *testing.T) { + cases := map[string]string{ + "projects/foo/locations/europe-north1/datasets/bar/operations/foobar": "europe-north1", + "projects/REDACTED/regions/europe-north1/subnetworks/tf-test-net-xbwhsmlfm8": "europe-north1", + } + for input, expected := range cases { + if result := GetRegionFromRegionalSelfLink(input); result != expected { + t.Errorf("expected to get %q from %q, got %q", expected, input, result) + } + } +}