2020-05-26 09:29:47 -04:00
|
|
|
---
|
|
|
|
description: >
|
2020-06-02 05:49:40 -04:00
|
|
|
A source block nested in a build block allows you to use an already defined
|
2020-05-28 11:04:34 -04:00
|
|
|
source and to set specific fields.
|
2020-05-26 09:29:47 -04:00
|
|
|
layout: docs
|
|
|
|
page_title: source - build - Blocks
|
|
|
|
sidebar_title: <tt>source</tt>
|
|
|
|
---
|
|
|
|
|
|
|
|
# The `source` block
|
|
|
|
|
|
|
|
`@include 'from-1.5/beta-hcl2-note.mdx'`
|
|
|
|
|
2020-05-28 10:22:07 -04:00
|
|
|
A `source` block nested in a `build` block allows to use an already defined
|
|
|
|
source and to set specific fields.
|
2020-05-26 09:29:47 -04:00
|
|
|
|
|
|
|
```hcl
|
|
|
|
# builds.pkr.hcl
|
2020-06-09 06:42:01 -04:00
|
|
|
source "lxd" "arch" {
|
|
|
|
image = "archlinux"
|
|
|
|
}
|
|
|
|
|
2020-05-26 09:29:47 -04:00
|
|
|
build {
|
2020-06-09 06:42:01 -04:00
|
|
|
source "lxd.arch" {
|
2020-07-02 05:07:59 -04:00
|
|
|
// setting the name field allows to rename the source only for this build
|
|
|
|
// section.
|
|
|
|
name = "nomad"
|
|
|
|
output_image = "nomad"
|
2020-06-09 06:42:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "shell" {
|
|
|
|
inline = [ "echo installing nomad" ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
build {
|
|
|
|
source "lxd.arch" {
|
2020-07-02 05:07:59 -04:00
|
|
|
name = "consul"
|
|
|
|
output_image = "consul"
|
2020-06-09 06:42:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "shell" {
|
|
|
|
inline = [ "echo installing consul" ]
|
2020-05-26 09:29:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-06-09 06:42:01 -04:00
|
|
|
This allows to have commonly defined source settings with specific parts of it
|
|
|
|
defined inside the specific build block.
|
|
|
|
|
2020-06-02 06:35:32 -04:00
|
|
|
-> **Note:** It is **not allowed** to set the same field in a top-level source
|
2020-07-13 06:33:16 -04:00
|
|
|
block and in a used source block. For example, if in the above example, the
|
|
|
|
top-level "amazon-ebs.example" source block also had an `output` field;
|
|
|
|
Packer would error.
|