Skip to content

Commit aab7402

Browse files
Expand boot disk name to full name during instance from template creation (#5430)
Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Sam Levenick <[email protected]>
1 parent 3aaab71 commit aab7402

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

google/resource_compute_instance_from_template.go

+4
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ func adjustInstanceFromTemplateDisks(d *schema.ResourceData, config *Config, it
181181
// boot disk was not overridden, so use the one from the instance template
182182
for _, disk := range it.Properties.Disks {
183183
if disk.Boot {
184+
if disk.Source != "" {
185+
// Instances need a URL for the disk, but instance templates only have the name
186+
disk.Source = fmt.Sprintf("projects/%s/zones/%s/disks/%s", project, zone.Name, disk.Source)
187+
}
184188
if disk.InitializeParams != nil {
185189
if dt := disk.InitializeParams.DiskType; dt != "" {
186190
// Instances need a URL for the disk type, but instance templates

google/resource_compute_instance_from_template_test.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,10 @@ resource "google_compute_instance_template" "foobar" {
229229
name = "%s"
230230
machine_type = "n1-standard-1"
231231
232-
disk {
233-
source_image = data.google_compute_image.my_image.self_link
234-
auto_delete = true
235-
disk_size_gb = 100
236-
boot = true
237-
}
238-
239232
disk {
240233
source = google_compute_disk.foobar.name
241234
auto_delete = false
242-
boot = false
235+
boot = true
243236
}
244237
245238
disk {
@@ -249,6 +242,15 @@ resource "google_compute_instance_template" "foobar" {
249242
disk_size_gb = 375
250243
}
251244
245+
disk {
246+
source_image = data.google_compute_image.my_image.self_link
247+
auto_delete = true
248+
disk_size_gb = 100
249+
boot = false
250+
disk_type = "pd-ssd"
251+
type = "PERSISTENT"
252+
}
253+
252254
network_interface {
253255
network = "default"
254256
}

0 commit comments

Comments
 (0)