packer/command/test-fixtures/hcl/data-source-validation.pkr.hcl
Adrien Delorme 0362a3ec10
all shells: Pass env vars through a key value store (#11569)
* allowing to set shell env vars from a key/value map.
* tests

This new map will work alongside the `environment_vars` but it allows using a
datasource value seamlessly. At validation, and because `environment_vars` was
an array of strings containing `KEY=value`, using datsources would not work,
because these values are not known yet and would evaluate to `<unknown>`. With
this, the value and the key can be unknown and will validate correctly for
datasources.
2022-02-16 12:05:44 +01:00

39 lines
750 B
HCL

data "null" "secret" {
input = "s3cr3t"
}
locals {
secret = data.null.secret.output
}
source "file" "foo" {
content = "foo"
target = "foo.txt"
}
build {
sources = ["file.foo"]
provisioner "shell-local" {
only_on = ["darwin", "freebsd", "linux", "openbsd", "solaris"]
# original bug in :
# environment_vars = ["MY_SECRET=${local.secret}"]
env = {
"MY_SECRET":"${local.secret}",
}
inline = [
"echo yo, my secret is $MY_SECRET",
"echo '' > $MY_SECRET",
]
}
provisioner "shell-local" {
only_on = ["windows"]
env = {
"MY_SECRET":"${local.secret}",
}
inline = [
"echo yo, my secret is %MY_SECRET%",
"echo '' > %MY_SECRET%",
]
}
}