Is anyone using terraform to build packer images and use the ami produced as output?

I’m hoping to use terraform to build images with Packer. I like the idea of idempotently ensuring the ami’s are built only if they don’t exist or the template file content has changed, and producing an output with the ami. I’m sure I can figure it out but I was hoping it would be a more common workflow, perhaps even a packer resource type… Any thoughts?

Unfortunately, I don’t think such a resource currently exists. We are thinking about the prospect of using Packer output as a Terraform data source, but that product idea is still in the “thinking” stage and it will be some time before we move on to implementation.

1 Like

No worries, it looks like I can get close enough by generating a json manifest and passing the result in with a bash env var

export PKR_VAR_bastion_centos7_ami="$(jq -r '.builds[] | select(.name == "centos7-ami") | .artifact_id' modules/terraform-aws-vault/examples/bastion-ami/manifest.json | tail -1 | cut -d ":" -f2)"