Packer build fails with AMIName but unsure how to troubleshoot

Have been using packer to prep our Vault images for use in AWS. All has gone well so far and I was tagging my base AMI with the version of vault installed and then copying that tag to the environment specific build I needed. This worked well in the same AWS account but when trying to provision to a new account of course the tags are not visible. I then decided to try and add the “{{ .SourceAMITags.Vault_Version }}” in to the AMI name field:

"{{ user `name_tag` }}-{{ user `server_env`}}-{{ user `region_short`}}-{{ .SourceAMITags.Vault_Version}}-{{isotime \"2006-01-02\"}}-{{user `ami_version_number`}}"

But I keep getting this error:

Errors validating build 'amazon-ebs'. 1 error(s) occurred:

* AMIName should only contain alphanumeric characters, parentheses (()), square brackets ([]), spaces ( ), periods (.), slashes (/), dashes (-), single quotes ('), at-signs (@), or underscores(_). You can use the `clean_resource_name` template filter to automatically clean your ami name.

I tried declaring the tag as a variable via:

"vault_version": "{{ .SourceAMITags.Vault_Version }}"

But get the same result. I am also unable to get the vriable to interpolate in the “packer console”. I am guessing there is some illegal character in the packer interpretation of the amitag but I cannot seem to work out how to troubleshoot further and get packer to spit out what it is trying to do. Anyone able to help?

You can use the packer console command https://www.packer.io/docs/commands/console to test out your interpolation