add missing provisioner override hcl docs (#10684)

This commit is contained in:
Sylvia Moss 2021-02-23 18:00:02 +01:00 committed by GitHub
parent ff5b55b560
commit fc23eb9241
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 84 additions and 24 deletions

View File

@ -76,6 +76,66 @@ build {
The values within `only` or `except` are _build names_, not builder types.
## Build-Specific Overrides
While the goal of Packer is to produce identical machine images, it sometimes
requires periods of time where the machines are different before they
eventually converge to be identical. In these cases, different configurations
for provisioners may be necessary depending on the build. This can be done
using build-specific overrides.
An example of where this might be necessary is when building both an EC2 AMI
and a VMware machine. The source EC2 AMI may setup a user with administrative
privileges by default, whereas the VMware machine doesn't have these
privileges. In this case, the shell script may need to be executed differently.
Of course, the goal is that hopefully the shell script converges these two
images to be identical. However, they may initially need to be run differently.
This example is shown below:
```hcl
source "null" "example1" {
communicator = "none"
}
source "null" "example2" {
communicator = "none"
}
source "null" "example3" {
communicator = "none"
}
build {
sources = ["source.null.example2", "source.null.example3"]
source "source.null.example1" {
// Give a name to this source
name = "renamed"
}
provisioner "shell-local" {
inline = ["echo not overridden"]
override = {
example3 = {
inline = ["echo overrides for example3"]
}
// Refer to the source with the given name
renamed = {
inline = ["echo overrides for renamed"]
}
}
}
}
```
As you can see, the `override` key is used. The value of this key is another
HCL attribute map where the key is the name of a [builder
definition](/docs/templates/hcl_templates/blocks/source). The value of this is in turn
another HCL attribute map. This HCL attribute map simply contains the provisioner
configuration as normal. This configuration is merged into the default
provisioner configuration.
## On Error Provisioner
You can optionally create a single specialized provisioner called an

View File

@ -10,6 +10,30 @@ Parameters common to all provisioners:
- `override` (object) - Override the builder with different settings for a
specific builder, eg :
In HCL2:
```hcl
source "null" "example1" {
communicator = "none"
}
source "null" "example2" {
communicator = "none"
}
build {
sources = ["source.null.example1", "source.null.example2"]
provisioner "shell-local" {
inline = ["echo not overridden"]
override = {
example1 = {
inline = ["echo yes overridden"]
}
}
}
}
```
In JSON:
```json
@ -40,29 +64,5 @@ Parameters common to all provisioners:
}
```
In HCL2:
```hcl
source "null" "example1" {
communicator = "none"
}
source "null" "example2" {
communicator = "none"
}
build {
sources = ["source.null.example1", "source.null.example2"]
provisioner "shell-local" {
inline = ["echo not overridden"]
override = {
example1 = {
inline = ["echo yes overridden"]
}
}
}
}
```
- `timeout` (duration) - If the provisioner takes more than for example
`1h10m1s` or `10m` to finish, the provisioner will timeout and fail.