Created
February 11, 2020 12:45
-
-
Save diasjorge/3737bea2659b8b5c15a10c119f38db5c to your computer and use it in GitHub Desktop.
Gather attributes from a list of subnets with terraform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# terraform aws_subnet return multiple elements | |
data "aws_vpc" "main" { | |
tags = { | |
Name = "your-vpc" | |
} | |
} | |
data "aws_subnet_ids" "main" { | |
vpc_id = data.aws_vpc.main.id | |
} | |
data "aws_subnet" "main" { | |
id = tolist(data.aws_subnet_ids.main.ids)[count.index] | |
count = length(data.aws_subnet_ids.main.ids) | |
} | |
# then you can use them as data.aws_subnet.main.*.availability_zone |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment