2020-05-26 15:29:47 +02:00
|
|
|
---
|
|
|
|
description: >
|
2020-06-02 11:49:40 +02:00
|
|
|
A source block nested in a build block allows you to use an already defined
|
2021-02-11 14:21:06 +01:00
|
|
|
source and to set specific fields which aren't already set in the top-level
|
2021-01-27 11:12:42 -08:00
|
|
|
source block.
|
2020-05-26 15:29:47 +02:00
|
|
|
page_title: source - build - Blocks
|
|
|
|
sidebar_title: <tt>source</tt>
|
|
|
|
---
|
|
|
|
|
|
|
|
# The `source` block
|
|
|
|
|
|
|
|
`@include 'from-1.5/beta-hcl2-note.mdx'`
|
|
|
|
|
2021-01-27 11:12:42 -08:00
|
|
|
A `source` block nested in a `build` block allows you to use an already defined
|
2021-02-11 14:21:06 +01:00
|
|
|
source and to "fill in" those fields _which aren't already set in the top-level
|
|
|
|
source block_.
|
|
|
|
|
|
|
|
Build-level source blocks are implemented by merging their contents with the
|
|
|
|
corresponding top-level source block, and a packer build will fail when it
|
|
|
|
encounters the ambiguity that arises when a source parameter is defined twice.
|
|
|
|
For example, in the below example, if the top-level "lxd.arch" source block
|
|
|
|
also defined an `output_image` field (or if one of the build-level source blocks
|
2021-01-27 11:12:42 -08:00
|
|
|
redefined and image field), Packer would error.
|
2020-05-26 15:29:47 +02:00
|
|
|
|
|
|
|
```hcl
|
2021-02-11 14:21:06 +01:00
|
|
|
# file: builds.pkr.hcl
|
2020-06-09 12:42:01 +02:00
|
|
|
source "lxd" "arch" {
|
|
|
|
image = "archlinux"
|
|
|
|
}
|
|
|
|
|
2020-05-26 15:29:47 +02:00
|
|
|
build {
|
2021-02-11 14:21:06 +01:00
|
|
|
# Use the singular `source` block set specific fields.
|
|
|
|
# Note that fields cannot be overwritten, in other words, you cannot
|
|
|
|
# set the 'image' field from the top-level source block in here, as well as
|
|
|
|
# the 'name' and 'output_image' fields cannot be set in the top-level source block.
|
2020-06-09 12:42:01 +02:00
|
|
|
source "lxd.arch" {
|
2021-02-11 14:21:06 +01:00
|
|
|
# Setting the name field allows to rename the source only for this build section.
|
2020-07-02 11:07:59 +02:00
|
|
|
name = "nomad"
|
|
|
|
output_image = "nomad"
|
2020-06-09 12:42:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "shell" {
|
|
|
|
inline = [ "echo installing nomad" ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
build {
|
|
|
|
source "lxd.arch" {
|
2020-07-02 11:07:59 +02:00
|
|
|
name = "consul"
|
|
|
|
output_image = "consul"
|
2020-06-09 12:42:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "shell" {
|
|
|
|
inline = [ "echo installing consul" ]
|
2020-05-26 15:29:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|