From a94cf68c8373dc2dd201a7050c471f0663baaeae Mon Sep 17 00:00:00 2001 From: Andrew Garcia-Corley Date: Fri, 3 Mar 2023 15:18:01 -0700 Subject: [PATCH] Cleaned up arguments being passed in to be more inline with other tests --- ...urce_compute_instance_template_test.go.erb | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 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..2a795cad9568 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,12 @@ 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{}{ + "kmsRingName": GetResourceNameFromSelfLink(kmsKey.CryptoKey.Name), + "kmsKeyName": GetResourceNameFromSelfLink(kmsKey.KeyRing.Name), + "random_suffix": randString(t, 10), + } vcrTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -1214,7 +1218,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 +1239,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{}{ + "kmsRingName": GetResourceNameFromSelfLink(kmsKey.CryptoKey.Name), + "kmsKeyName": GetResourceNameFromSelfLink(kmsKey.KeyRing.Name), + "random_suffix": randString(t, 10), + } vcrTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -1244,7 +1252,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,8 +3135,9 @@ 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 { + # kmsRingName, kmsKeyName, suffix string + return Nprintf(` data "google_kms_key_ring" "ring" { name = "%s" location = "us-central1" @@ -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" @@ -3191,11 +3200,11 @@ 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" location = "us-central1" @@ -3250,5 +3259,5 @@ resource "google_compute_instance_template" "template" { network = "default" } } -`, kmsRingName, kmsKeyName, suffix, suffix) +`, context) }