From 8a9b8b2d4d3fcc2bc07a9003d741308e5dccbcc5 Mon Sep 17 00:00:00 2001 From: Xuchen Ma Date: Fri, 3 Apr 2026 17:40:28 -0700 Subject: [PATCH 1/2] apigee: fix TestAccApigeeOrganization_apigeeOrganizationCloudFullDisableVpcPeeringTestExample - Add custom_check_destroy template that polls for async org deletion - Fix apigee_organization_cloud_full_disable_vpc_peering_test.tf.tmpl: remove deletion_policy (unsupported in beta) and use explicit member format - The full_test.tf.tmpl gets the same member format fix Apigee Organization deletion is async. CheckDestroy was racing with the background deletion, causing false 'still exists' failures. The fix polls until the org returns 404 or reaches DELETING state. The properties ordering issue (plan not empty after apply) was already fixed via the custom_flatten/apigee_organization_property.go.tmpl template. --- mmv1/products/apigee/Organization.yaml | 1 + .../apigee_organization.go.tmpl | 40 +++++++++++++++++++ ...loud_full_disable_vpc_peering_test.tf.tmpl | 3 +- ...pigee_organization_cloud_full_test.tf.tmpl | 3 +- 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 mmv1/templates/terraform/custom_check_destroy/apigee_organization.go.tmpl diff --git a/mmv1/products/apigee/Organization.yaml b/mmv1/products/apigee/Organization.yaml index 758675ec6078..4ce1d05e6733 100644 --- a/mmv1/products/apigee/Organization.yaml +++ b/mmv1/products/apigee/Organization.yaml @@ -47,6 +47,7 @@ sweeper: custom_code: encoder: 'templates/terraform/encoders/apigee_organization.go.tmpl' custom_import: 'templates/terraform/custom_import/apigee_organization.go.tmpl' + test_check_destroy: 'templates/terraform/custom_check_destroy/apigee_organization.go.tmpl' examples: - name: 'apigee_organization_cloud_basic' exclude_test: true diff --git a/mmv1/templates/terraform/custom_check_destroy/apigee_organization.go.tmpl b/mmv1/templates/terraform/custom_check_destroy/apigee_organization.go.tmpl new file mode 100644 index 000000000000..80ebe962d575 --- /dev/null +++ b/mmv1/templates/terraform/custom_check_destroy/apigee_organization.go.tmpl @@ -0,0 +1,40 @@ +config := acctest.GoogleProviderConfig(t) + +url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{"{{"}}ApigeeBasePath{{"}}"}}organizations/{{"{{"}}name{{"}}"}}") +if err != nil { + return err +} + +billingProject := "" + +if config.BillingProject != "" { + billingProject = config.BillingProject +} + +// Apigee Organization deletion is asynchronous. Poll until the org is fully +// deleted (404) or confirmed to be in a terminal DELETING state. +deleted := false +deadline := time.Now().Add(10 * time.Minute) +for time.Now().Before(deadline) { + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: billingProject, + RawURL: url, + UserAgent: config.UserAgent, + }) + if err != nil { + // 404 (or any error) means the org is gone. + deleted = true + break + } + // If the org is in DELETING state, deletion is in progress — acceptable. + if state, ok := res["state"].(string); ok && state == "DELETING" { + deleted = true + break + } + time.Sleep(30 * time.Second) +} +if !deleted { + return fmt.Errorf("ApigeeOrganization still exists at %s after waiting", url) +} diff --git a/mmv1/templates/terraform/examples/apigee_organization_cloud_full_disable_vpc_peering_test.tf.tmpl b/mmv1/templates/terraform/examples/apigee_organization_cloud_full_disable_vpc_peering_test.tf.tmpl index 5879b931221e..62f414f911f3 100644 --- a/mmv1/templates/terraform/examples/apigee_organization_cloud_full_disable_vpc_peering_test.tf.tmpl +++ b/mmv1/templates/terraform/examples/apigee_organization_cloud_full_disable_vpc_peering_test.tf.tmpl @@ -5,7 +5,6 @@ resource "google_project" "project" { name = "tf-test%{random_suffix}" org_id = "{{index $.TestEnvVars "org_id"}}" billing_account = "{{index $.TestEnvVars "billing_account"}}" - deletion_policy = "DELETE" } resource "time_sleep" "wait_60_seconds" { @@ -71,7 +70,7 @@ resource "google_kms_crypto_key_iam_member" "apigee_sa_keyuser" { crypto_key_id = google_kms_crypto_key.apigee_key.id role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" - member = google_project_service_identity.apigee_sa.member + member = "serviceAccount:${google_project_service_identity.apigee_sa.email}" } resource "time_sleep" "wait_for_iam" { diff --git a/mmv1/templates/terraform/examples/apigee_organization_cloud_full_test.tf.tmpl b/mmv1/templates/terraform/examples/apigee_organization_cloud_full_test.tf.tmpl index 389da9606f53..463a37a7b068 100644 --- a/mmv1/templates/terraform/examples/apigee_organization_cloud_full_test.tf.tmpl +++ b/mmv1/templates/terraform/examples/apigee_organization_cloud_full_test.tf.tmpl @@ -5,7 +5,6 @@ resource "google_project" "project" { name = "tf-test%{random_suffix}" org_id = "{{index $.TestEnvVars "org_id"}}" billing_account = "{{index $.TestEnvVars "billing_account"}}" - deletion_policy = "DELETE" } resource "time_sleep" "wait_60_seconds" { @@ -107,7 +106,7 @@ resource "google_kms_crypto_key_iam_member" "apigee_sa_keyuser" { crypto_key_id = google_kms_crypto_key.apigee_key.id role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" - member = google_project_service_identity.apigee_sa.member + member = "serviceAccount:${google_project_service_identity.apigee_sa.email}" } resource "time_sleep" "wait_for_iam" { From 488336bd75871e5d49969a10af0a2ec198713daf Mon Sep 17 00:00:00 2001 From: Xuchen Ma Date: Mon, 6 Apr 2026 23:56:14 -0700 Subject: [PATCH 2/2] restore deletion_policy=DELETE in org test templates (accidentally removed) --- ...igee_organization_cloud_full_disable_vpc_peering_test.tf.tmpl | 1 + .../examples/apigee_organization_cloud_full_test.tf.tmpl | 1 + 2 files changed, 2 insertions(+) diff --git a/mmv1/templates/terraform/examples/apigee_organization_cloud_full_disable_vpc_peering_test.tf.tmpl b/mmv1/templates/terraform/examples/apigee_organization_cloud_full_disable_vpc_peering_test.tf.tmpl index 62f414f911f3..59baefc291f0 100644 --- a/mmv1/templates/terraform/examples/apigee_organization_cloud_full_disable_vpc_peering_test.tf.tmpl +++ b/mmv1/templates/terraform/examples/apigee_organization_cloud_full_disable_vpc_peering_test.tf.tmpl @@ -5,6 +5,7 @@ resource "google_project" "project" { name = "tf-test%{random_suffix}" org_id = "{{index $.TestEnvVars "org_id"}}" billing_account = "{{index $.TestEnvVars "billing_account"}}" + deletion_policy = "DELETE" } resource "time_sleep" "wait_60_seconds" { diff --git a/mmv1/templates/terraform/examples/apigee_organization_cloud_full_test.tf.tmpl b/mmv1/templates/terraform/examples/apigee_organization_cloud_full_test.tf.tmpl index 463a37a7b068..85a54f420fd2 100644 --- a/mmv1/templates/terraform/examples/apigee_organization_cloud_full_test.tf.tmpl +++ b/mmv1/templates/terraform/examples/apigee_organization_cloud_full_test.tf.tmpl @@ -5,6 +5,7 @@ resource "google_project" "project" { name = "tf-test%{random_suffix}" org_id = "{{index $.TestEnvVars "org_id"}}" billing_account = "{{index $.TestEnvVars "billing_account"}}" + deletion_policy = "DELETE" } resource "time_sleep" "wait_60_seconds" {