You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My particular case is as follow. I'm trying Terraform to manage both GitHub and GitLab, as we migrate from GitHub to GitLab, we need to keep the structure in both in sync. For that, for example, when creating a team, since both usernames in GitHub and GitLab are not the same, I need to do a mapping between one and the other. To avoid having to write a map for every user (we have a lot), as most of the times the username can be inferred by the name of the person, we have a map of exceptions and if the user is not in the map, we "calculate it". Here is the conversion "function": "${lookup(var.members_map, var.members[0], "${lower(replace(var.members[0], " ", "-"))}-suffix")}"
I have the feeling this can be applied to many other use cases.
Attempted Solutions
The only current solution I found is just copy&pasting the whole conversion function every time I need to use a member username.
Proposal
Some way to define custom functions. Maybe like variables:
# args is a special value, like count
function "convert_member" {
result = "${lookup(var.members_map, args[0], "${lower(replace(args[0], " ", "-"))}-suffix")}"
description = "some function"
}
# Usage: "${fun.convert_member(var.members[0]))}"
This is just the first example that came to mind, how are they exactly defined I don't care much, I guess someone that knows the HCL better can come up with a better approach.
Current Terraform Version
Use-cases
My particular case is as follow. I'm trying Terraform to manage both GitHub and GitLab, as we migrate from GitHub to GitLab, we need to keep the structure in both in sync. For that, for example, when creating a team, since both usernames in GitHub and GitLab are not the same, I need to do a mapping between one and the other. To avoid having to write a map for every user (we have a lot), as most of the times the username can be inferred by the name of the person, we have a map of exceptions and if the user is not in the map, we "calculate it". Here is the conversion "function":
"${lookup(var.members_map, var.members[0], "${lower(replace(var.members[0], " ", "-"))}-suffix")}"
More contextualized example:
I have the feeling this can be applied to many other use cases.
Attempted Solutions
The only current solution I found is just copy&pasting the whole conversion function every time I need to use a member username.
Proposal
Some way to define custom functions. Maybe like variables:
This is just the first example that came to mind, how are they exactly defined I don't care much, I guess someone that knows the HCL better can come up with a better approach.
References
The text was updated successfully, but these errors were encountered: