From 670040eb261e8d6d5ada50038b92049549a31f03 Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Fri, 17 Jan 2020 12:22:23 -0800 Subject: [PATCH] Expand boot disk name to full name during instance from template creation (#2989) Merged PR #2989. --- .../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/third_party/terraform/resources/resource_compute_instance_from_template.go b/third_party/terraform/resources/resource_compute_instance_from_template.go index ad1840784890..c5793396f399 100644 --- a/third_party/terraform/resources/resource_compute_instance_from_template.go +++ b/third_party/terraform/resources/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/third_party/terraform/tests/resource_compute_instance_from_template_test.go b/third_party/terraform/tests/resource_compute_instance_from_template_test.go index 0309417fcfa5..f419604a923b 100644 --- a/third_party/terraform/tests/resource_compute_instance_from_template_test.go +++ b/third_party/terraform/tests/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" }