Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing name field on google_compute_disk for TestAccComputeInstanceTemplate_sourceSnapshotEncryptionKey to include randomly generated string #13986

Merged
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
Changing name field on google_compute_disk for TestAccComputeInstance…
…Template_sourceSnapshotEncryptionKey to include randomly generated string (#7392)

* Changed name within google_compute_disk  on line 3162 to inclue and randomly generated string

* Cleaned up arguments being passed in to be more inline with other tests

* Updated based on addtional PR comments

* Fixed swapping of values within new context

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Mar 14, 2023
commit f67afbec4381a6bd23df020849b20125fadecab2
3 changes: 3 additions & 0 deletions .changelog/7392.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
Changing name field on google_compute_disk for TestAccComputeInstanceTemplate_sourceSnapshotEncryptionKey to include randomly generated string
```
50 changes: 29 additions & 21 deletions google/resource_compute_instance_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,16 +1138,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{}{
"kms_ring_name": GetResourceNameFromSelfLink(kmsKey.KeyRing.Name),
"kms_key_name": GetResourceNameFromSelfLink(kmsKey.CryptoKey.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 @@ -1168,16 +1172,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{}{
"kms_ring_name": GetResourceNameFromSelfLink(kmsKey.KeyRing.Name),
"kms_key_name": GetResourceNameFromSelfLink(kmsKey.CryptoKey.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 @@ -3013,20 +3021,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 = "tf-test-sa-%{random_suffix}"
display_name = "KMS Ops Account"
}

Expand All @@ -3042,7 +3050,7 @@ data "google_compute_image" "debian" {
}

resource "google_compute_disk" "persistent" {
name = "debian-disk"
name = "tf-test-debian-disk-%{random_suffix}"
image = data.google_compute_image.debian.self_link
size = 10
type = "pd-ssd"
Expand All @@ -3060,7 +3068,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 {
Expand All @@ -3077,23 +3085,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"
}

Expand All @@ -3119,7 +3127,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 {
Expand All @@ -3136,5 +3144,5 @@ resource "google_compute_instance_template" "template" {
network = "default"
}
}
`, kmsRingName, kmsKeyName, suffix, suffix)
`, context)
}