Skip to content

Commit

Permalink
Cleaned up arguments being passed in to be more inline with other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NA2047 committed Mar 3, 2023
1 parent 2961a73 commit a94cf68
Showing 1 changed file with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1205,16 +1205,20 @@ 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) },
Providers: testAccProviders,
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),
Expand All @@ -1235,16 +1239,20 @@ 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) },
Providers: testAccProviders,
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),
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -3250,5 +3259,5 @@ resource "google_compute_instance_template" "template" {
network = "default"
}
}
`, kmsRingName, kmsKeyName, suffix, suffix)
`, context)
}

0 comments on commit a94cf68

Please sign in to comment.