'Terraform. Finding combinations for for_each when one of value should be got to know
I would like to create a droplet with each of the provided regions from the already present image (snapshot). But it needs to find out the image ID in each of the regions.
I don't know how to find combinations for for_each when one of the values needs to get to be known.
locals {
regions = toset([
"tor1",
"sgp1",
"sfo3",
"lon1",
"fra1",
"blr1",
"ams3",
"nyc1",
"nyc3",
])
}
Getting image ID in a region
data "digitalocean_droplet_snapshot" "web-snapshot" {
for_each = local.regions
name_regex = "^s-sites"
region = each.key
most_recent = true
}
This code doesn't work. Creates droplet in a region with image IDs in these regions.
resource "digitalocean_droplet" "stop-sites" {
for_each = local.regions
name = "${var.server_name}-${each.key}"
image = 102913678 # we should find the ID of image
region = each.key
size = "s-1vcpu-1gb"
ipv6 = true
backups = false
monitoring = true
droplet_agent = true
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
