From 679b063a30df89692e3bc82426770711ac3c56a6 Mon Sep 17 00:00:00 2001 From: Noah Webb Date: Fri, 19 Aug 2016 13:55:30 -0400 Subject: [PATCH] provider/google: changed the format of source_image in autoscaler tests --- .../google/resource_compute_autoscaler_test.go | 4 ++-- ...esource_compute_instance_group_manager_test.go | 10 +++++----- .../google/resource_compute_instance_template.go | 15 ++++++++++----- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/builtin/providers/google/resource_compute_autoscaler_test.go b/builtin/providers/google/resource_compute_autoscaler_test.go index 40f9fcac6..00a92592f 100644 --- a/builtin/providers/google/resource_compute_autoscaler_test.go +++ b/builtin/providers/google/resource_compute_autoscaler_test.go @@ -139,7 +139,7 @@ resource "google_compute_instance_template" "foobar" { tags = ["foo", "bar"] disk { - source_image = "debian-8-jessie-v20160803" + source_image = "debian-cloud/debian-7-wheezy-v20160301" auto_delete = true boot = true } @@ -196,7 +196,7 @@ resource "google_compute_instance_template" "foobar" { tags = ["foo", "bar"] disk { - source_image = "debian-8-jessie-v20160803" + source_image = "debian-cloud/debian-7-wheezy-v20160301" auto_delete = true boot = true } diff --git a/builtin/providers/google/resource_compute_instance_group_manager_test.go b/builtin/providers/google/resource_compute_instance_group_manager_test.go index 87d4ea3d8..610793bc6 100644 --- a/builtin/providers/google/resource_compute_instance_group_manager_test.go +++ b/builtin/providers/google/resource_compute_instance_group_manager_test.go @@ -277,7 +277,7 @@ func testAccInstanceGroupManager_basic(template, target, igm1, igm2 string) stri tags = ["foo", "bar"] disk { - source_image = "debian-8-jessie-v20160803" + source_image = "debian-cloud/debian-7-wheezy-v20160301" auto_delete = true boot = true } @@ -331,7 +331,7 @@ func testAccInstanceGroupManager_update(template, target, igm string) string { tags = ["foo", "bar"] disk { - source_image = "debian-8-jessie-v20160803" + source_image = "debian-cloud/debian-7-wheezy-v20160301" auto_delete = true boot = true } @@ -380,7 +380,7 @@ func testAccInstanceGroupManager_update2(template1, target, template2, igm strin tags = ["foo", "bar"] disk { - source_image = "debian-8-jessie-v20160803" + source_image = "debian-cloud/debian-7-wheezy-v20160301" auto_delete = true boot = true } @@ -411,7 +411,7 @@ func testAccInstanceGroupManager_update2(template1, target, template2, igm strin tags = ["foo", "bar"] disk { - source_image = "debian-8-jessie-v20160803" + source_image = "debian-cloud/debian-7-wheezy-v20160301" auto_delete = true boot = true } @@ -456,7 +456,7 @@ func testAccInstanceGroupManager_updateLifecycle(tag, igm string) string { tags = ["%s"] disk { - source_image = "debian-8-jessie-v20160803" + source_image = "debian-cloud/debian-7-wheezy-v20160301" auto_delete = true boot = true } diff --git a/builtin/providers/google/resource_compute_instance_template.go b/builtin/providers/google/resource_compute_instance_template.go index 9b448f1a9..1b76bc7db 100644 --- a/builtin/providers/google/resource_compute_instance_template.go +++ b/builtin/providers/google/resource_compute_instance_template.go @@ -585,13 +585,18 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac return resourceComputeInstanceTemplateRead(d, meta) } -func flattenDisks(disks []*compute.AttachedDisk) []map[string]interface{} { +func flattenDisks(disks []*compute.AttachedDisk, d *schema.ResourceData) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(disks)) - for _, disk := range disks { + for i, disk := range disks { diskMap := make(map[string]interface{}) if disk.InitializeParams != nil { - sourceImageUrl := strings.Split(disk.InitializeParams.SourceImage, "/") - diskMap["source_image"] = sourceImageUrl[len(sourceImageUrl)-1] + var source_img = fmt.Sprintf("disk.%d.source_image", i) + if d.Get(source_img) == nil || d.Get(source_img) == "" { + sourceImageUrl := strings.Split(disk.InitializeParams.SourceImage, "/") + diskMap["source_image"] = sourceImageUrl[len(sourceImageUrl)-1] + } else { + diskMap["source_image"] = d.Get(source_img) + } diskMap["disk_type"] = disk.InitializeParams.DiskType diskMap["disk_name"] = disk.InitializeParams.DiskName diskMap["disk_size_gb"] = disk.InitializeParams.DiskSizeGb @@ -701,7 +706,7 @@ func resourceComputeInstanceTemplateRead(d *schema.ResourceData, meta interface{ d.Set("self_link", instanceTemplate.SelfLink) d.Set("name", instanceTemplate.Name) if instanceTemplate.Properties.Disks != nil { - d.Set("disk", flattenDisks(instanceTemplate.Properties.Disks)) + d.Set("disk", flattenDisks(instanceTemplate.Properties.Disks, d)) } d.Set("description", instanceTemplate.Description) d.Set("machine_type", instanceTemplate.Properties.MachineType)