Skip to content

Fit disk size to source image by default - #356

Open
ExplorerRay wants to merge 2 commits into
hashicorp:mainfrom
ExplorerRay:fit-disk-size-to-source-image
Open

Fit disk size to source image by default#356
ExplorerRay wants to merge 2 commits into
hashicorp:mainfrom
ExplorerRay:fit-disk-size-to-source-image

Conversation

@ExplorerRay

Copy link
Copy Markdown

Description

I found that this builder will use 20GB when not specified image disk_size and I met an issue that my source image is using a disk with 430GB which GCE reports me 20GB is unavailable to build. Working around it means looking up the image's size and hardcoding it into the template, so I think defaulting to the source image size is the better behavior.

With the help of Claude, I made Config.Prepare stop defaulting disk_size to 20, which lets an unset value reach the build as 0. StepCreateInstance then resolves it against sourceImage.SizeGb, which the driver already populates from the image's diskSizeGb. If the source image reports no size, it falls back to a new defaultDiskSizeGb constant of 20GB, matching the original behavior.

An explicitly set disk_size is passed through unchanged, including a value smaller than the source image — that still fails at the GCE API exactly as it does today. I left it that way deliberately, but I'm happy to add a clearer error message or grow the disk automatically if reviewers prefer. Maybe we can add a fail-fast mechanism in resolveDiskSize().

One behavior change worth flagging: with disk_size unset and a source image smaller than 20GB, the boot disk is now the image's size rather than 20GB. Builds that relied on that extra headroom will need to set disk_size explicitly.

Also added TestResolveDiskSize, TestStepCreateInstance_diskSize, and TestConfigPrepare_DiskSizeDefault. go test ./... passes and the docs were regenerated with make generate.

Resolved Issues

No. I didn't create an issue before making this change.

Rollback Plan

If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

No. This reuses the existing code path that fetches image information.

Signed-off-by: Ray Huang <bjhuang@cs.nycu.edu.tw>
Signed-off-by: Ray Huang <bjhuang@cs.nycu.edu.tw>
@ExplorerRay
ExplorerRay requested a review from a team as a code owner August 2, 2026 01:13
@hashicorp-cla-app

hashicorp-cla-app Bot commented Aug 2, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@hashicorp-cla-app

Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant