From 2961a73958d7e7aef5f190494cfb20aa9207cd64 Mon Sep 17 00:00:00 2001 From: Andrew Garcia-Corley Date: Thu, 2 Mar 2023 14:37:30 -0700 Subject: [PATCH 1/4] Changed name within google_compute_disk on line 3162 to inclue and randomly generated string --- .../tests/resource_compute_instance_template_test.go.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb b/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb index 7099d4641eeb..d4094fcbc943 100644 --- a/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb @@ -3156,7 +3156,7 @@ data "google_compute_image" "debian" { } resource "google_compute_disk" "persistent" { - name = "debian-disk" + name = "tf-test-debian-disk-%{suffix}" image = data.google_compute_image.debian.self_link size = 10 type = "pd-ssd" From e669d6ed010880310c2210ae5060aa3c027fca9d Mon Sep 17 00:00:00 2001 From: Andrew Garcia-Corley Date: Fri, 3 Mar 2023 15:18:01 -0700 Subject: [PATCH 2/4] Cleaned up arguments being passed in to be more inline with other tests --- ...urce_compute_instance_template_test.go.erb | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb b/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb index d4094fcbc943..f6c5eb183b0b 100644 --- a/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb @@ -1205,8 +1205,13 @@ func TestAccComputeInstanceTemplate_sourceSnapshotEncryptionKey(t *testing.T) { var instanceTemplate compute.InstanceTemplate kmsKey := BootstrapKMSKeyInLocation(t, "us-central1") - kmsKeyName := GetResourceNameFromSelfLink(kmsKey.CryptoKey.Name) - kmsRingName := GetResourceNameFromSelfLink(kmsKey.KeyRing.Name) + + context := map[string]interface{}{ + "kms_ring_name": GetResourceNameFromSelfLink(kmsKey.CryptoKey.Name), + "kms_key_name": GetResourceNameFromSelfLink(kmsKey.KeyRing.Name), + "random_suffix": randString(t, 10), + } + vcrTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -1214,7 +1219,7 @@ func TestAccComputeInstanceTemplate_sourceSnapshotEncryptionKey(t *testing.T) { CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccComputeInstanceTemplate_sourceSnapshotEncryptionKey(kmsRingName, kmsKeyName, randString(t, 10)), + Config: testAccComputeInstanceTemplate_sourceSnapshotEncryptionKey(context), Check: resource.ComposeTestCheckFunc( testAccCheckComputeInstanceTemplateExists( t, "google_compute_instance_template.template", &instanceTemplate), @@ -1235,8 +1240,12 @@ func TestAccComputeInstanceTemplate_sourceImageEncryptionKey(t *testing.T) { var instanceTemplate compute.InstanceTemplate kmsKey := BootstrapKMSKeyInLocation(t, "us-central1") - kmsKeyName := GetResourceNameFromSelfLink(kmsKey.CryptoKey.Name) - kmsRingName := GetResourceNameFromSelfLink(kmsKey.KeyRing.Name) + + context := map[string]interface{}{ + "kms_ring_name": GetResourceNameFromSelfLink(kmsKey.CryptoKey.Name), + "kms_key_name": GetResourceNameFromSelfLink(kmsKey.KeyRing.Name), + "random_suffix": randString(t, 10), + } vcrTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -1244,7 +1253,7 @@ func TestAccComputeInstanceTemplate_sourceImageEncryptionKey(t *testing.T) { CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccComputeInstanceTemplate_sourceImageEncryptionKey(kmsRingName, kmsKeyName, randString(t, 10)), + Config: testAccComputeInstanceTemplate_sourceImageEncryptionKey(context), Check: resource.ComposeTestCheckFunc( testAccCheckComputeInstanceTemplateExists( t, "google_compute_instance_template.template", &instanceTemplate), @@ -3127,20 +3136,20 @@ resource "google_compute_instance_template" "foobar" { `, suffix) } -func testAccComputeInstanceTemplate_sourceSnapshotEncryptionKey(kmsRingName, kmsKeyName, suffix string) string { - return fmt.Sprintf(` +func testAccComputeInstanceTemplate_sourceSnapshotEncryptionKey(context map[string]interface{}) string { + return Nprintf(` data "google_kms_key_ring" "ring" { - name = "%s" + name = "%{kms_ring_name}" location = "us-central1" } data "google_kms_crypto_key" "key" { - name = "%s" + name = "%{kms_key_name}" key_ring = data.google_kms_key_ring.ring.id } resource "google_service_account" "test" { - account_id = "test-sa-%s" + account_id = "test-sa-%{random_suffix}" display_name = "KMS Ops Account" } @@ -3156,7 +3165,7 @@ data "google_compute_image" "debian" { } resource "google_compute_disk" "persistent" { - name = "tf-test-debian-disk-%{suffix}" + name = "tf-test-debian-disk-%{random_suffix}" image = data.google_compute_image.debian.self_link size = 10 type = "pd-ssd" @@ -3174,7 +3183,7 @@ resource "google_compute_snapshot" "snapshot" { } resource "google_compute_instance_template" "template" { - name = "tf-test-instance-template-%s" + name = "tf-test-instance-template-%{random_suffix}" machine_type = "e2-medium" disk { @@ -3191,23 +3200,23 @@ resource "google_compute_instance_template" "template" { network = "default" } } -`, kmsRingName, kmsKeyName, suffix, suffix) +`, context) } -func testAccComputeInstanceTemplate_sourceImageEncryptionKey(kmsRingName, kmsKeyName, suffix string) string { - return fmt.Sprintf(` +func testAccComputeInstanceTemplate_sourceImageEncryptionKey(context map[string]interface{}) string { + return Nprintf(` data "google_kms_key_ring" "ring" { - name = "%s" + name = "%{kms_ring_name}" location = "us-central1" } data "google_kms_crypto_key" "key" { - name = "%s" + name = "%{kms_key_name}" key_ring = data.google_kms_key_ring.ring.id } resource "google_service_account" "test" { - account_id = "tf-test-sa-%s" + account_id = "tf-test-sa-%{random_suffix}" display_name = "KMS Ops Account" } @@ -3233,7 +3242,7 @@ resource "google_compute_image" "image" { resource "google_compute_instance_template" "template" { - name = "tf-test-instance-template-%s" + name = "tf-test-instance-template-%{random_suffix}" machine_type = "e2-medium" disk { @@ -3250,5 +3259,5 @@ resource "google_compute_instance_template" "template" { network = "default" } } -`, kmsRingName, kmsKeyName, suffix, suffix) +`, context) } From 3fbdedb37d6f35444b87516f56ba617edeb1de20 Mon Sep 17 00:00:00 2001 From: Andrew Garcia-Corley Date: Mon, 6 Mar 2023 14:28:50 -0700 Subject: [PATCH 3/4] Updated based on addtional PR comments --- .../tests/resource_compute_instance_template_test.go.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb b/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb index ac984a648563..3f2aeee7208a 100644 --- a/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb @@ -1209,7 +1209,7 @@ func TestAccComputeInstanceTemplate_sourceSnapshotEncryptionKey(t *testing.T) { context := map[string]interface{}{ "kms_ring_name": GetResourceNameFromSelfLink(kmsKey.CryptoKey.Name), "kms_key_name": GetResourceNameFromSelfLink(kmsKey.KeyRing.Name), - "random_suffix": randString(t, 10), + "random_suffix": RandString(t, 10), } @@ -1244,7 +1244,7 @@ func TestAccComputeInstanceTemplate_sourceImageEncryptionKey(t *testing.T) { context := map[string]interface{}{ "kms_ring_name": GetResourceNameFromSelfLink(kmsKey.CryptoKey.Name), "kms_key_name": GetResourceNameFromSelfLink(kmsKey.KeyRing.Name), - "random_suffix": randString(t, 10), + "random_suffix": RandString(t, 10), } VcrTest(t, resource.TestCase{ @@ -3149,7 +3149,7 @@ data "google_kms_crypto_key" "key" { } resource "google_service_account" "test" { - account_id = "test-sa-%{random_suffix}" + account_id = "tf-test-sa-%{random_suffix}" display_name = "KMS Ops Account" } From 0503dfb59d40975db32384326017b655e0c627cd Mon Sep 17 00:00:00 2001 From: Andrew Garcia-Corley Date: Mon, 13 Mar 2023 11:02:54 -0600 Subject: [PATCH 4/4] Fixed swapping of values within new context --- .../tests/resource_compute_instance_template_test.go.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb b/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb index 3f2aeee7208a..72723161c772 100644 --- a/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_compute_instance_template_test.go.erb @@ -1207,8 +1207,8 @@ func TestAccComputeInstanceTemplate_sourceSnapshotEncryptionKey(t *testing.T) { kmsKey := BootstrapKMSKeyInLocation(t, "us-central1") context := map[string]interface{}{ - "kms_ring_name": GetResourceNameFromSelfLink(kmsKey.CryptoKey.Name), - "kms_key_name": GetResourceNameFromSelfLink(kmsKey.KeyRing.Name), + "kms_ring_name": GetResourceNameFromSelfLink(kmsKey.KeyRing.Name), + "kms_key_name": GetResourceNameFromSelfLink(kmsKey.CryptoKey.Name), "random_suffix": RandString(t, 10), } @@ -1242,8 +1242,8 @@ func TestAccComputeInstanceTemplate_sourceImageEncryptionKey(t *testing.T) { kmsKey := BootstrapKMSKeyInLocation(t, "us-central1") context := map[string]interface{}{ - "kms_ring_name": GetResourceNameFromSelfLink(kmsKey.CryptoKey.Name), - "kms_key_name": GetResourceNameFromSelfLink(kmsKey.KeyRing.Name), + "kms_ring_name": GetResourceNameFromSelfLink(kmsKey.KeyRing.Name), + "kms_key_name": GetResourceNameFromSelfLink(kmsKey.CryptoKey.Name), "random_suffix": RandString(t, 10), }