github.com/hashicorp/packer@v1.14.3/website/content/partials/from-1.5/contextual-source-variables.mdx (about)

     1  ## Source Variables
     2  
     3  Use the following syntax to access the `name` and `type` of your `source` from provisioners and post-processors:
     4  
     5  ```
     6  <build-name>.<source-type>.<source-name>
     7  ```
     8  
     9  The following example queries source names used in the build:
    10  
    11  ```hcl
    12  source "null" "first-example" {
    13    communicator = "none"
    14  }
    15  
    16  build {
    17    name = "roles"
    18  
    19    source "null.first-example" {
    20      name = "consul"
    21    }
    22    source "null.first-example" {
    23      name = "nomad"
    24    }
    25    source "null.first-example" {
    26      name = "vault"
    27    }
    28    sources = ["null.first-example"]
    29  
    30    provisioner "shell-local" {
    31      inline = ["echo ${source.name} and ${source.type}"]
    32    }
    33  }
    34  ```
    35  
    36  The example returns the following values:
    37  
    38  - `roles.null.consul`: Returns `consul` and `null`
    39  - `roles.null.nomad`: Returns `nomad` and `null`
    40  - `roles.null.vault`: Returns `vault` and `null`
    41  - `roles.null.first-example`: Returns `first-example` and `null`