From c1ac0f27d29f2fc5715dbc441e9370a183543119 Mon Sep 17 00:00:00 2001 From: Lola Liu Date: Mon, 11 Mar 2024 12:18:30 -0700 Subject: [PATCH] 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) -}