Skip to content

Commit

Permalink
Remove references to deleted compute images in multiple tests (#12062)
Browse files Browse the repository at this point in the history
  • Loading branch information
SirGitsalot authored Oct 24, 2024
1 parent b828c9b commit cdd8585
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 103 deletions.
3 changes: 3 additions & 0 deletions mmv1/products/compute/Image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ examples:
primary_resource_id: 'example'
primary_resource_name: 'fmt.Sprintf("tf-test-example-image%s", context["random_suffix"])'
vars:
disk_name: 'example-disk'
image_name: 'example-image'
- name: 'image_guest_os'
primary_resource_id: 'example'
vars:
disk_name: 'example-disk'
image_name: 'example-image'
- name: 'image_basic_storage_location'
primary_resource_id: 'example'
vars:
disk_name: 'example-disk'
image_name: 'example-sl-image'
primary_resource_name: 'fmt.Sprintf("tf-test-sl-example-image%s", context["random_suffix"])'
parameters:
Expand Down
17 changes: 14 additions & 3 deletions mmv1/templates/terraform/examples/image_basic.tf.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
data "google_compute_image" "debian" {
family = "debian-12"
project = "debian-cloud"
}

resource "google_compute_disk" "persistent" {
name = "{{index $.Vars "disk_name"}}"
image = data.google_compute_image.debian.self_link
size = 10
type = "pd-ssd"
zone = "us-central1-a"
}

resource "google_compute_image" "example" {
name = "{{index $.Vars "image_name"}}"

raw_disk {
source = "https://storage.googleapis.com/bosh-gce-raw-stemcells/bosh-stemcell-97.98-google-kvm-ubuntu-xenial-go_agent-raw-1557960142.tar.gz"
}
source_disk = google_compute_disk.persistent.id
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
data "google_compute_image" "debian" {
family = "debian-12"
project = "debian-cloud"
}

resource "google_compute_disk" "persistent" {
name = "{{index $.Vars "disk_name"}}"
image = data.google_compute_image.debian.self_link
size = 10
type = "pd-ssd"
zone = "us-central1-a"
}

resource "google_compute_image" "example" {
name = "{{index $.Vars "image_name"}}"

raw_disk {
source = "https://storage.googleapis.com/bosh-gce-raw-stemcells/bosh-stemcell-97.98-google-kvm-ubuntu-xenial-go_agent-raw-1557960142.tar.gz"
}
source_disk = google_compute_disk.persistent.id
storage_locations = ["us-central1"]
}
31 changes: 27 additions & 4 deletions mmv1/templates/terraform/examples/image_guest_os.tf.tmpl
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
data "google_compute_image" "debian" {
family = "debian-12"
project = "debian-cloud"
}

resource "google_compute_disk" "persistent" {
name = "{{index $.Vars "disk_name"}}"
image = data.google_compute_image.debian.self_link
size = 10
type = "pd-ssd"
zone = "us-central1-a"
}

resource "google_compute_image" "example" {
name = "{{index $.Vars "image_name"}}"

raw_disk {
source = "https://storage.googleapis.com/bosh-gce-raw-stemcells/bosh-stemcell-97.98-google-kvm-ubuntu-xenial-go_agent-raw-1557960142.tar.gz"
source_disk = google_compute_disk.persistent.id

guest_os_features {
type = "UEFI_COMPATIBLE"
}

guest_os_features {
type = "VIRTIO_SCSI_MULTIQUEUE"
}

guest_os_features {
type = "GVNIC"
}

guest_os_features {
type = "SECURE_BOOT"
type = "SEV_CAPABLE"
}

guest_os_features {
type = "MULTI_IP_SUBNET"
type = "SEV_LIVE_MIGRATABLE_V2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,29 @@ func TestAccComputeImage_update(t *testing.T) {

var image compute.Image

name := "image-test-" + acctest.RandString(t, 10)
context := map[string]interface{}{
"name": "image-test-" + acctest.RandString(t, 10),
"disk_image_path": "./test-fixtures/raw-disk-image.tar.gz",
"bucket_one": "tf-test-compute-image-bucket-" + acctest.RandString(t, 10),
"bucket_two": "tf-test-compute-image-bucket-" + acctest.RandString(t, 10),
}

// Only labels supports an update
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeImageDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeImage_basic(name),
Config: testAccComputeImage_basic(context),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeImageExists(
t, "google_compute_image.foobar", &image),
testAccCheckComputeImageContainsLabel(&image, "my-label", "my-label-value"),
),
},
{
Config: testAccComputeImage_update(name),
Config: testAccComputeImage_update(context),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeImageExists(
t, "google_compute_image.foobar", &image),
Expand Down Expand Up @@ -358,20 +364,32 @@ resource "google_compute_image" "foobar" {
`, name, name, family)
}

func testAccComputeImage_basic(name string) string {
return fmt.Sprintf(`
func testAccComputeImage_basic(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_storage_bucket" "bucket_one" {
name = "%{bucket_one}"
location = "US"
uniform_bucket_level_access = true
}

resource "google_storage_bucket_object" "object" {
name = "raw-disk-image.tar.gz"
bucket = google_storage_bucket.bucket_one.name
source = "%{disk_image_path}"
}

resource "google_compute_image" "foobar" {
name = "%s"
name = "%{name}"
description = "description-test"
family = "family-test"
raw_disk {
source = "https://storage.googleapis.com/bosh-gce-raw-stemcells/bosh-stemcell-97.98-google-kvm-ubuntu-xenial-go_agent-raw-1557960142.tar.gz"
source = "https://${google_storage_bucket.bucket_one.name}.storage.googleapis.com/${google_storage_bucket_object.object.name}"
}
labels = {
my-label = "my-label-value"
}
}
`, name)
`, context)
}

func testAccComputeImage_license(name string) string {
Expand Down Expand Up @@ -402,21 +420,33 @@ resource "google_compute_image" "foobar" {
`, name, name)
}

func testAccComputeImage_update(name string) string {
return fmt.Sprintf(`
func testAccComputeImage_update(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_storage_bucket" "bucket_two" {
name = "%{bucket_two}"
location = "US"
uniform_bucket_level_access = true
}

resource "google_storage_bucket_object" "object" {
name = "raw-disk-image.tar.gz"
bucket = google_storage_bucket.bucket_two.name
source = "%{disk_image_path}"
}

resource "google_compute_image" "foobar" {
name = "%s"
name = "%{name}"
description = "description-test"
family = "family-test"
raw_disk {
source = "https://storage.googleapis.com/bosh-gce-raw-stemcells/bosh-stemcell-97.98-google-kvm-ubuntu-xenial-go_agent-raw-1557960142.tar.gz"
source = "https://${google_storage_bucket.bucket_two.name}.storage.googleapis.com/${google_storage_bucket_object.object.name}"
}
labels = {
empty-label = "oh-look-theres-a-label-now"
new-field = "only-shows-up-when-updated"
}
}
`, name)
`, context)
}

func testAccComputeImage_basedondisk(diskName, imageName string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,20 @@ func TestAccComputeInstanceTemplate_imageShorthand(t *testing.T) {

var instanceTemplate compute.InstanceTemplate

context := map[string]interface{}{
"template": "tf-test-instance-template-" + acctest.RandString(t, 10),
"image": "tf-test-compute-image-" + acctest.RandString(t, 10),
"bucket": "tf-test-compute-image-bucket-" + acctest.RandString(t, 10),
"disk_image_path": "./test-fixtures/raw-disk-image.tar.gz",
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeInstanceTemplate_imageShorthand(acctest.RandString(t, 10)),
Config: testAccComputeInstanceTemplate_imageShorthand(context),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceTemplateExists(
t, "google_compute_instance_template.foobar", &instanceTemplate),
Expand Down Expand Up @@ -1089,14 +1096,14 @@ func TestAccComputeInstanceTemplate_nictype_update(t *testing.T) {
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeInstanceTemplate_nictype(instanceTemplateName, instanceTemplateName, "GVNIC"),
Config: testAccComputeInstanceTemplate_nictype(instanceTemplateName, "GVNIC"),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceTemplateExists(
t, "google_compute_instance_template.foobar", &instanceTemplate),
),
},
{
Config: testAccComputeInstanceTemplate_nictype(instanceTemplateName, instanceTemplateName, "VIRTIO_NET"),
Config: testAccComputeInstanceTemplate_nictype(instanceTemplateName, "VIRTIO_NET"),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceTemplateExists(
t, "google_compute_instance_template.foobar", &instanceTemplate),
Expand Down Expand Up @@ -2361,14 +2368,26 @@ resource "google_compute_instance_template" "foobar" {
`, suffix)
}

func testAccComputeInstanceTemplate_imageShorthand(suffix string) string {
return fmt.Sprintf(`
func testAccComputeInstanceTemplate_imageShorthand(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_storage_bucket" "bucket" {
name = "%{bucket}"
location = "US"
uniform_bucket_level_access = true
}

resource "google_storage_bucket_object" "object" {
name = "raw-disk-image.tar.gz"
bucket = google_storage_bucket.bucket.name
source = "%{disk_image_path}"
}

resource "google_compute_image" "foobar" {
name = "tf-test-%s"
name = "%{image}"
description = "description-test"
family = "family-test"
raw_disk {
source = "https://storage.googleapis.com/bosh-gce-raw-stemcells/bosh-stemcell-97.98-google-kvm-ubuntu-xenial-go_agent-raw-1557960142.tar.gz"
source = "https://${google_storage_bucket.bucket.name}.storage.googleapis.com/${google_storage_bucket_object.object.name}"
}
labels = {
my-label = "my-label-value"
Expand All @@ -2379,7 +2398,7 @@ resource "google_compute_image" "foobar" {
}

resource "google_compute_instance_template" "foobar" {
name = "tf-test-instance-template-%s"
name = "%{template}"
machine_type = "e2-medium"
can_ip_forward = false
tags = ["foo", "bar"]
Expand Down Expand Up @@ -2411,7 +2430,7 @@ resource "google_compute_instance_template" "foobar" {
my_label = "foobar"
}
}
`, suffix, suffix)
`, context)
}

func testAccComputeInstanceTemplate_preemptible(suffix string) string {
Expand Down Expand Up @@ -3899,25 +3918,11 @@ resource "google_compute_resource_policy" "foo" {
`, suffix, policyName)
}

func testAccComputeInstanceTemplate_nictype(image, instance, nictype string) string {
func testAccComputeInstanceTemplate_nictype(instance, nictype string) string {
return fmt.Sprintf(`
resource "google_compute_image" "example" {
name = "%s"
raw_disk {
source = "https://storage.googleapis.com/bosh-gce-raw-stemcells/bosh-stemcell-97.98-google-kvm-ubuntu-xenial-go_agent-raw-1557960142.tar.gz"
}

guest_os_features {
type = "SECURE_BOOT"
}

guest_os_features {
type = "MULTI_IP_SUBNET"
}

guest_os_features {
type = "GVNIC"
}
data "google_compute_image" "example" {
family = "debian-12"
project = "debian-cloud"
}

resource "google_compute_instance_template" "foobar" {
Expand All @@ -3927,7 +3932,7 @@ resource "google_compute_instance_template" "foobar" {
tags = ["foo", "bar"]

disk {
source_image = google_compute_image.example.name
source_image = data.google_compute_image.example.self_link
auto_delete = true
boot = true
}
Expand All @@ -3954,7 +3959,7 @@ resource "google_compute_instance_template" "foobar" {
my_label = "foobar"
}
}
`, image, instance, nictype)
`, instance, nictype)
}

func testAccComputeInstanceTemplate_queueCount(instanceTemplateName string) string {
Expand Down
Loading

0 comments on commit cdd8585

Please sign in to comment.