From ff823ebb381f00b76c4e008e65a9b0499ea56a35 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Tue, 13 Feb 2024 16:00:25 -0800 Subject: [PATCH 01/22] setup resoruce config and add create tests --- .../products/cloudquotas/QuotaPreference.yaml | 162 ++++++++++++++++++ mmv1/products/cloudquotas/product.yaml | 22 +++ .../cloudquotas_quota_preference_basic.tf.erb | 10 ++ ...oudquotas_quota_preference_regional.tf.erb | 11 ++ 4 files changed, 205 insertions(+) create mode 100644 mmv1/products/cloudquotas/QuotaPreference.yaml create mode 100644 mmv1/products/cloudquotas/product.yaml create mode 100644 mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb create mode 100644 mmv1/templates/terraform/examples/cloudquotas_quota_preference_regional.tf.erb diff --git a/mmv1/products/cloudquotas/QuotaPreference.yaml b/mmv1/products/cloudquotas/QuotaPreference.yaml new file mode 100644 index 000000000000..7a1af27f05b9 --- /dev/null +++ b/mmv1/products/cloudquotas/QuotaPreference.yaml @@ -0,0 +1,162 @@ +# Copyright 2024 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::Resource +name: 'QuotaPreference' +description: | + QuotaPreference represents the preferred quota configuration specified for a project, folder or organization. There is only one QuotaPreference resource for a quota value targeting a unique set of dimensions. +references: !ruby/object:Api::Resource::ReferenceLinks + guides: + 'Cloud Quotas Overview': 'https://cloud.google.com/docs/quotas/overview' + api: 'https://cloud.google.com/docs/quotas/reference/rest/v1/projects.locations.quotaPreferences' +base_url: '{{parent}}/locations/global/quotaPreferences' +self_link: '{{parent}}/locations/global/quotaPreferences/{{quota_preference_id}}' +create_url: '{{parent}}/locations/global/quotaPreferences?quotaPreferenceId={{quota_preference_id}}&ignoreSafetyChecks={{ignore_safety_checks}}' +update_verb: :PATCH +update_mask: true +skip_delete: true +autogen_async: false +examples: + - !ruby/object:Provider::Terraform::Examples + name: "cloudquotas_quota_preference_basic" + primary_resource_id: "preference" + vars: + preference_name: "compute_CPUS-per-project" + service: "compute.googleapis.com" + quota_id: "CPUS-per-project-region" + contact_email: "liulola@google.com" + test_env_vars: + project: :PROJECT_NAME + +parameters: + - !ruby/object:Api::Type::String + name: 'parent' + required: true + immutable: true + url_param_only: true + description: The parent of the quota preference. + - !ruby/object:Api::Type::String + name: 'quota_preference_id' + required: true + immutable: true + url_param_only: true + description: The unique quota preference id. + - !ruby/object:Api::Type::Boolean + name: 'allow_missing' + url_param_only: true + description: | + If set to true, and the quota preference is not found, a new one will be created. In this situation, updateMask is ignored. + - !ruby/object:Api::Type::Boolean + name: 'validate_only' + url_param_only: true + description: | + If set to true, validate the request, but do not actually update. Note that a request being valid does not mean that the request is guaranteed to be fulfilled. + - !ruby/object:Api::Type::Enum + name: 'ignore_safety_checks' + url_param_only: true + description: The list of quota safety checks to be ignored. + values: + - :QUOTA_SAFETY_CHECK_UNSPECIFIED + - :QUOTA_DECREASE_BELOW_USAGE + - :QUOTA_DECREASE_PERCENTAGE_TOO_HIGH + +properties: + - !ruby/object:Api::Type::String + name: 'name' + description: | + The resource name of the quota preference. Required except in the CREATE requests. + - !ruby/object:Api::Type::String + name: 'service' + required: true + description: The name of the service to which the quota preference is applied. + - !ruby/object:Api::Type::String + name: 'quotaId' + required: true + description: | + The id of the quota to which the quota preference is applied. A quota id is unique in the service. + Example: CPUS-per-project-region. + - !ruby/object:Api::Type::NestedObject + name: 'quotaConfig' + required: true + description: The preferred quota configuration. + properties: + - !ruby/object:Api::Type::String + name: 'preferredValue' + required: true + description: | + The preferred value. Must be greater than or equal to -1. If set to -1, it means the value is "unlimited". + - !ruby/object:Api::Type::String + name: 'stateDetail' + output: true + description: Optional details about the state of this quota preference. + - !ruby/object:Api::Type::String + name: 'grantedValue' + output: true + description: Granted quota value. + - !ruby/object:Api::Type::String + name: 'traceId' + output: true + description: | + The trace id that the Google Cloud uses to provision the requested quota. This trace id may be used by the client to contact Cloud support to track the state of a quota preference request. The trace id is only produced for increase requests and is unique for each request. The quota decrease requests do not have a trace id. + - !ruby/object:Api::Type::KeyValuePairs + name: 'annotations' + description: |- + The annotations map for clients to store small amounts of arbitrary data. Do not put PII or other sensitive information here. See https://google.aip.dev/128#annotations. + + An object containing a list of "key: value" pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }. + - !ruby/object:Api::Type::Enum + name: 'requestOrigin' + output: true + description: The origin of the quota preference request. + values: + - :ORIGIN_UNSPECIFIED + - :CLOUD_CONSOLE` + - :AUTO_ADJUSTER + - !ruby/object:Api::Type::KeyValuePairs + name: 'dimensions' + description: |- + The dimensions that this quota preference applies to. The key of the map entry is the name of a dimension, such as "region", "zone", "network_id", and the value of the map entry is the dimension value. If a dimension is missing from the map of dimensions, the quota preference applies to all the dimension values except for those that have other quota preferences configured for the specific value. + + NOTE: QuotaPreferences can only be applied across all values of "user" and "resource" dimension. Do not set values for "user" or "resource" in the dimension map. + + Example: {"provider", "Foo Inc"} where "provider" is a service specific dimension. + - !ruby/object:Api::Type::String + name: 'etag' + description: | + The current etag of the quota preference. If an etag is provided on update and does not match the current server's etag of the quota preference, the request will be blocked and an ABORTED error will be returned. See https://google.aip.dev/134#etags for more details on etags. + - !ruby/object:Api::Type::String + name: 'createTime' + output: true + description: | + Create time stamp. + A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z". + - !ruby/object:Api::Type::String + name: 'updateTime' + output: true + description: | + Update time stamp. + A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z". + - !ruby/object:Api::Type::Boolean + name: 'reconciling' + output: true + description: | + Is the quota preference pending Google Cloud approval and fulfillment. + - !ruby/object:Api::Type::String + name: 'justification' + description: The reason / justification for this quota preference. + - !ruby/object:Api::Type::String + name: 'contactEmail' + description: |- + An email address that can be used for quota related communication between the Google Cloud and the user in case the Google Cloud needs further information to make a decision on whether the user preferred quota can be granted. + + The Google account for the email address must have quota update permission for the project, folder or organization this quota preference is for. \ No newline at end of file diff --git a/mmv1/products/cloudquotas/product.yaml b/mmv1/products/cloudquotas/product.yaml new file mode 100644 index 000000000000..8082932da0bc --- /dev/null +++ b/mmv1/products/cloudquotas/product.yaml @@ -0,0 +1,22 @@ +# Copyright 2024 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: CloudQuotas +display_name: Cloud Quotas +versions: + - !ruby/object:Api::Product::Version + name: ga + base_url: https://cloudquotas.googleapis.com/v1/ +scopes: + - https://www.googleapis.com/auth/cloud-platform \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb b/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb new file mode 100644 index 000000000000..dfc4c4d888cd --- /dev/null +++ b/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb @@ -0,0 +1,10 @@ +resource "google_cloudquotas_quota_preference" "<%= ctx[:primary_resource_id] %>" { + name = "projects/" + "<%= ctx[:test_env_vars]['project'] %>" + "/locations/global/" + "<%= ctx[:vars]['preference_name'] %>" + quota_config = google_cloudquotas_quota_config.config + service = "<%= ctx[:vars]['service'] %>" + quota_id = "<%= ctx[:vars]['quota_id'] %>" + contact_email = "<%= ctx[:vars]['contact_email'] %>" +} +resource "google_cloudquotas_quota_config" "config" { + preferred_value = "200" +} \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/cloudquotas_quota_preference_regional.tf.erb b/mmv1/templates/terraform/examples/cloudquotas_quota_preference_regional.tf.erb new file mode 100644 index 000000000000..58a59067e4d9 --- /dev/null +++ b/mmv1/templates/terraform/examples/cloudquotas_quota_preference_regional.tf.erb @@ -0,0 +1,11 @@ +resource "google_cloudquotas_quota_preference" "<%= ctx[:primary_resource_id] %>" { + name = "projects/" + "<%= ctx[:test_env_vars]['project'] %>" + "/locations/global/" + "<%= ctx[:vars]['preference_name'] %>" + dimensions = "<%= ctx[:vars]['dimensions'] %>" + quota_config = google_cloudquotas_quota_config.config + service = "<%= ctx[:vars]['service'] %>" + quota_id = "<%= ctx[:vars]['quota_id'] %>" + contact_email = "<%= ctx[:vars]['contact_email'] %>" +} +resource "google_cloudquotas_quota_config" "config" { + preferred_value = "200" +} \ No newline at end of file From 6f37c021ed16fa0b6697fdbf2f340d2b1d2bcbcf Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Tue, 20 Feb 2024 15:17:30 -0800 Subject: [PATCH 02/22] add create and update test --- .../products/cloudquotas/QuotaPreference.yaml | 16 ++-- .../encoders/quota_preference.go.erb | 40 +++++++++ .../cloudquotas_quota_preference_basic.tf.erb | 23 ++++-- ...oudquotas_quota_preference_regional.tf.erb | 11 --- ...urce_cloud_quotas_quota_preference_test.go | 82 +++++++++++++++++++ 5 files changed, 145 insertions(+), 27 deletions(-) create mode 100644 mmv1/templates/terraform/encoders/quota_preference.go.erb delete mode 100644 mmv1/templates/terraform/examples/cloudquotas_quota_preference_regional.tf.erb create mode 100644 mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go diff --git a/mmv1/products/cloudquotas/QuotaPreference.yaml b/mmv1/products/cloudquotas/QuotaPreference.yaml index 7a1af27f05b9..7868d2bb9bff 100644 --- a/mmv1/products/cloudquotas/QuotaPreference.yaml +++ b/mmv1/products/cloudquotas/QuotaPreference.yaml @@ -22,34 +22,35 @@ references: !ruby/object:Api::Resource::ReferenceLinks base_url: '{{parent}}/locations/global/quotaPreferences' self_link: '{{parent}}/locations/global/quotaPreferences/{{quota_preference_id}}' create_url: '{{parent}}/locations/global/quotaPreferences?quotaPreferenceId={{quota_preference_id}}&ignoreSafetyChecks={{ignore_safety_checks}}' +update_url: '{{parent}}/locations/global/quotaPreferences/{{quota_preference_id}}?allowMissing={{allow_missing}}&validateOnly={{validate_only}}&ignoreSafetyChecks={{ignore_safety_checks}}' update_verb: :PATCH update_mask: true skip_delete: true autogen_async: false +custom_code: !ruby/object:Provider::Terraform::CustomCode + encoder: templates/terraform/encoders/quota_preference.go.erb + examples: - !ruby/object:Provider::Terraform::Examples name: "cloudquotas_quota_preference_basic" primary_resource_id: "preference" + skip_test: true vars: - preference_name: "compute_CPUS-per-project" - service: "compute.googleapis.com" - quota_id: "CPUS-per-project-region" - contact_email: "liulola@google.com" + quota_preference_id: "compute_googleapis_com-CPUS-per-project_us-central2" test_env_vars: project: :PROJECT_NAME parameters: - !ruby/object:Api::Type::String name: 'parent' - required: true immutable: true url_param_only: true - description: The parent of the quota preference. + description: The parent of the quota preference. Allowed parents are "projects/[project-id / number]" or "folders/[folder-id / number]" or "organizations/[org-id / number]". - !ruby/object:Api::Type::String name: 'quota_preference_id' - required: true immutable: true url_param_only: true + default_value: "" description: The unique quota preference id. - !ruby/object:Api::Type::Boolean name: 'allow_missing' @@ -64,6 +65,7 @@ parameters: - !ruby/object:Api::Type::Enum name: 'ignore_safety_checks' url_param_only: true + default_value: :QUOTA_SAFETY_CHECK_UNSPECIFIED description: The list of quota safety checks to be ignored. values: - :QUOTA_SAFETY_CHECK_UNSPECIFIED diff --git a/mmv1/templates/terraform/encoders/quota_preference.go.erb b/mmv1/templates/terraform/encoders/quota_preference.go.erb new file mode 100644 index 000000000000..317717d6f6db --- /dev/null +++ b/mmv1/templates/terraform/encoders/quota_preference.go.erb @@ -0,0 +1,40 @@ +<%- # the license inside this block applies to this file + # Copyright 2023 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. +-%> + + +parent := d.Get("parent").(string) +preference_id := d.Get("quota_preference_id").(string) + +if d.Get("name") != nil { + preference_name := d.Get("name").(string) + + parent, err := tpgresource.ExtractFieldByPattern("parent", parent, preference_name, "((projects|folders|organizations)/([a-z0-9A-Z-]*))/.*") + if err != nil { + return nil, fmt.Errorf("error extracting parent field: %s", err) + } + d.Set("parent", parent) + + preference_id, err := tpgresource.ExtractFieldByPattern("quota_preference", preference_id, preference_name, ".*quotaPreferences/([a-zA-Z0-9-_]+)" ) + if err != nil { + return nil, fmt.Errorf("error extracting preference id field: %s", err) + } + d.Set("quota_preference_id", preference_id) +} else { + if parent != "" { + return nil, fmt.Errorf("'parent' field missing.") + } +} + +return obj, nil diff --git a/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb b/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb index dfc4c4d888cd..8e9abce96a48 100644 --- a/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb +++ b/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb @@ -1,10 +1,15 @@ -resource "google_cloudquotas_quota_preference" "<%= ctx[:primary_resource_id] %>" { - name = "projects/" + "<%= ctx[:test_env_vars]['project'] %>" + "/locations/global/" + "<%= ctx[:vars]['preference_name'] %>" - quota_config = google_cloudquotas_quota_config.config - service = "<%= ctx[:vars]['service'] %>" - quota_id = "<%= ctx[:vars]['quota_id'] %>" - contact_email = "<%= ctx[:vars]['contact_email'] %>" +# [START cloudquotas_quota_preference_basic] +resource "google_cloud_quotas_quota_preference" "<%= ctx[:primary_resource_id] %>" { + name = "projects/<%= ctx[:test_env_vars]['project'] %>/locations/global/quotaPreferences/<%= ctx[:vars]['quota_preference_id'] %>" + quota_config { + preferred_value = 210 + } + dimensions = { + region = "us-central2" + } + service = "compute.googleapis.com" + quota_id = "CPUS-per-project-region" + contact_email = "liulola@google.com" + justification = "Increase quota for terraform testing." } -resource "google_cloudquotas_quota_config" "config" { - preferred_value = "200" -} \ No newline at end of file +# [END cloudquotas_quota_preference_basic] diff --git a/mmv1/templates/terraform/examples/cloudquotas_quota_preference_regional.tf.erb b/mmv1/templates/terraform/examples/cloudquotas_quota_preference_regional.tf.erb deleted file mode 100644 index 58a59067e4d9..000000000000 --- a/mmv1/templates/terraform/examples/cloudquotas_quota_preference_regional.tf.erb +++ /dev/null @@ -1,11 +0,0 @@ -resource "google_cloudquotas_quota_preference" "<%= ctx[:primary_resource_id] %>" { - name = "projects/" + "<%= ctx[:test_env_vars]['project'] %>" + "/locations/global/" + "<%= ctx[:vars]['preference_name'] %>" - dimensions = "<%= ctx[:vars]['dimensions'] %>" - quota_config = google_cloudquotas_quota_config.config - service = "<%= ctx[:vars]['service'] %>" - quota_id = "<%= ctx[:vars]['quota_id'] %>" - contact_email = "<%= ctx[:vars]['contact_email'] %>" -} -resource "google_cloudquotas_quota_config" "config" { - preferred_value = "200" -} \ No newline at end of file diff --git a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go new file mode 100644 index 000000000000..618c37465735 --- /dev/null +++ b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go @@ -0,0 +1,82 @@ +package cloudquotas_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + "github.com/hashicorp/terraform-provider-google/google/acctest" + "github.com/hashicorp/terraform-provider-google/google/envvar" +) + +func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_update(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project": envvar.GetTestProjectFromEnv(), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_basic(context), + }, + { + ResourceName: "google_cloud_quotas_quota_preference.preference", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks"}, + }, + { + Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_update(context), + }, + { + ResourceName: "google_cloud_quotas_quota_preference.preference", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks"}, + }, + }, + }) +} + +func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_basic(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloud_quotas_quota_preference" "preference" { + name = "projects/%{project}/locations/global/quotaPreferences/tf-test-compute_googleapis_com-CPUS-per-project_us-central2%{random_suffix}" + quota_config { + preferred_value = 210 + } + dimensions = { + region = "us-central1" + } + service = "compute.googleapis.com" + quota_id = "CPUS-per-project-region" + contact_email = "liulola@google.com" + justification = "Increase quota for terraform testing." +} +`, context) +} + +func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_update(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloud_quotas_quota_preference" "preference" { + name = "projects/%{project}/locations/global/quotaPreferences/tf-test-compute_CPUS-per-project_compute_googleapis_com-CPUS-per-project_us-east1%{random_suffix}" + quota_config { + preferred_value = 200 + } + dimensions = { + region = "us-east1" + } + service = "compute.googleapis.com" + quota_id = "CPUS-per-project-region" + contact_email = "liulola@google.com" + justification = "Increase quota for terraform testing." + validate_only = true + allow_missing = true +} +`, context) +} From 17f5c74c5f01d2b90e6868bb0c16b259db281608 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Tue, 20 Feb 2024 15:49:29 -0800 Subject: [PATCH 03/22] fix lint error --- .../products/cloudquotas/QuotaPreference.yaml | 22 +++++++++---------- mmv1/products/cloudquotas/product.yaml | 2 +- .../encoders/quota_preference.go.erb | 3 +-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/mmv1/products/cloudquotas/QuotaPreference.yaml b/mmv1/products/cloudquotas/QuotaPreference.yaml index 7868d2bb9bff..3423334da219 100644 --- a/mmv1/products/cloudquotas/QuotaPreference.yaml +++ b/mmv1/products/cloudquotas/QuotaPreference.yaml @@ -67,7 +67,7 @@ parameters: url_param_only: true default_value: :QUOTA_SAFETY_CHECK_UNSPECIFIED description: The list of quota safety checks to be ignored. - values: + values: - :QUOTA_SAFETY_CHECK_UNSPECIFIED - :QUOTA_DECREASE_BELOW_USAGE - :QUOTA_DECREASE_PERCENTAGE_TOO_HIGH @@ -76,7 +76,7 @@ properties: - !ruby/object:Api::Type::String name: 'name' description: | - The resource name of the quota preference. Required except in the CREATE requests. + The resource name of the quota preference. Required except in the CREATE requests. - !ruby/object:Api::Type::String name: 'service' required: true @@ -96,7 +96,7 @@ properties: name: 'preferredValue' required: true description: | - The preferred value. Must be greater than or equal to -1. If set to -1, it means the value is "unlimited". + The preferred value. Must be greater than or equal to -1. If set to -1, it means the value is "unlimited". - !ruby/object:Api::Type::String name: 'stateDetail' output: true @@ -113,14 +113,14 @@ properties: - !ruby/object:Api::Type::KeyValuePairs name: 'annotations' description: |- - The annotations map for clients to store small amounts of arbitrary data. Do not put PII or other sensitive information here. See https://google.aip.dev/128#annotations. - + The annotations map for clients to store small amounts of arbitrary data. Do not put PII or other sensitive information here. See https://google.aip.dev/128#annotations. + An object containing a list of "key: value" pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }. - !ruby/object:Api::Type::Enum name: 'requestOrigin' output: true description: The origin of the quota preference request. - values: + values: - :ORIGIN_UNSPECIFIED - :CLOUD_CONSOLE` - :AUTO_ADJUSTER @@ -128,10 +128,10 @@ properties: name: 'dimensions' description: |- The dimensions that this quota preference applies to. The key of the map entry is the name of a dimension, such as "region", "zone", "network_id", and the value of the map entry is the dimension value. If a dimension is missing from the map of dimensions, the quota preference applies to all the dimension values except for those that have other quota preferences configured for the specific value. - - NOTE: QuotaPreferences can only be applied across all values of "user" and "resource" dimension. Do not set values for "user" or "resource" in the dimension map. - - Example: {"provider", "Foo Inc"} where "provider" is a service specific dimension. + + NOTE: QuotaPreferences can only be applied across all values of "user" and "resource" dimension. Do not set values for "user" or "resource" in the dimension map. + + Example: {"provider", "Foo Inc"} where "provider" is a service specific dimension. - !ruby/object:Api::Type::String name: 'etag' description: | @@ -146,7 +146,7 @@ properties: name: 'updateTime' output: true description: | - Update time stamp. + Update time stamp. A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z". - !ruby/object:Api::Type::Boolean name: 'reconciling' diff --git a/mmv1/products/cloudquotas/product.yaml b/mmv1/products/cloudquotas/product.yaml index 8082932da0bc..53c82344b0d2 100644 --- a/mmv1/products/cloudquotas/product.yaml +++ b/mmv1/products/cloudquotas/product.yaml @@ -19,4 +19,4 @@ versions: name: ga base_url: https://cloudquotas.googleapis.com/v1/ scopes: - - https://www.googleapis.com/auth/cloud-platform \ No newline at end of file + - https://www.googleapis.com/auth/cloud-platform diff --git a/mmv1/templates/terraform/encoders/quota_preference.go.erb b/mmv1/templates/terraform/encoders/quota_preference.go.erb index 317717d6f6db..9b96123f3cde 100644 --- a/mmv1/templates/terraform/encoders/quota_preference.go.erb +++ b/mmv1/templates/terraform/encoders/quota_preference.go.erb @@ -13,7 +13,6 @@ # limitations under the License. -%> - parent := d.Get("parent").(string) preference_id := d.Get("quota_preference_id").(string) @@ -37,4 +36,4 @@ if d.Get("name") != nil { } } -return obj, nil +return obj, nil \ No newline at end of file From 9a62c8991a66f3f8dee22f0dcdd03776ed87c711 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Tue, 20 Feb 2024 16:00:21 -0800 Subject: [PATCH 04/22] fix lint error --- mmv1/products/cloudquotas/QuotaPreference.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/products/cloudquotas/QuotaPreference.yaml b/mmv1/products/cloudquotas/QuotaPreference.yaml index 3423334da219..20ddcf6cb689 100644 --- a/mmv1/products/cloudquotas/QuotaPreference.yaml +++ b/mmv1/products/cloudquotas/QuotaPreference.yaml @@ -161,4 +161,4 @@ properties: description: |- An email address that can be used for quota related communication between the Google Cloud and the user in case the Google Cloud needs further information to make a decision on whether the user preferred quota can be granted. - The Google account for the email address must have quota update permission for the project, folder or organization this quota preference is for. \ No newline at end of file + The Google account for the email address must have quota update permission for the project, folder or organization this quota preference is for. From 2c57c14fceda9b68478a49313c7117e4ada66923 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Tue, 27 Feb 2024 13:55:09 -0800 Subject: [PATCH 05/22] update yaml config --- .../products/cloudquotas/QuotaPreference.yaml | 21 ++++------ .../cloudquotas_quota_preference_basic.tf.erb | 6 +-- ...urce_cloud_quotas_quota_preference_test.go | 41 +++---------------- 3 files changed, 17 insertions(+), 51 deletions(-) diff --git a/mmv1/products/cloudquotas/QuotaPreference.yaml b/mmv1/products/cloudquotas/QuotaPreference.yaml index 20ddcf6cb689..a8ccb984de31 100644 --- a/mmv1/products/cloudquotas/QuotaPreference.yaml +++ b/mmv1/products/cloudquotas/QuotaPreference.yaml @@ -50,8 +50,7 @@ parameters: name: 'quota_preference_id' immutable: true url_param_only: true - default_value: "" - description: The unique quota preference id. + description: The unique quota preference id. A UUID will be generated as the ID if the quota preference ID is empty. - !ruby/object:Api::Type::Boolean name: 'allow_missing' url_param_only: true @@ -75,6 +74,8 @@ parameters: properties: - !ruby/object:Api::Type::String name: 'name' + conflicts: + - parent description: | The resource name of the quota preference. Required except in the CREATE requests. - !ruby/object:Api::Type::String @@ -86,7 +87,7 @@ properties: required: true description: | The id of the quota to which the quota preference is applied. A quota id is unique in the service. - Example: CPUS-per-project-region. + Example: `CPUS-per-project-region`. - !ruby/object:Api::Type::NestedObject name: 'quotaConfig' required: true @@ -115,15 +116,11 @@ properties: description: |- The annotations map for clients to store small amounts of arbitrary data. Do not put PII or other sensitive information here. See https://google.aip.dev/128#annotations. - An object containing a list of "key: value" pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }. - - !ruby/object:Api::Type::Enum + An object containing a list of "key: value" pairs. Example: `{ "name": "wrench", "mass": "1.3kg", "count": "3" }`. + - !ruby/object:Api::Type::String name: 'requestOrigin' output: true description: The origin of the quota preference request. - values: - - :ORIGIN_UNSPECIFIED - - :CLOUD_CONSOLE` - - :AUTO_ADJUSTER - !ruby/object:Api::Type::KeyValuePairs name: 'dimensions' description: |- @@ -131,7 +128,7 @@ properties: NOTE: QuotaPreferences can only be applied across all values of "user" and "resource" dimension. Do not set values for "user" or "resource" in the dimension map. - Example: {"provider", "Foo Inc"} where "provider" is a service specific dimension. + Example: `{"provider": "Foo Inc"}` where "provider" is a service specific dimension. - !ruby/object:Api::Type::String name: 'etag' description: | @@ -141,13 +138,13 @@ properties: output: true description: | Create time stamp. - A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z". + A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: `2014-10-02T15:01:23Z` and `2014-10-02T15:01:23.045123456Z`. - !ruby/object:Api::Type::String name: 'updateTime' output: true description: | Update time stamp. - A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z". + A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: `2014-10-02T15:01:23Z` and `2014-10-02T15:01:23.045123456Z`. - !ruby/object:Api::Type::Boolean name: 'reconciling' output: true diff --git a/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb b/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb index 8e9abce96a48..df300a13dd8a 100644 --- a/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb +++ b/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb @@ -1,15 +1,13 @@ -# [START cloudquotas_quota_preference_basic] resource "google_cloud_quotas_quota_preference" "<%= ctx[:primary_resource_id] %>" { name = "projects/<%= ctx[:test_env_vars]['project'] %>/locations/global/quotaPreferences/<%= ctx[:vars]['quota_preference_id'] %>" quota_config { - preferred_value = 210 + preferred_value = 200 } dimensions = { region = "us-central2" } service = "compute.googleapis.com" quota_id = "CPUS-per-project-region" - contact_email = "liulola@google.com" + contact_email = "testuser@gmail.com" justification = "Increase quota for terraform testing." } -# [END cloudquotas_quota_preference_basic] diff --git a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go index 618c37465735..868751557ea9 100644 --- a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go +++ b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go @@ -1,3 +1,5 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 package cloudquotas_test import ( @@ -13,23 +15,13 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up t.Parallel() context := map[string]interface{}{ - "project": envvar.GetTestProjectFromEnv(), - "random_suffix": acctest.RandString(t, 10), + "project": envvar.GetTestProjectFromEnv(), } acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), Steps: []resource.TestStep{ - { - Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_basic(context), - }, - { - ResourceName: "google_cloud_quotas_quota_preference.preference", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks"}, - }, { Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_update(context), }, @@ -43,40 +35,19 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up }) } -func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_basic(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloud_quotas_quota_preference" "preference" { - name = "projects/%{project}/locations/global/quotaPreferences/tf-test-compute_googleapis_com-CPUS-per-project_us-central2%{random_suffix}" - quota_config { - preferred_value = 210 - } - dimensions = { - region = "us-central1" - } - service = "compute.googleapis.com" - quota_id = "CPUS-per-project-region" - contact_email = "liulola@google.com" - justification = "Increase quota for terraform testing." -} -`, context) -} - func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_update(context map[string]interface{}) string { return acctest.Nprintf(` -resource "google_cloud_quotas_quota_preference" "preference" { - name = "projects/%{project}/locations/global/quotaPreferences/tf-test-compute_CPUS-per-project_compute_googleapis_com-CPUS-per-project_us-east1%{random_suffix}" +resource "google_cloud_quotas_quota_preference" "my-preference" { + name = "projects/%{project}/locations/global/quotaPreferences/compute_googleapis_com-CPUS-per-project-us-central1" quota_config { preferred_value = 200 } - dimensions = { - region = "us-east1" - } + dimensions = { region = "us-central1" } service = "compute.googleapis.com" quota_id = "CPUS-per-project-region" contact_email = "liulola@google.com" justification = "Increase quota for terraform testing." validate_only = true - allow_missing = true } `, context) } From 2fb6fe02bdd6a5416b47f86d0db3471d9d33f3ad Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Tue, 27 Feb 2024 14:26:13 -0800 Subject: [PATCH 06/22] remove trailing spaces --- mmv1/products/cloudquotas/QuotaPreference.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/products/cloudquotas/QuotaPreference.yaml b/mmv1/products/cloudquotas/QuotaPreference.yaml index a8ccb984de31..6282089f610f 100644 --- a/mmv1/products/cloudquotas/QuotaPreference.yaml +++ b/mmv1/products/cloudquotas/QuotaPreference.yaml @@ -74,7 +74,7 @@ parameters: properties: - !ruby/object:Api::Type::String name: 'name' - conflicts: + conflicts: - parent description: | The resource name of the quota preference. Required except in the CREATE requests. From 9689ded6d050e0a74bf6a0d89984ea1647f557d5 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Mon, 4 Mar 2024 12:05:28 -0800 Subject: [PATCH 07/22] modify update test --- ...urce_cloud_quotas_quota_preference_test.go | 81 +++++++++++++++---- 1 file changed, 67 insertions(+), 14 deletions(-) diff --git a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go index 868751557ea9..c2e8f6f4aab7 100644 --- a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go +++ b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go @@ -1,5 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 package cloudquotas_test import ( @@ -15,13 +17,27 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up t.Parallel() context := map[string]interface{}{ - "project": envvar.GetTestProjectFromEnv(), + "org_id": envvar.GetTestOrgFromEnv(t), + "billing_account": envvar.GetTestBillingAccountFromEnv(t), + "random_suffix": acctest.RandString(t, 10), } acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + ExternalProviders: map[string]resource.ExternalProvider{ + "time": {}, + }, Steps: []resource.TestStep{ + { + Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_basic(context), + }, + { + ResourceName: "google_cloud_quotas_quota_preference.preference", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks"}, + }, { Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_update(context), }, @@ -35,19 +51,56 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up }) } -func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_update(context map[string]interface{}) string { +func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_basic(context map[string]interface{}) string { return acctest.Nprintf(` -resource "google_cloud_quotas_quota_preference" "my-preference" { - name = "projects/%{project}/locations/global/quotaPreferences/compute_googleapis_com-CPUS-per-project-us-central1" - quota_config { - preferred_value = 200 - } - dimensions = { region = "us-central1" } - service = "compute.googleapis.com" - quota_id = "CPUS-per-project-region" - contact_email = "liulola@google.com" - justification = "Increase quota for terraform testing." - validate_only = true + resource "google_project" "my_project" { + project_id = "tf-test%{random_suffix}" + name = "tf-test%{random_suffix}" + org_id = "%{org_id}" + billing_account = "%{billing_account}" + } + + resource "google_project_iam_binding" "project" { + project = google_project.my_project.project_id + role = "roles/cloudquotas.admin" + + members = [ + "user:liulola@google.com", + ] + } + + # Wait for project being created. + resource "time_sleep" "wait_120_seconds" { + depends_on = [google_project_iam_binding.project] + create_duration = "120s" + } + + resource "google_cloud_quotas_quota_preference" "my-preference" { + name = "projects/tf-test%{random_suffix}/locations/global/quotaPreferences/compute_googleapis_com-CPUS-per-project-us-central1" + quota_config { + preferred_value = 50 + } + dimensions = { region = "us-central1" } + service = "compute.googleapis.com" + quota_id = "CPUS-per-project-region" + contact_email = "liulola@google.com" + } + `, context) } -`, context) + +func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_update(context map[string]interface{}) string { + return acctest.Nprintf(` + resource "google_cloud_quotas_quota_preference" "my-preference" { + name = "projects/tf-test%{random_suffix}/locations/global/quotaPreferences/compute_googleapis_com-CPUS-per-project-us-central1" + quota_config { + preferred_value = 200 + } + dimensions = { region = "us-central1" } + service = "compute.googleapis.com" + quota_id = "CPUS-per-project-region" + contact_email = "liulola@google.com" + justification = "Increase quota for terraform testing." + validate_only = true + } + `, context) } From d8470a9f28e5283b9cb5deb30472b7814741fe66 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Wed, 6 Mar 2024 14:17:57 -0800 Subject: [PATCH 08/22] update acceptance test and cleanup --- .../products/cloudquotas/QuotaPreference.yaml | 35 ++++--- .../cloudquotas_quota_preference.go.erb | 3 + .../encoders/quota_preference.go.erb | 39 -------- .../cloudquotas_quota_preference_basic.tf.erb | 14 ++- ...urce_cloud_quotas_quota_preference_test.go | 91 ++++++++++++------- 5 files changed, 92 insertions(+), 90 deletions(-) create mode 100644 mmv1/templates/terraform/constants/cloudquotas_quota_preference.go.erb delete mode 100644 mmv1/templates/terraform/encoders/quota_preference.go.erb diff --git a/mmv1/products/cloudquotas/QuotaPreference.yaml b/mmv1/products/cloudquotas/QuotaPreference.yaml index 6282089f610f..ab42b8e0fee3 100644 --- a/mmv1/products/cloudquotas/QuotaPreference.yaml +++ b/mmv1/products/cloudquotas/QuotaPreference.yaml @@ -20,15 +20,17 @@ references: !ruby/object:Api::Resource::ReferenceLinks 'Cloud Quotas Overview': 'https://cloud.google.com/docs/quotas/overview' api: 'https://cloud.google.com/docs/quotas/reference/rest/v1/projects.locations.quotaPreferences' base_url: '{{parent}}/locations/global/quotaPreferences' -self_link: '{{parent}}/locations/global/quotaPreferences/{{quota_preference_id}}' -create_url: '{{parent}}/locations/global/quotaPreferences?quotaPreferenceId={{quota_preference_id}}&ignoreSafetyChecks={{ignore_safety_checks}}' -update_url: '{{parent}}/locations/global/quotaPreferences/{{quota_preference_id}}?allowMissing={{allow_missing}}&validateOnly={{validate_only}}&ignoreSafetyChecks={{ignore_safety_checks}}' +self_link: '{{parent}}/locations/global/quotaPreferences/{{name}}' +create_url: '{{parent}}/locations/global/quotaPreferences?quotaPreferenceId={{name}}&ignoreSafetyChecks={{ignore_safety_checks}}' +update_url: '{{parent}}/locations/global/quotaPreferences/{{name}}?allowMissing={{allow_missing}}&validateOnly={{validate_only}}&ignoreSafetyChecks={{ignore_safety_checks}}' update_verb: :PATCH update_mask: true skip_delete: true autogen_async: false +import_format: ['{{%parent}}/locations/global/quotaPreferences/{{name}}'] +id_format: '{{parent}}/locations/global/quotaPreferences/{{name}}' custom_code: !ruby/object:Provider::Terraform::CustomCode - encoder: templates/terraform/encoders/quota_preference.go.erb + constants: templates/terraform/constants/cloudquotas_quota_preference.go.erb examples: - !ruby/object:Provider::Terraform::Examples @@ -36,7 +38,7 @@ examples: primary_resource_id: "preference" skip_test: true vars: - quota_preference_id: "compute_googleapis_com-CPUS-per-project_us-central2" + name: "compute_googleapis_com-CPUS-per-project_us-east1" test_env_vars: project: :PROJECT_NAME @@ -45,20 +47,19 @@ parameters: name: 'parent' immutable: true url_param_only: true + required: true + default_from_api: true description: The parent of the quota preference. Allowed parents are "projects/[project-id / number]" or "folders/[folder-id / number]" or "organizations/[org-id / number]". - - !ruby/object:Api::Type::String - name: 'quota_preference_id' - immutable: true - url_param_only: true - description: The unique quota preference id. A UUID will be generated as the ID if the quota preference ID is empty. - !ruby/object:Api::Type::Boolean name: 'allow_missing' url_param_only: true + default_value: true description: | If set to true, and the quota preference is not found, a new one will be created. In this situation, updateMask is ignored. - !ruby/object:Api::Type::Boolean name: 'validate_only' url_param_only: true + default_value: false description: | If set to true, validate the request, but do not actually update. Note that a request being valid does not mean that the request is guaranteed to be fulfilled. - !ruby/object:Api::Type::Enum @@ -74,17 +75,22 @@ parameters: properties: - !ruby/object:Api::Type::String name: 'name' - conflicts: - - parent + default_from_api: true + pattern: '{{parent}}/locations/global/quotaPreferences/{{name}}' description: | The resource name of the quota preference. Required except in the CREATE requests. + diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName' + custom_expand: templates/terraform/custom_expand/resource_from_self_link.go.erb + custom_flatten: templates/terraform/custom_flatten/name_from_self_link.erb - !ruby/object:Api::Type::String name: 'service' required: true + default_from_api: true description: The name of the service to which the quota preference is applied. - !ruby/object:Api::Type::String name: 'quotaId' required: true + default_from_api: true description: | The id of the quota to which the quota preference is applied. A quota id is unique in the service. Example: `CPUS-per-project-region`. @@ -113,6 +119,7 @@ properties: The trace id that the Google Cloud uses to provision the requested quota. This trace id may be used by the client to contact Cloud support to track the state of a quota preference request. The trace id is only produced for increase requests and is unique for each request. The quota decrease requests do not have a trace id. - !ruby/object:Api::Type::KeyValuePairs name: 'annotations' + diff_suppress_func: QuotaConfigAnnotationsDiffSuppress description: |- The annotations map for clients to store small amounts of arbitrary data. Do not put PII or other sensitive information here. See https://google.aip.dev/128#annotations. @@ -123,6 +130,7 @@ properties: description: The origin of the quota preference request. - !ruby/object:Api::Type::KeyValuePairs name: 'dimensions' + default_from_api: true description: |- The dimensions that this quota preference applies to. The key of the map entry is the name of a dimension, such as "region", "zone", "network_id", and the value of the map entry is the dimension value. If a dimension is missing from the map of dimensions, the quota preference applies to all the dimension values except for those that have other quota preferences configured for the specific value. @@ -131,6 +139,7 @@ properties: Example: `{"provider": "Foo Inc"}` where "provider" is a service specific dimension. - !ruby/object:Api::Type::String name: 'etag' + output: true description: | The current etag of the quota preference. If an etag is provided on update and does not match the current server's etag of the quota preference, the request will be blocked and an ABORTED error will be returned. See https://google.aip.dev/134#etags for more details on etags. - !ruby/object:Api::Type::String @@ -152,9 +161,11 @@ properties: Is the quota preference pending Google Cloud approval and fulfillment. - !ruby/object:Api::Type::String name: 'justification' + ignore_read: true description: The reason / justification for this quota preference. - !ruby/object:Api::Type::String name: 'contactEmail' + ignore_read: true description: |- An email address that can be used for quota related communication between the Google Cloud and the user in case the Google Cloud needs further information to make a decision on whether the user preferred quota can be granted. diff --git a/mmv1/templates/terraform/constants/cloudquotas_quota_preference.go.erb b/mmv1/templates/terraform/constants/cloudquotas_quota_preference.go.erb new file mode 100644 index 000000000000..31dcd3069703 --- /dev/null +++ b/mmv1/templates/terraform/constants/cloudquotas_quota_preference.go.erb @@ -0,0 +1,3 @@ +func QuotaConfigAnnotationsDiffSuppress(k, old, new string, d *schema.ResourceData) bool { + return true +} \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/quota_preference.go.erb b/mmv1/templates/terraform/encoders/quota_preference.go.erb deleted file mode 100644 index 9b96123f3cde..000000000000 --- a/mmv1/templates/terraform/encoders/quota_preference.go.erb +++ /dev/null @@ -1,39 +0,0 @@ -<%- # the license inside this block applies to this file - # Copyright 2023 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. --%> - -parent := d.Get("parent").(string) -preference_id := d.Get("quota_preference_id").(string) - -if d.Get("name") != nil { - preference_name := d.Get("name").(string) - - parent, err := tpgresource.ExtractFieldByPattern("parent", parent, preference_name, "((projects|folders|organizations)/([a-z0-9A-Z-]*))/.*") - if err != nil { - return nil, fmt.Errorf("error extracting parent field: %s", err) - } - d.Set("parent", parent) - - preference_id, err := tpgresource.ExtractFieldByPattern("quota_preference", preference_id, preference_name, ".*quotaPreferences/([a-zA-Z0-9-_]+)" ) - if err != nil { - return nil, fmt.Errorf("error extracting preference id field: %s", err) - } - d.Set("quota_preference_id", preference_id) -} else { - if parent != "" { - return nil, fmt.Errorf("'parent' field missing.") - } -} - -return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb b/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb index df300a13dd8a..af168e050e95 100644 --- a/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb +++ b/mmv1/templates/terraform/examples/cloudquotas_quota_preference_basic.tf.erb @@ -1,13 +1,11 @@ resource "google_cloud_quotas_quota_preference" "<%= ctx[:primary_resource_id] %>" { - name = "projects/<%= ctx[:test_env_vars]['project'] %>/locations/global/quotaPreferences/<%= ctx[:vars]['quota_preference_id'] %>" - quota_config { - preferred_value = 200 - } - dimensions = { - region = "us-central2" - } + parent = "projects/<%= ctx[:test_env_vars]['project'] %>" + name = "<%= ctx[:vars]['name'] %>" + dimensions = { region = "us-east1" } service = "compute.googleapis.com" quota_id = "CPUS-per-project-region" contact_email = "testuser@gmail.com" - justification = "Increase quota for terraform testing." + quota_config { + preferred_value = 200 + } } diff --git a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go index c2e8f6f4aab7..91d2e1b41e0a 100644 --- a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go +++ b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go @@ -1,7 +1,5 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 package cloudquotas_test import ( @@ -33,19 +31,29 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_basic(context), }, { - ResourceName: "google_cloud_quotas_quota_preference.preference", + ResourceName: "google_cloud_quotas_quota_preference.my_preference", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks", "contact_email"}, + }, + { + Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_increaseQuota(context), + }, + { + ResourceName: "google_cloud_quotas_quota_preference.my_preference", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks"}, + ExpectNonEmptyPlan: true, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks", "contact_email", "justification", "quota_config.0.annotations"}, }, { - Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_update(context), + Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_decreaseQuota(context), }, { - ResourceName: "google_cloud_quotas_quota_preference.preference", + ResourceName: "google_cloud_quotas_quota_preference.my_preference", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks"}, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks", "contact_email", "justification"}, }, }, }) @@ -53,54 +61,75 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_basic(context map[string]interface{}) string { return acctest.Nprintf(` - resource "google_project" "my_project" { + resource "google_project" "new_project" { project_id = "tf-test%{random_suffix}" name = "tf-test%{random_suffix}" org_id = "%{org_id}" billing_account = "%{billing_account}" } - resource "google_project_iam_binding" "project" { - project = google_project.my_project.project_id + resource "google_project_service" "cloudquotas" { + project = google_project.new_project.project_id + service = "cloudquotas.googleapis.com" + depends_on = [google_project.new_project] + } + + resource "google_project_service" "billing" { + project = google_project.new_project.project_id + service = "cloudbilling.googleapis.com" + depends_on = [google_project.new_project] + } + + resource "google_project_iam_binding" "project_iam" { + project = google_project_service.cloudquotas.project role = "roles/cloudquotas.admin" members = [ - "user:liulola@google.com", + "user:liulola@google.com" ] + depends_on = [google_project.new_project] } - # Wait for project being created. resource "time_sleep" "wait_120_seconds" { - depends_on = [google_project_iam_binding.project] + depends_on = [google_project_iam_binding.project_iam] create_duration = "120s" } - resource "google_cloud_quotas_quota_preference" "my-preference" { - name = "projects/tf-test%{random_suffix}/locations/global/quotaPreferences/compute_googleapis_com-CPUS-per-project-us-central1" - quota_config { - preferred_value = 50 + resource "google_cloud_quotas_quota_preference" "my_preference"{ + parent = "projects/${google_project_iam_binding.project_iam.project}" + name = "compute_googleapis_com-A2-CPUS-per-project_asia-northeast1" + dimensions = { region = "asia-northeast1" } + service = "compute.googleapis.com" + quota_id = "A2-CPUS-per-project-region" + contact_email = "liulola@google.com" + quota_config { + preferred_value = 12 + } + } + `, context) +} + +func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_increaseQuota(context map[string]interface{}) string { + return acctest.Nprintf(` + resource "google_cloud_quotas_quota_preference" "my_preference"{ + contact_email = "liulola@google.com" + justification = "Increase quota for Terraform testing." + quota_config { + preferred_value = 12 + annotations = { label = "terraform" } } - dimensions = { region = "us-central1" } - service = "compute.googleapis.com" - quota_id = "CPUS-per-project-region" - contact_email = "liulola@google.com" } `, context) } -func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_update(context map[string]interface{}) string { +func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_decreaseQuota(context map[string]interface{}) string { return acctest.Nprintf(` - resource "google_cloud_quotas_quota_preference" "my-preference" { - name = "projects/tf-test%{random_suffix}/locations/global/quotaPreferences/compute_googleapis_com-CPUS-per-project-us-central1" + resource "google_cloud_quotas_quota_preference" "my_preference"{ + contact_email = "liulola@google.com" + ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" quota_config { - preferred_value = 200 + preferred_value = 10 } - dimensions = { region = "us-central1" } - service = "compute.googleapis.com" - quota_id = "CPUS-per-project-region" - contact_email = "liulola@google.com" - justification = "Increase quota for terraform testing." - validate_only = true } `, context) } From 95ec8991735d2ff59d928a5adab95d88228bb672 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Wed, 6 Mar 2024 16:56:57 -0800 Subject: [PATCH 09/22] add upsert scenario for testing --- .../products/cloudquotas/QuotaPreference.yaml | 1 - ...urce_cloud_quotas_quota_preference_test.go | 196 +++++++++++++++--- 2 files changed, 165 insertions(+), 32 deletions(-) diff --git a/mmv1/products/cloudquotas/QuotaPreference.yaml b/mmv1/products/cloudquotas/QuotaPreference.yaml index ab42b8e0fee3..de92d20664f8 100644 --- a/mmv1/products/cloudquotas/QuotaPreference.yaml +++ b/mmv1/products/cloudquotas/QuotaPreference.yaml @@ -130,7 +130,6 @@ properties: description: The origin of the quota preference request. - !ruby/object:Api::Type::KeyValuePairs name: 'dimensions' - default_from_api: true description: |- The dimensions that this quota preference applies to. The key of the map entry is the name of a dimension, such as "region", "zone", "network_id", and the value of the map entry is the dimension value. If a dimension is missing from the map of dimensions, the quota preference applies to all the dimension values except for those that have other quota preferences configured for the specific value. diff --git a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go index 91d2e1b41e0a..42decee0e62b 100644 --- a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go +++ b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go @@ -68,42 +68,49 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_ba billing_account = "%{billing_account}" } - resource "google_project_service" "cloudquotas" { - project = google_project.new_project.project_id - service = "cloudquotas.googleapis.com" - depends_on = [google_project.new_project] + resource "google_project_iam_binding" "project_iam" { + project = google_project.new_project.project_id + role = "roles/cloudquotas.admin" + members = [ + "user:testinguser2@google.com" + ] + depends_on = [google_project.new_project] } - resource "google_project_service" "billing" { - project = google_project.new_project.project_id - service = "cloudbilling.googleapis.com" - depends_on = [google_project.new_project] + resource "google_project_service" "cloudquotas" { + project = google_project.new_project.project_id + service = "cloudquotas.googleapis.com" + depends_on = [google_project_iam_binding.project_iam] } - resource "google_project_iam_binding" "project_iam" { - project = google_project_service.cloudquotas.project - role = "roles/cloudquotas.admin" - - members = [ - "user:liulola@google.com" - ] - depends_on = [google_project.new_project] + resource "google_project_service" "compute" { + project = google_project.new_project.project_id + service = "compute.googleapis.com" + depends_on = [google_project_service.cloudquotas] } - resource "time_sleep" "wait_120_seconds" { - depends_on = [google_project_iam_binding.project_iam] - create_duration = "120s" + resource "google_project_service" "billing" { + project = google_project.new_project.project_id + service = "cloudbilling.googleapis.com" + depends_on = [google_project_service.compute] + } + + resource "time_sleep" "wait_180_seconds" { + create_duration = "180s" + depends_on = [ + google_project_service.billing, + ] } resource "google_cloud_quotas_quota_preference" "my_preference"{ - parent = "projects/${google_project_iam_binding.project_iam.project}" - name = "compute_googleapis_com-A2-CPUS-per-project_asia-northeast1" - dimensions = { region = "asia-northeast1" } + parent = "projects/${google_project_service.billing.project}" + name = "compute_googleapis_com-CPUS-per-project_us-central1" + dimensions = { region = "us-central1" } service = "compute.googleapis.com" - quota_id = "A2-CPUS-per-project-region" - contact_email = "liulola@google.com" + quota_id = "CPUS-per-project-region" + contact_email = "testinguser2@google.com" quota_config { - preferred_value = 12 + preferred_value = 70 } } `, context) @@ -111,11 +118,46 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_ba func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_increaseQuota(context map[string]interface{}) string { return acctest.Nprintf(` + resource "google_project" "new_project" { + project_id = "tf-test%{random_suffix}" + name = "tf-test%{random_suffix}" + org_id = "%{org_id}" + billing_account = "%{billing_account}" + } + + resource "google_project_iam_binding" "project_iam" { + project = google_project.new_project.project_id + role = "roles/cloudquotas.admin" + members = [ + "user:testinguser2@google.com" + ] + depends_on = [google_project.new_project] + } + + resource "google_project_service" "cloudquotas" { + project = google_project.new_project.project_id + service = "cloudquotas.googleapis.com" + depends_on = [google_project_iam_binding.project_iam] + } + + resource "google_project_service" "compute" { + project = google_project.new_project.project_id + service = "compute.googleapis.com" + depends_on = [google_project_service.cloudquotas] + } + + resource "google_project_service" "billing" { + project = google_project.new_project.project_id + service = "cloudbilling.googleapis.com" + depends_on = [google_project_service.compute] + } + resource "google_cloud_quotas_quota_preference" "my_preference"{ - contact_email = "liulola@google.com" - justification = "Increase quota for Terraform testing." + dimensions = { region = "us-central1" } + contact_email = "testinguser2@google.com" + justification = "Ignore. Increase quota for Terraform testing." quota_config { - preferred_value = 12 + preferred_value = 72 annotations = { label = "terraform" } } } @@ -124,12 +166,104 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_in func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_decreaseQuota(context map[string]interface{}) string { return acctest.Nprintf(` + resource "google_project" "new_project" { + project_id = "tf-test%{random_suffix}" + name = "tf-test%{random_suffix}" + org_id = "%{org_id}" + billing_account = "%{billing_account}" + } + + resource "google_project_iam_binding" "project_iam" { + project = google_project.new_project.project_id + role = "roles/cloudquotas.admin" + members = [ + "user:testinguser2@google.com" + ] + depends_on = [google_project.new_project] + } + + resource "google_project_service" "cloudquotas" { + project = google_project.new_project.project_id + service = "cloudquotas.googleapis.com" + depends_on = [google_project_iam_binding.project_iam] + } + + resource "google_project_service" "compute" { + project = google_project.new_project.project_id + service = "compute.googleapis.com" + depends_on = [google_project_service.cloudquotas] + } + + resource "google_project_service" "billing" { + project = google_project.new_project.project_id + service = "cloudbilling.googleapis.com" + depends_on = [google_project_service.compute] + } + + resource "google_cloud_quotas_quota_preference" "my_preference"{ + dimensions = { region = "us-central1" } + contact_email = "testinguser2@google.com" + ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" + quota_config { + preferred_value = 65 + } + } + `, context) +} + +func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_upsert(context map[string]interface{}) string { + return acctest.Nprintf(` + resource "google_project" "new_project" { + project_id = "tf-test%{random_suffix}" + name = "tf-test%{random_suffix}" + org_id = "%{org_id}" + billing_account = "%{billing_account}" + } + + resource "google_project_iam_binding" "project_iam" { + project = google_project.new_project.project_id + role = "roles/cloudquotas.admin" + members = [ + "user:testinguser3@google.com" + ] + depends_on = [google_project.new_project] + } + + resource "google_project_service" "cloudquotas" { + project = google_project.new_project.project_id + service = "cloudquotas.googleapis.com" + depends_on = [google_project_iam_binding.project_iam] + } + + resource "google_project_service" "compute" { + project = google_project.new_project.project_id + service = "compute.googleapis.com" + depends_on = [google_project_service.cloudquotas] + } + + resource "google_project_service" "billing" { + project = google_project.new_project.project_id + service = "cloudbilling.googleapis.com" + depends_on = [google_project_service.compute] + } + + resource "time_sleep" "wait_180_seconds" { + depends_on = [ + google_project_service.billing, + ] + create_duration = "180s" + } + resource "google_cloud_quotas_quota_preference" "my_preference"{ - contact_email = "liulola@google.com" - ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" + parent = "projects/${google_project_service.billing.project}" + name = "libraryagent_googleapis_com-ReadsPerMinutePerProject" + service = "libraryagent.googleapis.com" + quota_id = "ReadsPerMinutePerProject" + contact_email = "testinguser3@google.com" quota_config { - preferred_value = 10 + preferred_value = 15 } + allow_missing = true } `, context) } From 6f3e3c72524531edf2f0020947eace413afb3d6c Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Thu, 7 Mar 2024 10:06:23 -0800 Subject: [PATCH 10/22] update acceptance test syntax --- ...urce_cloud_quotas_quota_preference_test.go | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go index 42decee0e62b..cc3b0ffb628a 100644 --- a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go +++ b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go @@ -55,6 +55,15 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up ImportStateVerify: true, ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks", "contact_email", "justification"}, }, + { + Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_upsert(context), + }, + { + ResourceName: "google_cloud_quotas_quota_preference.my_preference", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks", "contact_email", "justification"}, + }, }, }) } @@ -64,8 +73,8 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_ba resource "google_project" "new_project" { project_id = "tf-test%{random_suffix}" name = "tf-test%{random_suffix}" - org_id = "%{org_id}" - billing_account = "%{billing_account}" + org_id = "%{org_id}" + billing_account = "%{billing_account}" } resource "google_project_iam_binding" "project_iam" { @@ -96,8 +105,8 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_ba } resource "time_sleep" "wait_180_seconds" { - create_duration = "180s" - depends_on = [ + create_duration = "180s" + depends_on = [ google_project_service.billing, ] } @@ -121,8 +130,8 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_in resource "google_project" "new_project" { project_id = "tf-test%{random_suffix}" name = "tf-test%{random_suffix}" - org_id = "%{org_id}" - billing_account = "%{billing_account}" + org_id = "%{org_id}" + billing_account = "%{billing_account}" } resource "google_project_iam_binding" "project_iam" { @@ -152,9 +161,16 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_in depends_on = [google_project_service.compute] } + resource "time_sleep" "wait_180_seconds" { + create_duration = "180s" + depends_on = [ + google_project_service.billing, + ] + } + resource "google_cloud_quotas_quota_preference" "my_preference"{ - dimensions = { region = "us-central1" } - contact_email = "testinguser2@google.com" + dimensions = { region = "us-central1" } + contact_email = "testinguser2@google.com" justification = "Ignore. Increase quota for Terraform testing." quota_config { preferred_value = 72 @@ -169,8 +185,8 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_de resource "google_project" "new_project" { project_id = "tf-test%{random_suffix}" name = "tf-test%{random_suffix}" - org_id = "%{org_id}" - billing_account = "%{billing_account}" + org_id = "%{org_id}" + billing_account = "%{billing_account}" } resource "google_project_iam_binding" "project_iam" { @@ -200,12 +216,19 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_de depends_on = [google_project_service.compute] } + resource "time_sleep" "wait_180_seconds" { + create_duration = "180s" + depends_on = [ + google_project_service.billing, + ] + } + resource "google_cloud_quotas_quota_preference" "my_preference"{ - dimensions = { region = "us-central1" } + dimensions = { region = "us-central1" } contact_email = "testinguser2@google.com" - ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" + ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" quota_config { - preferred_value = 65 + preferred_value = 65 } } `, context) @@ -216,8 +239,8 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up resource "google_project" "new_project" { project_id = "tf-test%{random_suffix}" name = "tf-test%{random_suffix}" - org_id = "%{org_id}" - billing_account = "%{billing_account}" + org_id = "%{org_id}" + billing_account = "%{billing_account}" } resource "google_project_iam_binding" "project_iam" { @@ -248,20 +271,20 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up } resource "time_sleep" "wait_180_seconds" { - depends_on = [ + create_duration = "180s" + depends_on = [ google_project_service.billing, ] - create_duration = "180s" } resource "google_cloud_quotas_quota_preference" "my_preference"{ parent = "projects/${google_project_service.billing.project}" name = "libraryagent_googleapis_com-ReadsPerMinutePerProject" - service = "libraryagent.googleapis.com" - quota_id = "ReadsPerMinutePerProject" - contact_email = "testinguser3@google.com" + service = "libraryagent.googleapis.com" + quota_id = "ReadsPerMinutePerProject" + contact_email = "testinguser3@google.com" quota_config { - preferred_value = 15 + preferred_value = 15 } allow_missing = true } From c1ac0f27d29f2fc5715dbc441e9370a183543119 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Mon, 11 Mar 2024 12:18:30 -0700 Subject: [PATCH 11/22] remove allow-missing flag & fix update test failure --- .../products/cloudquotas/QuotaPreference.yaml | 11 +- ...urce_cloud_quotas_quota_preference_test.go | 131 +++--------------- 2 files changed, 21 insertions(+), 121 deletions(-) diff --git a/mmv1/products/cloudquotas/QuotaPreference.yaml b/mmv1/products/cloudquotas/QuotaPreference.yaml index de92d20664f8..b24162847f89 100644 --- a/mmv1/products/cloudquotas/QuotaPreference.yaml +++ b/mmv1/products/cloudquotas/QuotaPreference.yaml @@ -22,13 +22,11 @@ references: !ruby/object:Api::Resource::ReferenceLinks base_url: '{{parent}}/locations/global/quotaPreferences' self_link: '{{parent}}/locations/global/quotaPreferences/{{name}}' create_url: '{{parent}}/locations/global/quotaPreferences?quotaPreferenceId={{name}}&ignoreSafetyChecks={{ignore_safety_checks}}' -update_url: '{{parent}}/locations/global/quotaPreferences/{{name}}?allowMissing={{allow_missing}}&validateOnly={{validate_only}}&ignoreSafetyChecks={{ignore_safety_checks}}' +update_url: '{{parent}}/locations/global/quotaPreferences/{{name}}?validateOnly={{validate_only}}&ignoreSafetyChecks={{ignore_safety_checks}}' update_verb: :PATCH update_mask: true skip_delete: true autogen_async: false -import_format: ['{{%parent}}/locations/global/quotaPreferences/{{name}}'] -id_format: '{{parent}}/locations/global/quotaPreferences/{{name}}' custom_code: !ruby/object:Provider::Terraform::CustomCode constants: templates/terraform/constants/cloudquotas_quota_preference.go.erb @@ -50,12 +48,6 @@ parameters: required: true default_from_api: true description: The parent of the quota preference. Allowed parents are "projects/[project-id / number]" or "folders/[folder-id / number]" or "organizations/[org-id / number]". - - !ruby/object:Api::Type::Boolean - name: 'allow_missing' - url_param_only: true - default_value: true - description: | - If set to true, and the quota preference is not found, a new one will be created. In this situation, updateMask is ignored. - !ruby/object:Api::Type::Boolean name: 'validate_only' url_param_only: true @@ -130,6 +122,7 @@ properties: description: The origin of the quota preference request. - !ruby/object:Api::Type::KeyValuePairs name: 'dimensions' + default_from_api: true description: |- The dimensions that this quota preference applies to. The key of the map entry is the name of a dimension, such as "region", "zone", "network_id", and the value of the map entry is the dimension value. If a dimension is missing from the map of dimensions, the quota preference applies to all the dimension values except for those that have other quota preferences configured for the specific value. diff --git a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go index cc3b0ffb628a..0a6599205633 100644 --- a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go +++ b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go @@ -1,5 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 package cloudquotas_test import ( @@ -34,7 +36,7 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up ResourceName: "google_cloud_quotas_quota_preference.my_preference", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks", "contact_email"}, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "validate_only", "ignore_safety_checks", "contact_email"}, }, { Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_increaseQuota(context), @@ -44,7 +46,7 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up ImportState: true, ImportStateVerify: true, ExpectNonEmptyPlan: true, - ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks", "contact_email", "justification", "quota_config.0.annotations"}, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "validate_only", "ignore_safety_checks", "contact_email", "justification", "quota_config.0.annotations"}, }, { Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_decreaseQuota(context), @@ -53,16 +55,7 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up ResourceName: "google_cloud_quotas_quota_preference.my_preference", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks", "contact_email", "justification"}, - }, - { - Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_upsert(context), - }, - { - ResourceName: "google_cloud_quotas_quota_preference.my_preference", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "allow_missing", "validate_only", "ignore_safety_checks", "contact_email", "justification"}, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "validate_only", "ignore_safety_checks", "contact_email", "justification"}, }, }, }) @@ -73,23 +66,14 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_ba resource "google_project" "new_project" { project_id = "tf-test%{random_suffix}" name = "tf-test%{random_suffix}" - org_id = "%{org_id}" + org_id = "%{org_id}" billing_account = "%{billing_account}" } - resource "google_project_iam_binding" "project_iam" { - project = google_project.new_project.project_id - role = "roles/cloudquotas.admin" - members = [ - "user:testinguser2@google.com" - ] - depends_on = [google_project.new_project] - } - resource "google_project_service" "cloudquotas" { project = google_project.new_project.project_id service = "cloudquotas.googleapis.com" - depends_on = [google_project_iam_binding.project_iam] + depends_on = [google_project.new_project] } resource "google_project_service" "compute" { @@ -112,15 +96,16 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_ba } resource "google_cloud_quotas_quota_preference" "my_preference"{ - parent = "projects/${google_project_service.billing.project}" - name = "compute_googleapis_com-CPUS-per-project_us-central1" - dimensions = { region = "us-central1" } - service = "compute.googleapis.com" - quota_id = "CPUS-per-project-region" - contact_email = "testinguser2@google.com" + parent = "projects/${google_project_service.billing.project}" + name = "compute_googleapis_com-CPUS-per-project_us-central1" + dimensions = { region = "us-central1" } + service = "compute.googleapis.com" + quota_id = "CPUS-per-project-region" + contact_email = "testuser@gmail.com" quota_config { - preferred_value = 70 + preferred_value = 70 } + ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" } `, context) } @@ -130,23 +115,14 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_in resource "google_project" "new_project" { project_id = "tf-test%{random_suffix}" name = "tf-test%{random_suffix}" - org_id = "%{org_id}" + org_id = "%{org_id}" billing_account = "%{billing_account}" } - resource "google_project_iam_binding" "project_iam" { - project = google_project.new_project.project_id - role = "roles/cloudquotas.admin" - members = [ - "user:testinguser2@google.com" - ] - depends_on = [google_project.new_project] - } - resource "google_project_service" "cloudquotas" { project = google_project.new_project.project_id service = "cloudquotas.googleapis.com" - depends_on = [google_project_iam_binding.project_iam] + depends_on = [google_project.new_project] } resource "google_project_service" "compute" { @@ -169,7 +145,6 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_in } resource "google_cloud_quotas_quota_preference" "my_preference"{ - dimensions = { region = "us-central1" } contact_email = "testinguser2@google.com" justification = "Ignore. Increase quota for Terraform testing." quota_config { @@ -185,23 +160,14 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_de resource "google_project" "new_project" { project_id = "tf-test%{random_suffix}" name = "tf-test%{random_suffix}" - org_id = "%{org_id}" + org_id = "%{org_id}" billing_account = "%{billing_account}" } - resource "google_project_iam_binding" "project_iam" { - project = google_project.new_project.project_id - role = "roles/cloudquotas.admin" - members = [ - "user:testinguser2@google.com" - ] - depends_on = [google_project.new_project] - } - resource "google_project_service" "cloudquotas" { project = google_project.new_project.project_id service = "cloudquotas.googleapis.com" - depends_on = [google_project_iam_binding.project_iam] + depends_on = [google_project.new_project] } resource "google_project_service" "compute" { @@ -224,8 +190,6 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_de } resource "google_cloud_quotas_quota_preference" "my_preference"{ - dimensions = { region = "us-central1" } - contact_email = "testinguser2@google.com" ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" quota_config { preferred_value = 65 @@ -233,60 +197,3 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_de } `, context) } - -func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_upsert(context map[string]interface{}) string { - return acctest.Nprintf(` - resource "google_project" "new_project" { - project_id = "tf-test%{random_suffix}" - name = "tf-test%{random_suffix}" - org_id = "%{org_id}" - billing_account = "%{billing_account}" - } - - resource "google_project_iam_binding" "project_iam" { - project = google_project.new_project.project_id - role = "roles/cloudquotas.admin" - members = [ - "user:testinguser3@google.com" - ] - depends_on = [google_project.new_project] - } - - resource "google_project_service" "cloudquotas" { - project = google_project.new_project.project_id - service = "cloudquotas.googleapis.com" - depends_on = [google_project_iam_binding.project_iam] - } - - resource "google_project_service" "compute" { - project = google_project.new_project.project_id - service = "compute.googleapis.com" - depends_on = [google_project_service.cloudquotas] - } - - resource "google_project_service" "billing" { - project = google_project.new_project.project_id - service = "cloudbilling.googleapis.com" - depends_on = [google_project_service.compute] - } - - resource "time_sleep" "wait_180_seconds" { - create_duration = "180s" - depends_on = [ - google_project_service.billing, - ] - } - - resource "google_cloud_quotas_quota_preference" "my_preference"{ - parent = "projects/${google_project_service.billing.project}" - name = "libraryagent_googleapis_com-ReadsPerMinutePerProject" - service = "libraryagent.googleapis.com" - quota_id = "ReadsPerMinutePerProject" - contact_email = "testinguser3@google.com" - quota_config { - preferred_value = 15 - } - allow_missing = true - } - `, context) -} From 4e70fd0f1354d6069a58c826bf0d5a665f838325 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Mon, 11 Mar 2024 13:41:30 -0700 Subject: [PATCH 12/22] add import and id format --- mmv1/products/cloudquotas/QuotaPreference.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mmv1/products/cloudquotas/QuotaPreference.yaml b/mmv1/products/cloudquotas/QuotaPreference.yaml index b24162847f89..d0998a39a0b8 100644 --- a/mmv1/products/cloudquotas/QuotaPreference.yaml +++ b/mmv1/products/cloudquotas/QuotaPreference.yaml @@ -27,6 +27,8 @@ update_verb: :PATCH update_mask: true skip_delete: true autogen_async: false +import_format: ['{{%parent}}/locations/global/quotaPreferences/{{name}}'] +id_format: '{{parent}}/locations/global/quotaPreferences/{{name}}' custom_code: !ruby/object:Provider::Terraform::CustomCode constants: templates/terraform/constants/cloudquotas_quota_preference.go.erb From dfc19bc93d3459fc720567b2aa2f662bcad94584 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Tue, 12 Mar 2024 15:16:54 -0700 Subject: [PATCH 13/22] teamcity test failure - manually add cloudquotas service --- .../terraform/.teamcity/components/inputs/services_ga.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt b/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt index 08ce6c2ee82f..071ea16ec879 100644 --- a/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt @@ -178,6 +178,11 @@ var ServicesListGa = mapOf( "displayName" to "Cloudids", "path" to "./google/services/cloudids" ), + "cloudquotas" to mapOf( + "name" to "cloudquotas", + "displayName" to "Cloudquotas", + "path" to "./google/services/cloudquotas" + ), "cloudrun" to mapOf( "name" to "cloudrun", "displayName" to "Cloudrun", @@ -688,4 +693,4 @@ var ServicesListGa = mapOf( "displayName" to "Workstations", "path" to "./google/services/workstations" ) -) \ No newline at end of file +) From 5b9add60f99e84cfed761369a20832ff0caa66e0 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Tue, 12 Mar 2024 15:16:54 -0700 Subject: [PATCH 14/22] teamcity test failure - manually add cloudquotas service for beta --- .../terraform/.teamcity/components/inputs/services_beta.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt b/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt index 443987885a6f..2f3089f909db 100644 --- a/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt @@ -178,6 +178,11 @@ var ServicesListBeta = mapOf( "displayName" to "Cloudids", "path" to "./google-beta/services/cloudids" ), + "cloudquotas" to mapOf( + "name" to "cloudquotas", + "displayName" to "Cloudquotas", + "path" to "./google/services/cloudquotas" + ), "cloudrun" to mapOf( "name" to "cloudrun", "displayName" to "Cloudrun", From 165bdc8c8ee84e2f824b6669f2a2204e8d5f787b Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Tue, 12 Mar 2024 21:01:39 -0700 Subject: [PATCH 15/22] add field 'validate_only' to tests --- .../cloudquotas/resource_cloud_quotas_quota_preference_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go index 0a6599205633..df31b5b2cf7b 100644 --- a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go +++ b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go @@ -190,6 +190,7 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_de } resource "google_cloud_quotas_quota_preference" "my_preference"{ + validate_only = true ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" quota_config { preferred_value = 65 From 9171ac4f6f8ba53f969781727a84b3aad3cbcf8a Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Thu, 14 Mar 2024 15:50:24 -0700 Subject: [PATCH 16/22] address comments & fix test failure --- ...urce_cloud_quotas_quota_preference_test.go | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go index df31b5b2cf7b..9fcde020bd13 100644 --- a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go +++ b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go @@ -1,7 +1,3 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 package cloudquotas_test import ( @@ -45,7 +41,6 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up ResourceName: "google_cloud_quotas_quota_preference.my_preference", ImportState: true, ImportStateVerify: true, - ExpectNonEmptyPlan: true, ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "validate_only", "ignore_safety_checks", "contact_email", "justification", "quota_config.0.annotations"}, }, { @@ -66,7 +61,7 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_ba resource "google_project" "new_project" { project_id = "tf-test%{random_suffix}" name = "tf-test%{random_suffix}" - org_id = "%{org_id}" + org_id = "%{org_id}" billing_account = "%{billing_account}" } @@ -79,24 +74,26 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_ba resource "google_project_service" "compute" { project = google_project.new_project.project_id service = "compute.googleapis.com" - depends_on = [google_project_service.cloudquotas] + depends_on = [google_project.new_project] } resource "google_project_service" "billing" { project = google_project.new_project.project_id service = "cloudbilling.googleapis.com" - depends_on = [google_project_service.compute] + depends_on = [google_project.new_project] } resource "time_sleep" "wait_180_seconds" { create_duration = "180s" depends_on = [ + google_project_service.cloudquotas, + google_project_service.compute, google_project_service.billing, ] } resource "google_cloud_quotas_quota_preference" "my_preference"{ - parent = "projects/${google_project_service.billing.project}" + parent = "projects/${google_project.new_project.project_id}" name = "compute_googleapis_com-CPUS-per-project_us-central1" dimensions = { region = "us-central1" } service = "compute.googleapis.com" @@ -106,6 +103,9 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_ba preferred_value = 70 } ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" + depends_on = [ + time_sleep.wait_180_seconds + ] } `, context) } @@ -115,7 +115,7 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_in resource "google_project" "new_project" { project_id = "tf-test%{random_suffix}" name = "tf-test%{random_suffix}" - org_id = "%{org_id}" + org_id = "%{org_id}" billing_account = "%{billing_account}" } @@ -128,18 +128,20 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_in resource "google_project_service" "compute" { project = google_project.new_project.project_id service = "compute.googleapis.com" - depends_on = [google_project_service.cloudquotas] + depends_on = [google_project.new_project] } resource "google_project_service" "billing" { project = google_project.new_project.project_id service = "cloudbilling.googleapis.com" - depends_on = [google_project_service.compute] + depends_on = [google_project.new_project] } - + resource "time_sleep" "wait_180_seconds" { create_duration = "180s" depends_on = [ + google_project_service.cloudquotas, + google_project_service.compute, google_project_service.billing, ] } @@ -160,7 +162,7 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_de resource "google_project" "new_project" { project_id = "tf-test%{random_suffix}" name = "tf-test%{random_suffix}" - org_id = "%{org_id}" + org_id = "%{org_id}" billing_account = "%{billing_account}" } @@ -173,24 +175,25 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_de resource "google_project_service" "compute" { project = google_project.new_project.project_id service = "compute.googleapis.com" - depends_on = [google_project_service.cloudquotas] + depends_on = [google_project.new_project] } resource "google_project_service" "billing" { project = google_project.new_project.project_id service = "cloudbilling.googleapis.com" - depends_on = [google_project_service.compute] + depends_on = [google_project.new_project] } - + resource "time_sleep" "wait_180_seconds" { create_duration = "180s" depends_on = [ + google_project_service.cloudquotas, + google_project_service.compute, google_project_service.billing, ] } resource "google_cloud_quotas_quota_preference" "my_preference"{ - validate_only = true ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" quota_config { preferred_value = 65 From 06f26de3782c6da79a2b11bf3ae3c851a183e15e Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Fri, 15 Mar 2024 10:28:20 -0700 Subject: [PATCH 17/22] remove unused import --- .../terraform/provider/provider_mmv1_resources.go.erb | 3 --- 1 file changed, 3 deletions(-) diff --git a/mmv1/third_party/terraform/provider/provider_mmv1_resources.go.erb b/mmv1/third_party/terraform/provider/provider_mmv1_resources.go.erb index f58f2b57e660..dae368492232 100644 --- a/mmv1/third_party/terraform/provider/provider_mmv1_resources.go.erb +++ b/mmv1/third_party/terraform/provider/provider_mmv1_resources.go.erb @@ -15,9 +15,6 @@ import ( "github.com/hashicorp/terraform-provider-google/google/services/dataflow" "github.com/hashicorp/terraform-provider-google/google/services/servicenetworking" "github.com/hashicorp/terraform-provider-google/google/tpgiamresource" - <% if version == 'ga' -%> // https://github.com/hashicorp/terraform-provider-google/issues/15633 for details - "github.com/hashicorp/terraform-provider-google/google/services/cloudquotas" - <% end -%> ) // Datasources From 1188bed6bd167623ac1d9604d26f44ee83ae6e13 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Mon, 18 Mar 2024 13:50:11 -0700 Subject: [PATCH 18/22] remove `validate_only` field, add ignore read feature to `annotations` field --- .../products/cloudquotas/QuotaPreference.yaml | 12 +----- .../cloudquotas_quota_preference.go.erb | 3 -- ...quotas_quota_preference_annotations.go.erb | 4 ++ ...urce_cloud_quotas_quota_preference_test.go | 42 ++++++++----------- 4 files changed, 23 insertions(+), 38 deletions(-) delete mode 100644 mmv1/templates/terraform/constants/cloudquotas_quota_preference.go.erb create mode 100644 mmv1/templates/terraform/custom_flatten/cloudquotas_quota_preference_annotations.go.erb diff --git a/mmv1/products/cloudquotas/QuotaPreference.yaml b/mmv1/products/cloudquotas/QuotaPreference.yaml index d0998a39a0b8..9ac2a049bc54 100644 --- a/mmv1/products/cloudquotas/QuotaPreference.yaml +++ b/mmv1/products/cloudquotas/QuotaPreference.yaml @@ -22,15 +22,13 @@ references: !ruby/object:Api::Resource::ReferenceLinks base_url: '{{parent}}/locations/global/quotaPreferences' self_link: '{{parent}}/locations/global/quotaPreferences/{{name}}' create_url: '{{parent}}/locations/global/quotaPreferences?quotaPreferenceId={{name}}&ignoreSafetyChecks={{ignore_safety_checks}}' -update_url: '{{parent}}/locations/global/quotaPreferences/{{name}}?validateOnly={{validate_only}}&ignoreSafetyChecks={{ignore_safety_checks}}' +update_url: '{{parent}}/locations/global/quotaPreferences/{{name}}?ignoreSafetyChecks={{ignore_safety_checks}}' update_verb: :PATCH update_mask: true skip_delete: true autogen_async: false import_format: ['{{%parent}}/locations/global/quotaPreferences/{{name}}'] id_format: '{{parent}}/locations/global/quotaPreferences/{{name}}' -custom_code: !ruby/object:Provider::Terraform::CustomCode - constants: templates/terraform/constants/cloudquotas_quota_preference.go.erb examples: - !ruby/object:Provider::Terraform::Examples @@ -50,12 +48,6 @@ parameters: required: true default_from_api: true description: The parent of the quota preference. Allowed parents are "projects/[project-id / number]" or "folders/[folder-id / number]" or "organizations/[org-id / number]". - - !ruby/object:Api::Type::Boolean - name: 'validate_only' - url_param_only: true - default_value: false - description: | - If set to true, validate the request, but do not actually update. Note that a request being valid does not mean that the request is guaranteed to be fulfilled. - !ruby/object:Api::Type::Enum name: 'ignore_safety_checks' url_param_only: true @@ -113,7 +105,7 @@ properties: The trace id that the Google Cloud uses to provision the requested quota. This trace id may be used by the client to contact Cloud support to track the state of a quota preference request. The trace id is only produced for increase requests and is unique for each request. The quota decrease requests do not have a trace id. - !ruby/object:Api::Type::KeyValuePairs name: 'annotations' - diff_suppress_func: QuotaConfigAnnotationsDiffSuppress + custom_flatten: 'templates/terraform/custom_flatten/cloudquotas_quota_preference_annotations.go.erb' description: |- The annotations map for clients to store small amounts of arbitrary data. Do not put PII or other sensitive information here. See https://google.aip.dev/128#annotations. diff --git a/mmv1/templates/terraform/constants/cloudquotas_quota_preference.go.erb b/mmv1/templates/terraform/constants/cloudquotas_quota_preference.go.erb deleted file mode 100644 index 31dcd3069703..000000000000 --- a/mmv1/templates/terraform/constants/cloudquotas_quota_preference.go.erb +++ /dev/null @@ -1,3 +0,0 @@ -func QuotaConfigAnnotationsDiffSuppress(k, old, new string, d *schema.ResourceData) bool { - return true -} \ No newline at end of file diff --git a/mmv1/templates/terraform/custom_flatten/cloudquotas_quota_preference_annotations.go.erb b/mmv1/templates/terraform/custom_flatten/cloudquotas_quota_preference_annotations.go.erb new file mode 100644 index 000000000000..6ace95aae077 --- /dev/null +++ b/mmv1/templates/terraform/custom_flatten/cloudquotas_quota_preference_annotations.go.erb @@ -0,0 +1,4 @@ +func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + // ignore read on this field + return d.Get("quota_config.0.annotations") +} \ No newline at end of file diff --git a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go index 9fcde020bd13..f1315d19eab2 100644 --- a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go +++ b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go @@ -32,7 +32,7 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up ResourceName: "google_cloud_quotas_quota_preference.my_preference", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "validate_only", "ignore_safety_checks", "contact_email"}, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "ignore_safety_checks", "contact_email"}, }, { Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_increaseQuota(context), @@ -41,7 +41,7 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up ResourceName: "google_cloud_quotas_quota_preference.my_preference", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "validate_only", "ignore_safety_checks", "contact_email", "justification", "quota_config.0.annotations"}, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "ignore_safety_checks", "contact_email", "justification", "quota_config.0.annotation"}, }, { Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_decreaseQuota(context), @@ -50,7 +50,7 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up ResourceName: "google_cloud_quotas_quota_preference.my_preference", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "validate_only", "ignore_safety_checks", "contact_email", "justification"}, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "ignore_safety_checks", "contact_email"}, }, }, }) @@ -83,8 +83,8 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_ba depends_on = [google_project.new_project] } - resource "time_sleep" "wait_180_seconds" { - create_duration = "180s" + resource "time_sleep" "wait_120_seconds" { + create_duration = "120s" depends_on = [ google_project_service.cloudquotas, google_project_service.compute, @@ -103,8 +103,8 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_ba preferred_value = 70 } ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" - depends_on = [ - time_sleep.wait_180_seconds + depends_on = [ + time_sleep.wait_120_seconds ] } `, context) @@ -136,15 +136,6 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_in service = "cloudbilling.googleapis.com" depends_on = [google_project.new_project] } - - resource "time_sleep" "wait_180_seconds" { - create_duration = "180s" - depends_on = [ - google_project_service.cloudquotas, - google_project_service.compute, - google_project_service.billing, - ] - } resource "google_cloud_quotas_quota_preference" "my_preference"{ contact_email = "testinguser2@google.com" @@ -153,6 +144,11 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_in preferred_value = 72 annotations = { label = "terraform" } } + depends_on = [ + google_project_service.cloudquotas, + google_project_service.compute, + google_project_service.billing, + ] } `, context) } @@ -183,21 +179,17 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_de service = "cloudbilling.googleapis.com" depends_on = [google_project.new_project] } - - resource "time_sleep" "wait_180_seconds" { - create_duration = "180s" - depends_on = [ - google_project_service.cloudquotas, - google_project_service.compute, - google_project_service.billing, - ] - } resource "google_cloud_quotas_quota_preference" "my_preference"{ ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" quota_config { preferred_value = 65 } + depends_on = [ + google_project_service.cloudquotas, + google_project_service.compute, + google_project_service.billing, + ] } `, context) } From a011c53d337ca4258065b1686f9ca93dd33ec9ce Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Mon, 18 Mar 2024 22:08:06 -0700 Subject: [PATCH 19/22] add input only fields to ImportStateVerifyIgnore --- .../cloudquotas/resource_cloud_quotas_quota_preference_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go index f1315d19eab2..2cc1a9dbd135 100644 --- a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go +++ b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go @@ -50,7 +50,7 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up ResourceName: "google_cloud_quotas_quota_preference.my_preference", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "ignore_safety_checks", "contact_email"}, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "ignore_safety_checks", "contact_email", "justification", "quota_config.0.annotation"}, }, }, }) From 760d6017dab2240f1033562e4cda762f9a37d8c6 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Mon, 18 Mar 2024 22:18:59 -0700 Subject: [PATCH 20/22] update field name --- .../resource_cloud_quotas_quota_preference_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go index 2cc1a9dbd135..185b77cb491d 100644 --- a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go +++ b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go @@ -41,7 +41,7 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up ResourceName: "google_cloud_quotas_quota_preference.my_preference", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "ignore_safety_checks", "contact_email", "justification", "quota_config.0.annotation"}, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "ignore_safety_checks", "contact_email", "justification", "quota_config.0.annotations"}, }, { Config: testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_decreaseQuota(context), @@ -50,7 +50,7 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up ResourceName: "google_cloud_quotas_quota_preference.my_preference", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "ignore_safety_checks", "contact_email", "justification", "quota_config.0.annotation"}, + ImportStateVerifyIgnore: []string{"parent", "quota_preference_id", "ignore_safety_checks", "contact_email", "justification", "quota_config.0.annotations"}, }, }, }) From 82b92419580fa8e275d6b8143bf8fbe62f32b75d Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Wed, 20 Mar 2024 10:29:34 -0700 Subject: [PATCH 21/22] VCR test failure: remove batch service creation --- ...urce_cloud_quotas_quota_preference_test.go | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go index 185b77cb491d..4bf2b25794eb 100644 --- a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go +++ b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go @@ -68,28 +68,23 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_ba resource "google_project_service" "cloudquotas" { project = google_project.new_project.project_id service = "cloudquotas.googleapis.com" - depends_on = [google_project.new_project] } resource "google_project_service" "compute" { project = google_project.new_project.project_id service = "compute.googleapis.com" - depends_on = [google_project.new_project] + depends_on = [google_project_service.cloudquotas] } resource "google_project_service" "billing" { project = google_project.new_project.project_id service = "cloudbilling.googleapis.com" - depends_on = [google_project.new_project] + depends_on = [google_project_service.compute] } resource "time_sleep" "wait_120_seconds" { create_duration = "120s" - depends_on = [ - google_project_service.cloudquotas, - google_project_service.compute, - google_project_service.billing, - ] + depends_on = [google_project_service.billing] } resource "google_cloud_quotas_quota_preference" "my_preference"{ @@ -122,19 +117,18 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_in resource "google_project_service" "cloudquotas" { project = google_project.new_project.project_id service = "cloudquotas.googleapis.com" - depends_on = [google_project.new_project] } resource "google_project_service" "compute" { project = google_project.new_project.project_id service = "compute.googleapis.com" - depends_on = [google_project.new_project] + depends_on = [google_project_service.cloudquotas] } resource "google_project_service" "billing" { project = google_project.new_project.project_id service = "cloudbilling.googleapis.com" - depends_on = [google_project.new_project] + depends_on = [google_project_service.compute] } resource "google_cloud_quotas_quota_preference" "my_preference"{ @@ -144,11 +138,7 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_in preferred_value = 72 annotations = { label = "terraform" } } - depends_on = [ - google_project_service.cloudquotas, - google_project_service.compute, - google_project_service.billing, - ] + depends_on = [google_project_service.billing] } `, context) } @@ -165,19 +155,18 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_de resource "google_project_service" "cloudquotas" { project = google_project.new_project.project_id service = "cloudquotas.googleapis.com" - depends_on = [google_project.new_project] } resource "google_project_service" "compute" { project = google_project.new_project.project_id service = "compute.googleapis.com" - depends_on = [google_project.new_project] + depends_on = [google_project_service.cloudquotas] } resource "google_project_service" "billing" { project = google_project.new_project.project_id service = "cloudbilling.googleapis.com" - depends_on = [google_project.new_project] + depends_on = [google_project_service.compute] } resource "google_cloud_quotas_quota_preference" "my_preference"{ @@ -185,11 +174,7 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_de quota_config { preferred_value = 65 } - depends_on = [ - google_project_service.cloudquotas, - google_project_service.compute, - google_project_service.billing, - ] + depends_on = [google_project_service.billing] } `, context) } From 4ba069b133e76f601c766b4d849bb769d1442425 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Wed, 20 Mar 2024 10:34:41 -0700 Subject: [PATCH 22/22] fix formatting --- ...urce_cloud_quotas_quota_preference_test.go | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go index 4bf2b25794eb..35ea4107eae9 100644 --- a/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go +++ b/mmv1/third_party/terraform/services/cloudquotas/resource_cloud_quotas_quota_preference_test.go @@ -59,10 +59,10 @@ func TestAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_up func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_basic(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_project" "new_project" { - project_id = "tf-test%{random_suffix}" - name = "tf-test%{random_suffix}" - org_id = "%{org_id}" - billing_account = "%{billing_account}" + project_id = "tf-test%{random_suffix}" + name = "tf-test%{random_suffix}" + org_id = "%{org_id}" + billing_account = "%{billing_account}" } resource "google_project_service" "cloudquotas" { @@ -88,17 +88,17 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_ba } resource "google_cloud_quotas_quota_preference" "my_preference"{ - parent = "projects/${google_project.new_project.project_id}" - name = "compute_googleapis_com-CPUS-per-project_us-central1" - dimensions = { region = "us-central1" } - service = "compute.googleapis.com" - quota_id = "CPUS-per-project-region" - contact_email = "testuser@gmail.com" + parent = "projects/${google_project.new_project.project_id}" + name = "compute_googleapis_com-CPUS-per-project_us-central1" + dimensions = { region = "us-central1" } + service = "compute.googleapis.com" + quota_id = "CPUS-per-project-region" + contact_email = "testuser@gmail.com" quota_config { - preferred_value = 70 + preferred_value = 70 } - ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" - depends_on = [ + ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" + depends_on = [ time_sleep.wait_120_seconds ] } @@ -108,10 +108,10 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_ba func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_increaseQuota(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_project" "new_project" { - project_id = "tf-test%{random_suffix}" - name = "tf-test%{random_suffix}" - org_id = "%{org_id}" - billing_account = "%{billing_account}" + project_id = "tf-test%{random_suffix}" + name = "tf-test%{random_suffix}" + org_id = "%{org_id}" + billing_account = "%{billing_account}" } resource "google_project_service" "cloudquotas" { @@ -132,13 +132,13 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_in } resource "google_cloud_quotas_quota_preference" "my_preference"{ - contact_email = "testinguser2@google.com" - justification = "Ignore. Increase quota for Terraform testing." + contact_email = "testinguser2@google.com" + justification = "Ignore. Increase quota for Terraform testing." quota_config { preferred_value = 72 - annotations = { label = "terraform" } + annotations = { label = "terraform" } } - depends_on = [google_project_service.billing] + depends_on = [google_project_service.billing] } `, context) } @@ -146,10 +146,10 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_in func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_decreaseQuota(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_project" "new_project" { - project_id = "tf-test%{random_suffix}" - name = "tf-test%{random_suffix}" - org_id = "%{org_id}" - billing_account = "%{billing_account}" + project_id = "tf-test%{random_suffix}" + name = "tf-test%{random_suffix}" + org_id = "%{org_id}" + billing_account = "%{billing_account}" } resource "google_project_service" "cloudquotas" { @@ -170,11 +170,11 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_de } resource "google_cloud_quotas_quota_preference" "my_preference"{ - ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" + ignore_safety_checks = "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH" quota_config { - preferred_value = 65 + preferred_value = 65 } - depends_on = [google_project_service.billing] + depends_on = [google_project_service.billing] } `, context) }