Skip to content

Commit

Permalink
Prioritize disk.DiskSizeGb over disk.InitializeParams.DiskSizeGb (#8246
Browse files Browse the repository at this point in the history
…) (#15054)

* Add and prefer AttachedDisk.DiskSizeGb over AttachedDisk.InitializeParams.DiskSizeGb

* Fix a paren out of place

* Add DiskSizeGb outside InitializeParams as a separate field.

* Undo unnecessary changes

* use one field instead of two

* use one field instead of two

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored and SarahFrench committed Jul 6, 2023
1 parent d41ec6f commit bcfc366
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .changelog/8246.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
```release-note:none
```
15 changes: 11 additions & 4 deletions google/services/compute/resource_compute_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,10 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
disk.DiskEncryptionKey.KmsKeyName = v.(string)
}
}

// Assign disk.DiskSizeGb and disk.InitializeParams.DiskSizeGb the same value
if v, ok := d.GetOk(prefix + ".disk_size_gb"); ok {
disk.DiskSizeGb = int64(v.(int))
}
if v, ok := d.GetOk(prefix + ".source"); ok {
disk.Source = v.(string)
conflicts := []string{"disk_size_gb", "disk_name", "disk_type", "source_image", "source_snapshot", "labels"}
Expand All @@ -1014,6 +1017,7 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
if v, ok := d.GetOk(prefix + ".disk_name"); ok {
disk.InitializeParams.DiskName = v.(string)
}
// Assign disk.DiskSizeGb and disk.InitializeParams.DiskSizeGb the same value
if v, ok := d.GetOk(prefix + ".disk_size_gb"); ok {
disk.InitializeParams.DiskSizeGb = int64(v.(int))
}
Expand Down Expand Up @@ -1274,10 +1278,13 @@ func flattenDisk(disk *compute.AttachedDisk, configDisk map[string]any, defaultP
diskMap["disk_type"] = disk.InitializeParams.DiskType
diskMap["disk_name"] = disk.InitializeParams.DiskName
diskMap["labels"] = disk.InitializeParams.Labels
// The API does not return a disk size value for scratch disks. They can only be one size,
// so we can assume that size here.
if disk.InitializeParams.DiskSizeGb == 0 && disk.Type == "SCRATCH" {
// The API does not return a disk size value for scratch disks. They are largely only one size,
// so we can assume that size here. Prefer disk.DiskSizeGb over the deprecated
// disk.InitializeParams.DiskSizeGb.
if disk.DiskSizeGb == 0 && disk.InitializeParams.DiskSizeGb == 0 && disk.Type == "SCRATCH" {
diskMap["disk_size_gb"] = DEFAULT_SCRATCH_DISK_SIZE_GB
} else if disk.DiskSizeGb != 0 {
diskMap["disk_size_gb"] = disk.DiskSizeGb
} else {
diskMap["disk_size_gb"] = disk.InitializeParams.DiskSizeGb
}
Expand Down

0 comments on commit bcfc366

Please sign in to comment.