'Terraform Convert map output from module to list to use in other module
I managed to use for_each to create resources in regions based on a given array. Now I want to use the output URNs to assign the resources to a project in Digital Ocean. The problem is that the way I output the URNs for the resources creates a map while the project_resources resource can only use lists of strings.
My code:
output.tf
output "droplet_urns" {
value = tomap({
for k, drops in digitalocean_droplet.web : k => drops.urn
})
}
How can I convert the map into a list or use the value based on the key? I’m using Terraform v1.1.9
Solution 1:[1]
You can use the keys function to get list with all they keys from the map. Also, you can use the values function to get a list with all the values from a map.
You would probably need something like:
resource "digitalocean_project_resources" "barfoo" {
project = data.digitalocean_project.foo.id
resources = values(module.my_module.droplet_urns)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ervin Szilagyi |
