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
|
2020-05-28 17:04:34 +02:00
|
|
|
source and to set specific fields.
|
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'`
|
|
|
|
|
2020-05-28 16:22:07 +02:00
|
|
|
A `source` block nested in a `build` block allows to use an already defined
|
|
|
|
source and to set specific fields.
|
2020-05-26 15:29:47 +02:00
|
|
|
|
|
|
|
```hcl
|
|
|
|
# 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 {
|
2020-06-09 12:42:01 +02:00
|
|
|
source "lxd.arch" {
|
2020-07-02 11:07:59 +02:00
|
|
|
// setting the name field allows to rename the source only for this build
|
|
|
|
// section.
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-06-09 12:42:01 +02:00
|
|
|
This allows to have commonly defined source settings with specific parts of it
|
|
|
|
defined inside the specific build block.
|
|
|
|
|
2020-06-02 12:35:32 +02: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.
|