From ba09475747a690b30374ba084448752e016e0330 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 17 Jan 2020 11:08:07 -0800 Subject: [PATCH] Expand boot disk name to full name during instance from template creation (#1655) Signed-off-by: Modular Magician Co-authored-by: Sam Levenick --- .../resource_compute_instance_from_template.go | 4 ++++ ...urce_compute_instance_from_template_test.go | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/google-beta/resource_compute_instance_from_template.go b/google-beta/resource_compute_instance_from_template.go index ad18407848..c5793396f3 100644 --- a/google-beta/resource_compute_instance_from_template.go +++ b/google-beta/resource_compute_instance_from_template.go @@ -181,6 +181,10 @@ func adjustInstanceFromTemplateDisks(d *schema.ResourceData, config *Config, it // boot disk was not overridden, so use the one from the instance template for _, disk := range it.Properties.Disks { if disk.Boot { + if disk.Source != "" { + // Instances need a URL for the disk, but instance templates only have the name + disk.Source = fmt.Sprintf("projects/%s/zones/%s/disks/%s", project, zone.Name, disk.Source) + } if disk.InitializeParams != nil { if dt := disk.InitializeParams.DiskType; dt != "" { // Instances need a URL for the disk type, but instance templates diff --git a/google-beta/resource_compute_instance_from_template_test.go b/google-beta/resource_compute_instance_from_template_test.go index 0309417fcf..f419604a92 100644 --- a/google-beta/resource_compute_instance_from_template_test.go +++ b/google-beta/resource_compute_instance_from_template_test.go @@ -229,17 +229,10 @@ resource "google_compute_instance_template" "foobar" { name = "%s" machine_type = "n1-standard-1" - disk { - source_image = data.google_compute_image.my_image.self_link - auto_delete = true - disk_size_gb = 100 - boot = true - } - disk { source = google_compute_disk.foobar.name auto_delete = false - boot = false + boot = true } disk { @@ -249,6 +242,15 @@ resource "google_compute_instance_template" "foobar" { disk_size_gb = 375 } + disk { + source_image = data.google_compute_image.my_image.self_link + auto_delete = true + disk_size_gb = 100 + boot = false + disk_type = "pd-ssd" + type = "PERSISTENT" + } + network_interface { network = "default" }