Skip to content

Commit

Permalink
remove allow-missing flag & fix update test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
lola98 committed Mar 11, 2024
1 parent 13d04ae commit c1ac0f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 121 deletions.
11 changes: 2 additions & 9 deletions mmv1/products/cloudquotas/QuotaPreference.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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"},
},
},
})
Expand All @@ -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:[email protected]"
]
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" {
Expand All @@ -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)
}
Expand All @@ -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:[email protected]"
]
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" {
Expand All @@ -169,7 +145,6 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_in
}
resource "google_cloud_quotas_quota_preference" "my_preference"{
dimensions = { region = "us-central1" }
contact_email = "[email protected]"
justification = "Ignore. Increase quota for Terraform testing."
quota_config {
Expand All @@ -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:[email protected]"
]
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" {
Expand All @@ -224,69 +190,10 @@ func testAccCloudQuotasQuotaPreference_cloudquotasQuotaPreferenceBasicExample_de
}
resource "google_cloud_quotas_quota_preference" "my_preference"{
dimensions = { region = "us-central1" }
contact_email = "[email protected]"
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:[email protected]"
]
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 = "[email protected]"
quota_config {
preferred_value = 15
}
allow_missing = true
}
`, context)
}

0 comments on commit c1ac0f2

Please sign in to comment.