Regarding template engine functions the following two functions should be named and used in a more generic way:
Specific to Amazon builders: clean_ami_name
Specific to Google Compute builders: clean_image_name
These should be renamed to something like clean_amazon_name
and clean_google_cloud_name
. The reason is as follows. For example, all the names and labels for a Google Cloud resource should follow the same rules. They cannot include space, dot, etc. So, one can use clean_image_name
functions to sanitize a label value while the name for the function is confusing!
"builders": [{
"name": "google",
"type": "googlecompute",
"image_labels": {
"packer": "{{packer_version | clean_image_name}}"
}
}]
Going through old issues; sorry for not commenting a year ago. This makes a lot of sense to me and I'd like to see it, but it will have to wait until one of our bigger releases where we allow backwards-incompatible changes.
Looking at this, it looks like we implement each of the functions in builder specific ways (clean_image_name behaves differently depending on whether you're in googlecompute or azure, for example). I think it'd actually be really cool to have a single template function name clean_resource_name
that sanitizes the variable based on whichever cloud is being built from. That would make it very generalizable and abstract away specific cloud weirdness from the Packer template. @azr would love your thoughts on this.
It would still be backwards incompatible and we'd need to write fixers for clean_ami_name and clean_image_name template funcs.
I agree this would be nice for constancy of user experience !! And I think this will just work like a charm if we just rename clean_ami_name
to clean_image_name
. Both func will be defined in different scopes and behave in their own way, without conflicting. I'll try to come up with a quick PR.
Something like this: https://github.com/hashicorp/packer/pull/7456 ?
@azr Thanks for working on this. What about the case that we need a clean string for labels on Google Cloud?
It's already called clean_image_name
and they should not conflict. But may be like @SwampDragons suggested I should just change them both to clean_resource_name
?
I think the latter approach makes more sense and causes less confusion.
Okay I've made the old ones deprecated ( using them logs a warning ) and clean_resource_name
is now available for Azure, AWS & GCP.
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.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Okay I've made the old ones deprecated ( using them logs a warning ) and
clean_resource_name
is now available for Azure, AWS & GCP.