Have a unique question, that I can't solve (maybe I can't do what I want).
Designing a VPC module, I have a variable availability_zones which defines which AZ to create subnets in. I want the default to be all availability zones in the region the VPC is being created in. Otherwise the user can supply the list of AZ to deploy into.
However I can't do variable interpolation within a variable. I was trying to do something like
data "availabiilty_zones" "all" {}
variable "availability_zones" {
type = "list"
default = "${data.availability_zones.all.names}"
}
That fails since you can't do interpolation here.
Within the actual resource creation I use the variable availablity_zones in many places, as an example
resource "aws_subnet" "private" {
count = "${length(var.availability_zones)}"
cidr_block = "${cidrsubnet(aws_vpc.environment.cidr_block, var.cidr_block_bits, length(var.availability_zones) + count.index)}"
/* load balance over all availability zones */
availability_zone = "${element(var.availability_zones, count.index)}"
/* private subnet, no public IPs */
map_public_ip_on_launch = false
/* merge all the tags together */
tags = "${merge(var.tags, var.private_subnet_tags, map("Name", format("private-%d.%s", count.index,
var.name)), map("builtWith", "terraform"))}"
}
I could replace all var.availablity_zones with a conditional CONDITIONAL ? TRUE : FALSE but that will get kind of ugly repeating that over and over.
What I am basically looking for is a way to set that one place, and then just use it later on.