Skip to content

Instantly share code, notes, and snippets.

@diasjorge
Created February 11, 2020 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diasjorge/3737bea2659b8b5c15a10c119f38db5c to your computer and use it in GitHub Desktop.
Save diasjorge/3737bea2659b8b5c15a10c119f38db5c to your computer and use it in GitHub Desktop.
Gather attributes from a list of subnets with terraform
# 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