A few months back I wrote about how I built Packer images with Terraform. This week I had to make some changes to one of the projects that use this, and I started receiving a weird error.
Error waiting for AMI. Reason: <nil>
In doing some research, I found that the AMI was taking longer to build than Packer would wait. Apparently, Packer will wait about 30 minutes for the image to become ready before giving up. In my case it was taking just over an hour. I ended up finding a GitHub issue that shared a workaround that involved setting a couple of environmental variables to override the default settings in Packer.
export AWS_MAX_ATTEMPTS=90 export AWS_POLL_DELAY_SECONDS=60
AWS_POLL_DELAY_SECONDS tells Packer to check every 60 seconds, and the
AWS_MAX_ATTEMPTS tells it to check 90 times, for a total of 90 minutes. After adding these two variables to my local-exec code block, my terraform was able to successful create an AMI.