Could not set variables on the command line with command substitution

Hello there!

I’m trying to build an application image from the golden image (AMI ID). But, if I variablize the source AMI ID, it ended up with some errors.


  • export source_ami=ami-02961139e1c00ed16
  • packer build -machine-readable -var aws_source_ami="$source_ami" app_image.json

NOT Working:

  • export source_ami=$(curl -ks GET https://consul01/v1/kv/os/base/images/base/rhel_7.7/20200422?raw)
  • packer build -machine-readable -var aws_source_ami="$source_ami" app_image.json

Packer log:

In between, I thought of using the consul_key function, but even that throws an error like Error initializing core: error interpolating default value for 'aws_source_ami': template: root:1: function "consul_key" not defined. I’m not sure if it is the correct way to use it. Please suggest on that too.


	"variables": {
		"aws_source_ami"   : "{{consul_key `os/base/images/base/rhel_7.7/20200422`}}",

	"description"          : "This will create the baked VM image",
	 "builders": [{
		"source_ami"       : "{{user `aws_source_ami`}}"

packer build -machine-readable app_image.json