packer-cn/website/pages/docs/from-1.5/blocks/build/source.mdx

51 lines
1.1 KiB
Plaintext
Raw Normal View History

2020-05-26 09:29:47 -04:00
---
description: >
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
source "lxd" "arch" {
image = "archlinux"
}
2020-05-26 09:29:47 -04:00
build {
source "lxd.arch" {
output_image = "nomad"
}
provisioner "shell" {
inline = [ "echo installing nomad" ]
}
}
build {
source "lxd.arch" {
output_image = "consul"
}
provisioner "shell" {
inline = [ "echo installing consul" ]
2020-05-26 09:29:47 -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
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.