mirror of https://github.com/hashicorp/packer
add possibility to use variables everywhere in post-processor blocks (#11094)
feature + tests.
Including in:
* name
* only
* except
* keep_input_artifact
Example file:
```hcl
source "null" "example1" {
communicator = "none"
}
source "null" "example2" {
communicator = "none"
}
locals {
except = "null.example1"
}
variable "only" {
default = "null.example1"
}
build {
sources = ["source.null.example1", "source.null.example2"]
post-processor "shell-local" {
except = [local.except]
inline = ["echo first post-processor"]
}
post-processor "shell-local" {
only = [var.only]
inline = ["echo second post-processor"]
}
}
```
Ouput:
```shell-session
$ packer build foo.pkr.hcl
null.example1: output will be in this color.
null.example2: output will be in this color.
==> null.example1: Running post-processor: (type shell-local)
==> null.example2: Running post-processor: (type shell-local)
==> null.example2 (shell-local): Running local shell script: /var/folders/3k/2gb5ct4s7cncr52_jh2kz6cw0000gq/T/packer-shell201696062
==> null.example1 (shell-local): Running local shell script: /var/folders/3k/2gb5ct4s7cncr52_jh2kz6cw0000gq/T/packer-shell494781572
null.example1 (shell-local): second post-processor
Build 'null.example1' finished after 61 milliseconds 432 microseconds.
null.example2 (shell-local): first post-processor
Build 'null.example2' finished after 111 milliseconds 678 microseconds.
==> Wait completed after 111 milliseconds 714 microseconds
```
close #4895
pull/11102/head
parent
e22346f0fa
commit
9d0193ac14
@ -0,0 +1,35 @@
|
||||
source "null" "example1" {
|
||||
communicator = "none"
|
||||
}
|
||||
|
||||
source "null" "example2" {
|
||||
communicator = "none"
|
||||
}
|
||||
|
||||
locals {
|
||||
except_example2 = "null.example2"
|
||||
true = true
|
||||
}
|
||||
|
||||
variable "only_example2" {
|
||||
default = "null.example2"
|
||||
}
|
||||
|
||||
variable "foo" {
|
||||
default = "bar"
|
||||
}
|
||||
|
||||
build {
|
||||
sources = ["source.null.example1", "source.null.example2"]
|
||||
post-processor "shell-local" {
|
||||
keep_input_artifact = local.true
|
||||
except = [local.except_example2]
|
||||
inline = ["echo 1 > ${source.name}.1.txt"]
|
||||
}
|
||||
|
||||
post-processor "shell-local" {
|
||||
name = var.foo
|
||||
only = [var.only_example2]
|
||||
inline = ["echo 2 > ${source.name}.2.txt"]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue