mirror of https://github.com/hashicorp/packer
Sanitize var code (#11566)
* evaluateLocalVariables: modify code for readability and some (not benchmarked) perfs * Make default input variable type the DynamicPseudoType This should be the default, and avoids a panic. This type can represent situations where a type is not yet known. Its meaning is undefined in cty. * do not take Empty types from default value * Update types.variables.go Co-authored-by: Wilken Rivera <wilken@hashicorp.com>pull/11570/head
parent
19fc5added
commit
e03ad29ca0
@ -0,0 +1,4 @@
|
||||
foo = ["yo"]
|
||||
bar = {
|
||||
"baz": "foo",
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
|
||||
variable "foo" {
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "bar" {
|
||||
default = {}
|
||||
}
|
||||
|
||||
source "file" "base" {
|
||||
}
|
||||
|
||||
build {
|
||||
source "sources.file.base" {
|
||||
target = "${var.bar.baz}.txt"
|
||||
content = var.foo[0]
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
variable "vms_to_build" {
|
||||
default = {
|
||||
"amgroup": "hey"
|
||||
}
|
||||
}
|
||||
|
||||
locals {
|
||||
vms_to_build = var.vms_to_build
|
||||
dynamic_slice = {
|
||||
for vm, val in var.vms_to_build :
|
||||
vm => lookup(local.vms_to_build, vm, "VM NAME NOT FOUND")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
source "file" "chocolate" {
|
||||
content = "hello"
|
||||
target = "${local.dynamic_slice.amgroup}.txt"
|
||||
}
|
||||
|
||||
build {
|
||||
sources = [
|
||||
"sources.file.chocolate",
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
|
||||
variable "vms_to_build" {
|
||||
}
|
||||
|
||||
locals {
|
||||
vms_to_build = var.vms_to_build
|
||||
dynamic_map = {
|
||||
for vm in local.vms_to_build :
|
||||
vm => lookup(local, vm, "VM NAME NOT FOUND")
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue