Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mmv1/products/apigee/Organization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How confident are we to accept any error from the API meaning that the org is gone? I'm not sure why we can't explicitly check for when the status response is a 404 have 100% confirmation of the apigee org not existing.

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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,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" {
Expand Down
Loading