Skip to content

Instantly share code, notes, and snippets.

@mijdavis2
Created March 12, 2019 15:06
Show Gist options
  • Save mijdavis2/0487a21602885cc3113e3249b5bad32a to your computer and use it in GitHub Desktop.
Save mijdavis2/0487a21602885cc3113e3249b5bad32a to your computer and use it in GitHub Desktop.
How to get available AZs in terraform from data and subnet list.
data "aws_availability_zones" "available" {}
# Assuming we vars for list of private_subnet_ids and or public_subnet_ids
# we take a slice of available AZs.
#
# Add or remove private/public vars when necessary.
locals {
available_azs = "${
slice(
data.aws_availability_zones.available.names,
0,
max(length(var.private_subnet_ids), length(var.public_subnet_ids)))
}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment