Confusing behavior in declaring variables that are set via variable files
- Dominant language
- Go
- Stars
- 15.8k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
#### Overview of the Issue
After switching to pkr.hcl I cannot use a vars file of any kind with my template.
Previously I used .json and had separated templates and config I do not want in our repo for security reasons.
To be able to use vshpere iso builders new feature of adding a vTPM during build I could only get the newest version of the builder when adding the version in hcl. So I converted a .json to .pkr.hcl. But I cannot find a way to add a variables.pkr.hcl to the template. -var-file does not like the .pkr.hcl. Adding the variables.json also does not work. Also tried variables.auto.pkr.hcl and variables.pkvars.hcl There were older bug that were closed without it being obvious that this is fixed.
#### Reproduction Steps
Create a .pkr.hcl template. Also add a variables.pkr.hcl
PACKER_LOG=1 packer build .
with template and variables.pkr.hcl in the current folder
### Packer version
1.7.10
### Simplified Packer Template
declarative
vcenter_network = "qa.lan"
also tried with variable datatype
variable "vcenter_network" {
type = string
default = "qa.lan"
}
### Operating system and Environment details
ubuntu 20.04.4 LTS on amd64
running vsphere iso 1.8.3 against a 7.0.2 vCenter
### Log Fragments and crash.log files
Error: Unsupported argument
on variables.auto.pkr.hcl line 8:
8: vcenter_network = "qa.lan"
An argument named "vcenter_network" is not expected here.
Contributor guide
Research direction
Reproduce the behavior with Packer 1.7.10 using a .pkr.hcl template and variables.pkr.hcl, then compare it with the documented -var-file and automatic variable-file paths. Start by tracing how the Packer CLI loads HCL variable files; done means a supported variable-file workflow works without the reported Unsupported argument error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100