Overview of the Issue
When using HCL w/ v1.5.4 on macOS, a local value crashes when referencing a variable without a default value, even when the variable is passed in on the command line. If the variable does have a default value, but a different value is passed on the command line, the local incorrectly uses the default value.
Reproduction Steps
When running with a variable default value set, we get the following (var.test should be the same as local.test):
$ packer build -color=false -var "test=\"new value\"" .
==> null: Running local shell script: /var/folders/ks/qdjm0w8j2rn556v32lqqhqzc0000gn/T/packer-shell942124337
null: var.test=new value local.test=default value
Build 'null' finished.
==> Builds finished. The artifacts of successful builds are:
--> null: Did not export anything. This is the null builder
If the default value is not specified, Packer will crash:
bash-3.2$ packer build -color=false -var "test=\"new value\"" .
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4a183d7]
goroutine 1 [running]:
github.com/hashicorp/packer/hcl2template.(*Variable).Value(0xc0002486e0, 0xc000204990, 0xc000614f20, 0x0, 0x0, 0xc0000b4800)
/private/tmp/packer-20200215-62787-y95gm9/hcl2template/types.variables.go:64 +0x197
github.com/hashicorp/packer/hcl2template.Variables.Values(0xc000204990, 0xc000205290)
/private/tmp/packer-20200215-62787-y95gm9/hcl2template/types.variables.go:73 +0xc3
github.com/hashicorp/packer/hcl2template.(*PackerConfig).EvalContext(0xc0001c6a80, 0xc000204ae0)
/private/tmp/packer-20200215-62787-y95gm9/hcl2template/types.packer_config.go:39 +0x111
Packer version
Packer v1.5.4
Simplified Packer Buildfile
https://gist.github.com/robzr/01a3a4da52bd85342528fc9a7c8246ab#file-main-pkr-hcl
Operating system and Environment details
Darwin GargiMac.local 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64
Log Fragments and crash.log files
https://gist.github.com/robzr/24f9b92928d541ba28a773e3697e55b2#file-crash-log
Overview of the Issue
When using HCL w/ v1.5.4 on macOS, a local value crashes when referencing a variable without a default value, even when the variable is passed in on the command line. If the variable does have a default value, but a different value is passed on the command line, the local incorrectly uses the default value.
Reproduction Steps
When running with a variable default value set, we get the following (var.test should be the same as local.test):
If the default value is not specified, Packer will crash:
Packer version
Packer v1.5.4
Simplified Packer Buildfile
https://gist.github.com/robzr/01a3a4da52bd85342528fc9a7c8246ab#file-main-pkr-hcl
Operating system and Environment details
Darwin GargiMac.local 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64
Log Fragments and crash.log files
https://gist.github.com/robzr/24f9b92928d541ba28a773e3697e55b2#file-crash-log