I have a list of subnets IDs and I want to get an array of the cidr_blocks associated to each subnet.
variable "aws_subnet_ids" {
type = list(string)
default = ["subnet-aaaaaaaa","subnet-bbbbbbbb"]
}
desired_output = ['10.0.1.0/24', '10.0.2.0/24']
I've been fiddling around with for loops and count data for a quite a while for what should be a really simple problem. But I'm having a hard time finding an appropriate way to actually do this.
This seemed like a decent example to work off of, but you can't actually use a for_each in a data source off a list of strings. https://www.terraform.io/docs/providers/aws/d/subnet_ids.html
data "aws_subnet" "example" {
for_each = var.aws_subnet_ids
cidr_blocks = each.cidr_block
}
output "subnet_cidr_blocks" {
value = [for s in data.aws_subnet.example : s.cidr_block]
}