Hi All,
I’m trying to figure out how to create dynamic locals by looking up a map value stored in a variable.
More context:
- I’ve got a variable called
all_github_users
that looks like this:
variable "all_github_users" {
type = map(string)
description = "List of all Github users with their emails."
default = {
"user1@company.com" = "their-github-username",
"user2@domain.com" = "another-github-user",
"user3@foo.com" = "yet-another-github-user",
}
}
This essentially contains all the Github usernames in our org.
- My Terraform template users will be asked to supply another variable that will look like this:
variable github_collaborators {
type = map(string)
description = "List of Github usernames that should be added to the new Github repository as collaborators."
default = {
"user1@company.com" = "admin",
"user2@domain.com" = "push"
}
}
The above contains the user emails and their respective Github repo permissions the Terraform user would like to add as repo collaborators.
What I am trying to do then is to create a local variable (local presumably, but it doesn’t matter to me as long as it works) of type map(string)
that would contain the following data (based on the example above):
variable github_usernames_to_add {
type = map(string)
default = {
"their-github-username" = "admin",
"another-github-user" = "push"
}
(I realise that the above is a variable definition, I simply wanted to make the var. type clear)
In short, I simply want to take the github_collaborators
variable and replace emails with Github usernames as mapped in the variable all_github_users
.
Is there a way to do that?
Thank you!