From 214f4d27d1defda5b608a60e82c208f2ccc9e910 Mon Sep 17 00:00:00 2001 From: Maksym Omelchenko Date: Fri, 22 Nov 2024 22:03:21 +0000 Subject: [PATCH 1/5] Remove ApigeeOrganization update operation logic. --- mmv1/products/apigee/Organization.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/products/apigee/Organization.yaml b/mmv1/products/apigee/Organization.yaml index 55db1fc16838..32096d648d58 100644 --- a/mmv1/products/apigee/Organization.yaml +++ b/mmv1/products/apigee/Organization.yaml @@ -30,7 +30,7 @@ timeouts: delete_minutes: 45 autogen_async: true async: - actions: ['create', 'delete', 'update'] + actions: ['create', 'delete'] type: 'OpAsync' operation: base_url: '{{op_id}}' From 0727b250a0ea1ef69ea217da08600984a9b135c3 Mon Sep 17 00:00:00 2001 From: Maksym Omelchenko Date: Tue, 7 Jan 2025 02:18:34 +0000 Subject: [PATCH 2/5] Add ApigeeOrganization update acceptance test. --- ...esource_apigee_organization_update_test.go | 313 ++++++++++++++++++ 1 file changed, 313 insertions(+) create mode 100644 mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go diff --git a/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go b/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go new file mode 100644 index 000000000000..25a92538cf1d --- /dev/null +++ b/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go @@ -0,0 +1,313 @@ +package apigee_test + +import ( + "maps" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + "github.com/hashicorp/terraform-plugin-testing/plancheck" + "github.com/hashicorp/terraform-provider-google/google/acctest" + "github.com/hashicorp/terraform-provider-google/google/envvar" +) + +func TestAccApigeeOrganization_update(t *testing.T) { + acctest.SkipIfVcr(t) + t.Parallel() + + default_context := map[string]interface{}{ + "billing_account": envvar.GetTestBillingAccountFromEnv(t), + "org_id": envvar.GetTestOrgFromEnv(t), + "random_suffix": acctest.RandString(t, 10), + } + update_context := maps.Clone(default_context) + update_context["org_description"] = "Updated Apigee Org description." + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccApigeeOrganization_full(default_context), + }, + { + ResourceName: "google_apigee_organization.org", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"project_id", "properties", "retention"}, + }, + { + Config: testAccApigeeOrganization_update(update_context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_apigee_organization.org", plancheck.ResourceActionUpdate), + }, + }, + }, + { + ResourceName: "google_apigee_organization.org", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"project_id", "properties", "retention"}, + }, + }, + }) +} + +func testAccApigeeOrganization_full(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_project" "project" { + provider = google + + project_id = "tf-test%{random_suffix}" + name = "tf-test%{random_suffix}" + org_id = "%{org_id}" + billing_account = "%{billing_account}" + deletion_policy = "DELETE" +} + +resource "google_project_service" "apigee" { + provider = google + + project = google_project.project.project_id + service = "apigee.googleapis.com" +} + +resource "google_project_service" "compute" { + provider = google + + project = google_project.project.project_id + service = "compute.googleapis.com" +} + +resource "google_project_service" "servicenetworking" { + provider = google + + project = google_project.project.project_id + service = "servicenetworking.googleapis.com" +} + +resource "google_project_service" "kms" { + provider = google + + project = google_project.project.project_id + service = "cloudkms.googleapis.com" +} + +resource "google_compute_network" "apigee_network" { + provider = google + + name = "apigee-network" + project = google_project.project.project_id + depends_on = [google_project_service.compute] +} + +resource "google_compute_global_address" "apigee_range" { + provider = google + + name = "apigee-range" + purpose = "VPC_PEERING" + address_type = "INTERNAL" + prefix_length = 16 + network = google_compute_network.apigee_network.id + project = google_project.project.project_id +} + +resource "google_service_networking_connection" "apigee_vpc_connection" { + provider = google + + network = google_compute_network.apigee_network.id + service = "servicenetworking.googleapis.com" + reserved_peering_ranges = [google_compute_global_address.apigee_range.name] + depends_on = [google_project_service.servicenetworking] +} + +resource "google_kms_key_ring" "apigee_keyring" { + provider = google + + name = "apigee-keyring" + location = "us-central1" + project = google_project.project.project_id + depends_on = [google_project_service.kms] +} + +resource "google_kms_crypto_key" "apigee_key" { + provider = google + + name = "apigee-key" + key_ring = google_kms_key_ring.apigee_keyring.id +} + +resource "google_project_service_identity" "apigee_sa" { + provider = google + + project = google_project.project.project_id + service = google_project_service.apigee.service +} + +resource "google_kms_crypto_key_iam_member" "apigee_sa_keyuser" { + provider = google + + crypto_key_id = google_kms_crypto_key.apigee_key.id + role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" + + member = google_project_service_identity.apigee_sa.member +} + +resource "google_apigee_organization" "org" { + provider = google + + display_name = "apigee-org" + description = "%{org_description}" + analytics_region = "us-central1" + project_id = google_project.project.project_id + authorized_network = google_compute_network.apigee_network.id + billing_type = "EVALUATION" + runtime_database_encryption_key_name = google_kms_crypto_key.apigee_key.id + properties { + property { + name = "features.hybrid.enabled" + value = "true" + } + property { + name = "features.mart.connect.enabled" + value = "true" + } + } + + depends_on = [ + google_service_networking_connection.apigee_vpc_connection, + google_kms_crypto_key_iam_member.apigee_sa_keyuser, + ] +} +`, context) +} + +func testAccApigeeOrganization_update(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_project" "project" { + provider = google + + project_id = "tf-test%{random_suffix}" + name = "tf-test%{random_suffix}" + org_id = "%{org_id}" + billing_account = "%{billing_account}" + deletion_policy = "DELETE" +} + +resource "google_project_service" "apigee" { + provider = google + + project = google_project.project.project_id + service = "apigee.googleapis.com" +} + +resource "google_project_service" "compute" { + provider = google + + project = google_project.project.project_id + service = "compute.googleapis.com" +} + +resource "google_project_service" "servicenetworking" { + provider = google + + project = google_project.project.project_id + service = "servicenetworking.googleapis.com" +} + +resource "google_project_service" "kms" { + provider = google + + project = google_project.project.project_id + service = "cloudkms.googleapis.com" +} + +resource "google_compute_network" "apigee_network" { + provider = google + + name = "apigee-network" + project = google_project.project.project_id + depends_on = [google_project_service.compute] +} + +resource "google_compute_global_address" "apigee_range" { + provider = google + + name = "apigee-range" + purpose = "VPC_PEERING" + address_type = "INTERNAL" + prefix_length = 16 + network = google_compute_network.apigee_network.id + project = google_project.project.project_id +} + +resource "google_service_networking_connection" "apigee_vpc_connection" { + provider = google + + network = google_compute_network.apigee_network.id + service = "servicenetworking.googleapis.com" + reserved_peering_ranges = [google_compute_global_address.apigee_range.name] + depends_on = [google_project_service.servicenetworking] +} + +resource "google_kms_key_ring" "apigee_keyring" { + provider = google + + name = "apigee-keyring" + location = "us-central1" + project = google_project.project.project_id + depends_on = [google_project_service.kms] +} + +resource "google_kms_crypto_key" "apigee_key" { + provider = google + + name = "apigee-key" + key_ring = google_kms_key_ring.apigee_keyring.id +} + +resource "google_project_service_identity" "apigee_sa" { + provider = google + + project = google_project.project.project_id + service = google_project_service.apigee.service +} + +resource "google_kms_crypto_key_iam_member" "apigee_sa_keyuser" { + provider = google + + crypto_key_id = google_kms_crypto_key.apigee_key.id + role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" + + member = google_project_service_identity.apigee_sa.member +} + +resource "google_apigee_organization" "org" { + provider = google + + display_name = "apigee-org" + description = "Terraform-managed Apigee Org" + analytics_region = "us-central1" + project_id = google_project.project.project_id + authorized_network = google_compute_network.apigee_network.id + billing_type = "EVALUATION" + runtime_database_encryption_key_name = google_kms_crypto_key.apigee_key.id + properties { + property { + name = "features.hybrid.enabled" + value = "true" + } + property { + name = "features.mart.connect.enabled" + value = "true" + } + } + + depends_on = [ + google_service_networking_connection.apigee_vpc_connection, + google_kms_crypto_key_iam_member.apigee_sa_keyuser, + ] +} +`, context) +} From c039fcb0a0874ab33cd50bb01ffb1790d8dedc40 Mon Sep 17 00:00:00 2001 From: Maksym Omelchenko Date: Tue, 7 Jan 2025 02:21:29 +0000 Subject: [PATCH 3/5] Update ApigeeOrganization update acceptance test. --- .../apigee/resource_apigee_organization_update_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go b/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go index 25a92538cf1d..594e725f01b4 100644 --- a/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go +++ b/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go @@ -158,7 +158,7 @@ resource "google_apigee_organization" "org" { provider = google display_name = "apigee-org" - description = "%{org_description}" + description = "Terraform-managed Apigee Org" analytics_region = "us-central1" project_id = google_project.project.project_id authorized_network = google_compute_network.apigee_network.id @@ -287,7 +287,7 @@ resource "google_apigee_organization" "org" { provider = google display_name = "apigee-org" - description = "Terraform-managed Apigee Org" + description = "%{org_description}" analytics_region = "us-central1" project_id = google_project.project.project_id authorized_network = google_compute_network.apigee_network.id From ed2a9ccea58519db631af96a0fa4bdd2f484464d Mon Sep 17 00:00:00 2001 From: Maksym Omelchenko Date: Tue, 7 Jan 2025 21:14:38 +0000 Subject: [PATCH 4/5] Fix resource definitions in ApigeeOrganization update acceptance test. --- ...esource_apigee_organization_update_test.go | 140 +++--------------- 1 file changed, 19 insertions(+), 121 deletions(-) diff --git a/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go b/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go index 594e725f01b4..2e6a4ce7e9e6 100644 --- a/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go +++ b/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go @@ -25,7 +25,7 @@ func TestAccApigeeOrganization_update(t *testing.T) { acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), Steps: []resource.TestStep{ { Config: testAccApigeeOrganization_full(default_context), @@ -87,13 +87,6 @@ resource "google_project_service" "servicenetworking" { service = "servicenetworking.googleapis.com" } -resource "google_project_service" "kms" { - provider = google - - project = google_project.project.project_id - service = "cloudkms.googleapis.com" -} - resource "google_compute_network" "apigee_network" { provider = google @@ -108,7 +101,7 @@ resource "google_compute_global_address" "apigee_range" { name = "apigee-range" purpose = "VPC_PEERING" address_type = "INTERNAL" - prefix_length = 16 + prefix_length = 21 network = google_compute_network.apigee_network.id project = google_project.project.project_id } @@ -122,62 +115,18 @@ resource "google_service_networking_connection" "apigee_vpc_connection" { depends_on = [google_project_service.servicenetworking] } -resource "google_kms_key_ring" "apigee_keyring" { +resource "google_apigee_organization" "apigee_org" { provider = google - name = "apigee-keyring" - location = "us-central1" - project = google_project.project.project_id - depends_on = [google_project_service.kms] -} - -resource "google_kms_crypto_key" "apigee_key" { - provider = google - - name = "apigee-key" - key_ring = google_kms_key_ring.apigee_keyring.id -} - -resource "google_project_service_identity" "apigee_sa" { - provider = google - - project = google_project.project.project_id - service = google_project_service.apigee.service -} - -resource "google_kms_crypto_key_iam_member" "apigee_sa_keyuser" { - provider = google - - crypto_key_id = google_kms_crypto_key.apigee_key.id - role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" - - member = google_project_service_identity.apigee_sa.member -} - -resource "google_apigee_organization" "org" { - provider = google - - display_name = "apigee-org" - description = "Terraform-managed Apigee Org" - analytics_region = "us-central1" - project_id = google_project.project.project_id - authorized_network = google_compute_network.apigee_network.id - billing_type = "EVALUATION" - runtime_database_encryption_key_name = google_kms_crypto_key.apigee_key.id - properties { - property { - name = "features.hybrid.enabled" - value = "true" - } - property { - name = "features.mart.connect.enabled" - value = "true" - } - } - + display_name = "apigee-org" + analytics_region = "us-central1" + description = "Terraform-managed Apigee Org" + project_id = google_project.project.project_id + authorized_network = google_compute_network.apigee_network.id + billing_type = "EVALUATION" depends_on = [ google_service_networking_connection.apigee_vpc_connection, - google_kms_crypto_key_iam_member.apigee_sa_keyuser, + google_project_service.apigee, ] } `, context) @@ -216,13 +165,6 @@ resource "google_project_service" "servicenetworking" { service = "servicenetworking.googleapis.com" } -resource "google_project_service" "kms" { - provider = google - - project = google_project.project.project_id - service = "cloudkms.googleapis.com" -} - resource "google_compute_network" "apigee_network" { provider = google @@ -237,7 +179,7 @@ resource "google_compute_global_address" "apigee_range" { name = "apigee-range" purpose = "VPC_PEERING" address_type = "INTERNAL" - prefix_length = 16 + prefix_length = 21 network = google_compute_network.apigee_network.id project = google_project.project.project_id } @@ -251,62 +193,18 @@ resource "google_service_networking_connection" "apigee_vpc_connection" { depends_on = [google_project_service.servicenetworking] } -resource "google_kms_key_ring" "apigee_keyring" { +resource "google_apigee_organization" "apigee_org" { provider = google - name = "apigee-keyring" - location = "us-central1" - project = google_project.project.project_id - depends_on = [google_project_service.kms] -} - -resource "google_kms_crypto_key" "apigee_key" { - provider = google - - name = "apigee-key" - key_ring = google_kms_key_ring.apigee_keyring.id -} - -resource "google_project_service_identity" "apigee_sa" { - provider = google - - project = google_project.project.project_id - service = google_project_service.apigee.service -} - -resource "google_kms_crypto_key_iam_member" "apigee_sa_keyuser" { - provider = google - - crypto_key_id = google_kms_crypto_key.apigee_key.id - role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" - - member = google_project_service_identity.apigee_sa.member -} - -resource "google_apigee_organization" "org" { - provider = google - - display_name = "apigee-org" - description = "%{org_description}" - analytics_region = "us-central1" - project_id = google_project.project.project_id - authorized_network = google_compute_network.apigee_network.id - billing_type = "EVALUATION" - runtime_database_encryption_key_name = google_kms_crypto_key.apigee_key.id - properties { - property { - name = "features.hybrid.enabled" - value = "true" - } - property { - name = "features.mart.connect.enabled" - value = "true" - } - } - + display_name = "apigee-org" + analytics_region = "us-central1" + description = "%{org_description}" + project_id = google_project.project.project_id + authorized_network = google_compute_network.apigee_network.id + billing_type = "EVALUATION" depends_on = [ google_service_networking_connection.apigee_vpc_connection, - google_kms_crypto_key_iam_member.apigee_sa_keyuser, + google_project_service.apigee, ] } `, context) From 7a7c7d7d68e2fa9f20b8e3470f09176f1f1d5634 Mon Sep 17 00:00:00 2001 From: Maksym Omelchenko Date: Wed, 8 Jan 2025 18:34:07 +0000 Subject: [PATCH 5/5] Fix org name in ApigeeOrganization update acceptance test. --- .../apigee/resource_apigee_organization_update_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go b/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go index 2e6a4ce7e9e6..cd89a7ea6d84 100644 --- a/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go +++ b/mmv1/third_party/terraform/services/apigee/resource_apigee_organization_update_test.go @@ -31,7 +31,7 @@ func TestAccApigeeOrganization_update(t *testing.T) { Config: testAccApigeeOrganization_full(default_context), }, { - ResourceName: "google_apigee_organization.org", + ResourceName: "google_apigee_organization.apigee_org", ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"project_id", "properties", "retention"}, @@ -40,12 +40,12 @@ func TestAccApigeeOrganization_update(t *testing.T) { Config: testAccApigeeOrganization_update(update_context), ConfigPlanChecks: resource.ConfigPlanChecks{ PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction("google_apigee_organization.org", plancheck.ResourceActionUpdate), + plancheck.ExpectResourceAction("google_apigee_organization.apigee_org", plancheck.ResourceActionUpdate), }, }, }, { - ResourceName: "google_apigee_organization.org", + ResourceName: "google_apigee_organization.apigee_org", ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"project_id", "properties", "retention"},