Back to Packer

Contextual Source Variables

website/content/partials/from-1.5/contextual-source-variables.mdx

1.15.3895 B
Original Source

Source Variables

Use the following syntax to access the name and type of your source from provisioners and post-processors:

<build-name>.<source-type>.<source-name>

The following example queries source names used in the build:

hcl
source "null" "first-example" {
  communicator = "none"
}

build {
  name = "roles"

  source "null.first-example" {
    name = "consul"
  }
  source "null.first-example" {
    name = "nomad"
  }
  source "null.first-example" {
    name = "vault"
  }
  sources = ["null.first-example"]

  provisioner "shell-local" {
    inline = ["echo ${source.name} and ${source.type}"]
  }
}

The example returns the following values:

  • roles.null.consul: Returns consul and null
  • roles.null.nomad: Returns nomad and null
  • roles.null.vault: Returns vault and null
  • roles.null.first-example: Returns first-example and null