First of all, if you keep on using this value: "firehawk-base-amazon-linux-2-{{isotime | clean_resource_name}}-{{uuid}}" things will keep on working, but if you’d like something more “HCL2” I’d so something like that:
For technical reasons, clean_resource_name cannot be re-implemented into Packer HCL2. The isotime is a golang templating specific function and to remain consistent with Terraform we did not import it over, HCL2 does have a timestamp which can be used alongside formatdate to get something better formatted. And if this builds once this should build forever.
Lastly, you could use custom validation rules in input variables to make sure the prefix is valid but since that prefix not meant to change much I wouldn’t do that.
Custom validation rules are going to be available in the next version of Packer. If you want I can give you an example here.
[05:21:10]
[05:21:10] * 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.
[05:21:10]
[05:21:10] on /home/ec2-user/environment/firehawk-main/modules/terraform-aws-vault/examples/bastion-ami/bastion.json.pkr.hcl line 40:
[05:21:10] (source code not available)
[05:21:10]
[05:21:10] Error: 1 error(s) occurred: