mirror of https://github.com/hashicorp/packer
cmd/hcl2_upgrade: Generate variable block for all referenced user input variables (#12136)
Currently the HCL2 upgrade command generates a valid variable block for all variables within the JSON variables property. However JSON templates in Packer support variable interpolation for input variables defined within a variable definition file without it being declared within the variables property. When upgrading a JSON template to HCL2 the user variable reference gets converted to var.<var_name>. The upgraded template ultimately fails on validation or build execution with undefined variable errors, with this change the upgrade command will now create a variable block for all input variables referenced within the build template to ensure all required variables been defined.pull/12144/head
parent
f29b6da035
commit
dbeeab448a
@ -0,0 +1,26 @@
|
||||
|
||||
variable "communicator_type" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "foo" {
|
||||
type = string
|
||||
default = "bar"
|
||||
}
|
||||
|
||||
variable "scriptpath" {
|
||||
type = string
|
||||
}
|
||||
|
||||
source "null" "autogenerated_1" {
|
||||
communicator = "${var.communicator_type}"
|
||||
}
|
||||
|
||||
build {
|
||||
sources = ["source.null.autogenerated_1"]
|
||||
|
||||
provisioner "shell" {
|
||||
script = "${var.scriptpath}"
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
{
|
||||
"variables": {
|
||||
"foo": "bar"
|
||||
},
|
||||
"builders": [
|
||||
{
|
||||
"type": "null",
|
||||
"communicator": "{{ user `communicator_type` }}"
|
||||
}
|
||||
],
|
||||
"provisioners": [
|
||||
{
|
||||
"type": "shell",
|
||||
"script": "{{user `scriptpath`}}"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue