-
Notifications
You must be signed in to change notification settings - Fork 303
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
Use name template variables to customize the name of each resource #234
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @DatsloJRel for opening this pr. I like this idea, but a simple var.group_by_vm_instance
only provides one alternative naming pattern, I'm thinking of a more flexible way.
My thought is providing several naming template variable to render resource's name, so we can customize the template. e.g.:
var.group_by_vm_instance ? join("-", [var.vm_hostname, host_number, "datadisk", data_disk_number]) : join("-", [var.vm_hostname, "datadisk", host_number, data_disk_number])
This expression implied two different templates: ${vm_hostname}-${host_number}-datadisk-${data_disk_number}
&& ${vm_hostname}-datadisk-${host_number}-${data_disk_number}
. We can also assigned a different template, like ${vm_hostname}-${host_number}-dd-${data_disk_number}
.
The problem is, Terraform is lacking of templatestring
function like templatefile
do. So a possible way is to use multiple replace
, like this comment suggested:
replace(replace(replace(var.data_disk_name_template, "${vm_hostname}", var.vm_hostname), "${host_number}", hostnumber), "${data_disk_number}", data_disk_number)
Meanwhile the default value for this var.data_disk_name_template
is ${vm_hostname}-datadisk-${host_number}-${data_disk_number}
. You can customize your template as you like.
Remove the `group_by_vm_instance` and use `*_name_template` variable for each resource to fully customize the name
@lonegunmanb Thanks for the suggestion of using In total, there are now 10 new variables for the name templates:
It is unfortunate that |
@lonegunmanb If you would prefer to group the 10 |
@DatsloJRel Wow thanks for your careful consideration! I like the |
@lonegunmanb I will update the PR to name as As for using For example, try this:
Results in this error:
|
@lonegunmanb There is no rule that we need to use |
@lonegunmanb The PR has been updated for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @DatsloJRel, LGTM! 🚀
Describe your changes
Added the ability to optionally name resources using variables for name templates. This allows each resource created to have a custom name.
Checklist before requesting a review
CHANGELOG.md
file