-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build fails for valid ami-name #12056
Comments
Hi @sydrawat01 thanks for reaching out. Looking at the provided error messaging it seems like on By chance does the ubuntu version variable contain dots (e.g 22.04)? Dots in the AMI name are not supported so that might be the reason you are seeing the error above. If you remove the dots it should work, assuming there are no other illegal characters. I don't believe the clean_resource_name function works for HCL templates so it seems like a bug to me to mention that.
Data sources are not evaluated when running |
Possible bug here that clearn_resource_name is displayed as an option for HCL builds 👇 We may need to consider adding a clean_resource_name function to HCL or provide guidance on using the regex_replace function https://www.packer.io/docs/templates/hcl_templates/functions/string/regex_replace
|
My version name does not contain dots. Also I think ami_name = "EC2-AMI-${substr(data.git-commit.commit.hash, 0, 8)}" # does not work
tags = {
Name = "EC2-AMI-${substr(data.git-commit.commit.hash, 0, 8)}" # works
}
I don't think there's any invalid character in the commit hash, as the |
Hi @sydrawat01 I took another looks at this issue and I believe I misunderstood. I see you mention both Is it both validate and build that is failing or just validate? If the error is happening solely on
Running a build with a completed template using the provide configuration for the ami_name and ami_description results in a successful build.
I think it might be safe to close this issue but I will keep it open in case you run into the same issue with Packer 1.8.5. Otherwise feel free to close. |
Thanks for the detailed explanation and the fix @nywilken! I used My workflows should now pass successfully! 😁 |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Community Note
While trying to have a dynamic
ami_name
in the packer template, thebuild
command throws an error saying the AMI name is invalid, whereas the variables and locals have valid values of the git branch name and the commit sha. This error occurs while using the packer plugin git-commit.Overview of the Issue
Using the
git-commit
plugin to use the git branch name and commit sha in theami_name
foramazon-ebs
, packervalidate
and build commands fail throwing an error which says that theami_name
contains invalid characters.Reproduction Steps
Create a packer file with a dynamic
ami_name
foramazon-ebs
Run packer
init
,validate
andbuild
commands in successionErrors:
Another interesting thing to notice here is, when I run the
validate -syntax-only
, it runs without errors, verifying there's no issue with the syntax.I'm trying something like this with my packer template.
Packer version
packer version v1.8.3
Simplified Packer Template
Operating system and Environment details
MacOS Monterey (v12.6), Intel i5
The text was updated successfully, but these errors were encountered: