You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
packer/website/content/docs/templates/hcl_templates/blocks/build/source.mdx

57 lines
1.7 KiB

---
description: >
A `source` block nested in a `build` block reuses a builder defined
elsewhere in the configuration. Learn how to configure a nested `source` block.
page_title: source block reference
---
# `source` block
This topic provides reference information about `source` blocks nested in a `build` block.
## Description
Add a `source` block to your `build` block to reuse a builder defined elsewhere in the configuration. Packer fills in the source fields that are not 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` command fails 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
redefined and image field, Packer would error.
```hcl
# file: builds.pkr.hcl
source "lxd" "arch" {
image = "archlinux"
}
build {
# 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.
source "lxd.arch" {
# Setting the name field allows to rename the source only for this build section.
name = "nomad"
output_image = "nomad"
}
provisioner "shell" {
inline = [ "echo installing nomad" ]
}
}
build {
source "lxd.arch" {
name = "consul"
output_image = "consul"
}
provisioner "shell" {
inline = [ "echo installing consul" ]
}
}
```