Yes! here’s a working config with several examples:
(This is on v1.6.1 which dropped yesterday)
source "amazon-ebs" "basic-example" {
region = "us-east-1"
source_ami_filter {
filters = {
virtualization-type = "hvm"
name = "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*"
root-device-type = "ebs"
}
owners = ["099720109477"]
most_recent = true
}
instance_type = "t2.small"
ssh_username = "ubuntu"
ami_name = "packer_AWS {{timestamp}}"
}
build {
sources = [
"source.amazon-ebs.basic-example"
]
provisioner "shell-local"{
inline = ["echo '${build.SourceAMIName}'"]
environment_vars = ["HELLO_USER=packeruser", "SOURCE_AMI_NAME=${build.SourceAMIName}"]
execute_command = ["/bin/sh", "-c", "echo '${build.SourceAMIName}'", "{{.Vars}} {{.Script}}"]
}
}
edit: this example use SourceAMIName but it will also work for SourceAMI:
use ${build.SourceAMI} if embedding it in a string (most likely), or build.SourceAMI if you’re setting it as a standalone value in an option