Error: cannot parse 'disk_size' as uint (Packer)
Fixes packer validate failing to parse disk_size values with unit suffixes. For engineers whose templates use human-readable sizes like '5G', the fix is plain megabytes.
Error: cannot parse 'disk_size' as uint: strconv.ParseUint: parsing "5G": invalid syntax (Packer)
TL;DR
disk_size takes a bare number in MiB, not a human-readable size. Change "5G" to "5120".
The error
Build 'ubuntu-aarch64' prepare failure: 1 error(s) decoding:
* cannot parse 'disk_size' as uint: strconv.ParseUint: parsing "5G": invalid syntaxFix it
- Find the
disk_size(or yourbuild_disk_sizevariable) in the template.
- Success check: you see the quoted
"5G"or similar suffix.
- Replace with mebibytes as a bare number: 5 GiB becomes
5120, 20 GiB becomes20480.
- Success check: the value is digits only (quotes are fine; the suffix is the problem).
- Run
packer validate.
- Success check: the decoding error is gone.
- Re-run
packer build.
- Success check: the build prepares and proceeds.
When to use this
You hit this at prepare/validate time with a disk_size carrying a unit suffix.
When NOT to use this
Do not use this for disk space errors during provisioning (guest ran out of room; increase the size) or for cloud block-device size limits.
Compatibility
Packer 1.x, qemu and other builders with numeric disk_size.
Variants
cannot parse '[other-field]' as uintfor any numeric field given a suffixed string"5GB","5120M","20g"all fail the same way
Root cause
The field decodes as an unsigned int in MiB. Go's ParseUint rejects anything but digits, so unit suffixes fail at config decode time, before the build starts.
Edge cases
- Some builders document the unit as MiB explicitly; others just say "size". When in doubt, assume MiB.
- Template variables pass the string through; fix the variable default or the
-varvalue, not just the template.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.