Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assume scratch disk size when not returned by the API #4014

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var (
}
)

var REQUIRED_SCRATCH_DISK_SIZE_GB = 375

func resourceComputeInstanceTemplate() *schema.Resource {
return &schema.Resource{
Create: resourceComputeInstanceTemplateCreate,
Expand Down Expand Up @@ -131,6 +133,7 @@ func resourceComputeInstanceTemplate() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Computed: true,
Description: `The size of the image in gigabytes. If not specified, it will inherit the size of its base image. For SCRATCH disks, the size must be exactly 375GB.`,
},

Expand Down Expand Up @@ -671,8 +674,8 @@ func resourceComputeInstanceTemplateScratchDiskCustomizeDiffFunc(diff TerraformR
}

diskSize := diff.Get(fmt.Sprintf("disk.%d.disk_size_gb", i)).(int)
if typee == "SCRATCH" && diskSize != 375 {
return fmt.Errorf("SCRATCH disks must be exactly 375GB, disk %d is %d", i, diskSize)
if typee == "SCRATCH" && diskSize != REQUIRED_SCRATCH_DISK_SIZE_GB {
return fmt.Errorf("SCRATCH disks must be exactly %dGB, disk %d is %d", REQUIRED_SCRATCH_DISK_SIZE_GB, i, diskSize)
}
}

Expand Down Expand Up @@ -953,8 +956,14 @@ func flattenDisk(disk *computeBeta.AttachedDisk, defaultProject string) (map[str
}
diskMap["disk_type"] = disk.InitializeParams.DiskType
diskMap["disk_name"] = disk.InitializeParams.DiskName
diskMap["disk_size_gb"] = disk.InitializeParams.DiskSizeGb
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" {
diskMap["disk_size_gb"] = REQUIRED_SCRATCH_DISK_SIZE_GB
} else {
diskMap["disk_size_gb"] = disk.InitializeParams.DiskSizeGb
}
}

if disk.DiskEncryptionKey != nil {
Expand Down