»The source block

A source block nested in a build block allows to use an already defined source and to set specific fields.

# builds.pkr.hcl
source "lxd" "arch" {
  image = "archlinux"
}

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" ]
  }
}

This allows to have commonly defined source settings with specific parts of it defined inside the specific build block.