github.com/hashicorp/packer@v1.14.3/website/content/docs/templates/hcl_templates/blocks/source.mdx (about)

     1  ---
     2  description: |
     3    The `source` block defines reusable builder configuration blocks. Learn how to define reusable builders using the `source` block.
     4  page_title: source block reference
     5  ---
     6  
     7  # `source` block
     8  
     9  This topic providers reference information about the `source` block.
    10  
    11  ## Description
    12  
    13  The `source` block defines reusable builder configuration blocks. Builders are commonly used in custom plugins.
    14  
    15  ## Example 
    16  
    17  The following example defines a source for a builder type called `happycloud` with the name `foo`:
    18  
    19  `@include 'from-1.5/sources/example-block.mdx'`
    20  
    21  There is only one `source.happycloud.foo` top-level source block, but it can be used more than once. 
    22  
    23  You can start builders by referring to `source` blocks from a [`build`
    24  block](/packer/docs/templates/hcl_templates/blocks/build) :
    25  
    26  ```hcl
    27  build {
    28    sources = [
    29      # Here Packer will use a default ami_name when saving the image.
    30      "source.happycloud.example",
    31      "source.happycloud.foo",
    32    ]
    33  }
    34  ```
    35  
    36  The build-level [`source`
    37  block](/packer/docs/templates/hcl_templates/blocks/build/source) allows to set specific
    38  source fields. Each field must be defined only once and it is currently not
    39  allowed to override a value.
    40  
    41  ```hcl
    42  build {
    43    source "source.happycloud.example" {
    44      # Here Packer will use the provided image_name instead of defaulting it.
    45      # Note that fields cannot be overwritten, in other words, you cannot
    46      # set the 'image_name' field in the top-level source block and here at the
    47      # same time
    48      image_name = "build_specific_field"
    49    }
    50  }
    51  ```
    52  
    53  `@include 'from-1.5/contextual-source-variables.mdx'`
    54  
    55  ## Related
    56  
    57  - Refer to the [builders reference overview](/packer/docs/builders) for information about Packer builders.
    58  
    59  - Refer to the [community builders reference](/packer/docs/community-tools#community-builders) for information about builders maintained by the community.
    60  
    61  - Refer to [Create Custom Builders](/packer/docs/plugins/creation/custom-builders) for instructions on how to create your own builders.