Merge pull request #8301 from nwwebb/import-autoscaler

provider/google: Ignore source image for 'google_compute_instance_template'
This commit is contained in:
Lars Wander 2016-08-19 14:53:27 -04:00 committed by GitHub
commit 4aaff3da46
3 changed files with 17 additions and 12 deletions

View File

@ -139,7 +139,7 @@ resource "google_compute_instance_template" "foobar" {
tags = ["foo", "bar"] tags = ["foo", "bar"]
disk { disk {
source_image = "debian-8-jessie-v20160803" source_image = "debian-cloud/debian-7-wheezy-v20160301"
auto_delete = true auto_delete = true
boot = true boot = true
} }
@ -196,7 +196,7 @@ resource "google_compute_instance_template" "foobar" {
tags = ["foo", "bar"] tags = ["foo", "bar"]
disk { disk {
source_image = "debian-8-jessie-v20160803" source_image = "debian-cloud/debian-7-wheezy-v20160301"
auto_delete = true auto_delete = true
boot = true boot = true
} }

View File

@ -277,7 +277,7 @@ func testAccInstanceGroupManager_basic(template, target, igm1, igm2 string) stri
tags = ["foo", "bar"] tags = ["foo", "bar"]
disk { disk {
source_image = "debian-8-jessie-v20160803" source_image = "debian-cloud/debian-7-wheezy-v20160301"
auto_delete = true auto_delete = true
boot = true boot = true
} }
@ -331,7 +331,7 @@ func testAccInstanceGroupManager_update(template, target, igm string) string {
tags = ["foo", "bar"] tags = ["foo", "bar"]
disk { disk {
source_image = "debian-8-jessie-v20160803" source_image = "debian-cloud/debian-7-wheezy-v20160301"
auto_delete = true auto_delete = true
boot = true boot = true
} }
@ -380,7 +380,7 @@ func testAccInstanceGroupManager_update2(template1, target, template2, igm strin
tags = ["foo", "bar"] tags = ["foo", "bar"]
disk { disk {
source_image = "debian-8-jessie-v20160803" source_image = "debian-cloud/debian-7-wheezy-v20160301"
auto_delete = true auto_delete = true
boot = true boot = true
} }
@ -411,7 +411,7 @@ func testAccInstanceGroupManager_update2(template1, target, template2, igm strin
tags = ["foo", "bar"] tags = ["foo", "bar"]
disk { disk {
source_image = "debian-8-jessie-v20160803" source_image = "debian-cloud/debian-7-wheezy-v20160301"
auto_delete = true auto_delete = true
boot = true boot = true
} }
@ -456,7 +456,7 @@ func testAccInstanceGroupManager_updateLifecycle(tag, igm string) string {
tags = ["%s"] tags = ["%s"]
disk { disk {
source_image = "debian-8-jessie-v20160803" source_image = "debian-cloud/debian-7-wheezy-v20160301"
auto_delete = true auto_delete = true
boot = true boot = true
} }

View File

@ -585,13 +585,18 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac
return resourceComputeInstanceTemplateRead(d, meta) 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)) result := make([]map[string]interface{}, 0, len(disks))
for _, disk := range disks { for i, disk := range disks {
diskMap := make(map[string]interface{}) diskMap := make(map[string]interface{})
if disk.InitializeParams != nil { if disk.InitializeParams != nil {
sourceImageUrl := strings.Split(disk.InitializeParams.SourceImage, "/") var source_img = fmt.Sprintf("disk.%d.source_image", i)
diskMap["source_image"] = sourceImageUrl[len(sourceImageUrl)-1] 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_type"] = disk.InitializeParams.DiskType
diskMap["disk_name"] = disk.InitializeParams.DiskName diskMap["disk_name"] = disk.InitializeParams.DiskName
diskMap["disk_size_gb"] = disk.InitializeParams.DiskSizeGb 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("self_link", instanceTemplate.SelfLink)
d.Set("name", instanceTemplate.Name) d.Set("name", instanceTemplate.Name)
if instanceTemplate.Properties.Disks != nil { 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("description", instanceTemplate.Description)
d.Set("machine_type", instanceTemplate.Properties.MachineType) d.Set("machine_type", instanceTemplate.Properties.MachineType)