Hi guys,In a CloudFormation template, I can use the built-in function "GetAZs", which AWS expands to a list of the availability zones in the region I'm deploying the template in.
variable aws_vpc_cidr_prefix { default = "172.20" }
variable aws_region { default = "us-east-1" }
variable aws_azs {
default = {
us-east-1 = "us-east-1a,us-east-1c,us-east-1d"
us-west-2 = "us-west-2a,us-west-2b,us-west-2c"
}
}
#
# Each app subnet group is a /21 (172.20.0.0/21)
# each app subnet group is split across up to 4 seperate
# AZ's, i.e. 172.20.[0,4,8,12].0/22
#
# Example:
# gfcp-app -> 172.20.0.0 - 172.20.15.255
# gfcp-app (us-east-1a) -> 172.20.0.0 - 172.20.3.255
# gfcp-app (us-east-1c) -> 172.20.4.0 - 172.20.7.255
# gfcp-app (us-east-1d) -> 172.20.8.0 - 172.20.11.255
# gfcp-app (unused) -> 172.20.12.0 - 172.20.15.255
#
# This configuration gives:
# - 4 AZ's per region (currently only use 3)
# - 16 App networks
# - 4096 IP addresses per App network
# - 1024 IPaddresses per App, per AZ
#
variable aws_appnet_map {
default = {
gfcp-app = "0" # jboss, fuse
gfcp-dmz = "16" # boxes with public and private ips
gfcp-rds = "32" # main databases
gfcp-web = "48" # web-facing, apache ended up in dmz
gfcp-tmp = "64" # temporary instances, like data-pipeline
undef80 = "80" # unused block 80
undef96 = "96" # unused block 96
undef112 = "112" # unused block 112
undef128 = "128" # unused block 128
undef144 = "144" # unused block 144
undef160 = "160" # unused block 160
undef176 = "176" # unused block 176
ops-vpn = "192" # vpn client ips
ops-dmz = "208" # nat boxes, bastion
ops-rds = "224" # ops databases
ops-app = "240" # puppet, rundeck, etc
}
}
resource "aws_subnet" "gfcp-app" {
...
count = "${length(split(",", lookup(var.aws_azs, var.aws_region)))}"
availability_zone = "${element(split(",", lookup(var.aws_azs, var.aws_region)), count.index)}"
cidr_block = "${var.aws_vpc_cidr_prefix}.${lookup(var.aws_appnet_map, "gfcp-app")+(4*count.index)}.0/22"
}
resource "aws_elb" "gfcp-single" {
...
subnets = [ "${aws_subnet.gfcp-app.*.id}" ]
...
}
resource "aws_autoscaling_group" "gfcp-app" {
...
availability_zones = [ "${split(",", lookup(var.aws_azs, var.aws_region))}" ] vpc_zone_identifier = [ "${aws_subnet.gfcp-app.*.id}" ]...
}
variable aws_azs {
default = {
us-east-1 = ["us-east-1a","us-east-1c","us-east-1d"]
us-west-2 = ["us-west-2a","us-west-2b","us-west-2c"]
}
}
lookup(map, key, [default])
- Performs a dynamic lookup into a map variable. The map
parameter should be another variable, such as var.amis
. If key
does not exist in map
, the interpolation will fail unless you specify a third argument, default
, which should be a string value to return if no key
is found in map
. This function only works on flat maps and will return an error for maps that include nested lists or maps.variable "aws_region" {default = "eu-west-1"}variable "aws_availability_zones" {default = {eu-west-1 = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]us-east-1 = ["eu-west-1b", "eu-west-1c", "eu-west-1d", "eu-west-1e"]}}
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/3b0fd539-42c2-41cf-be36-0814a88f4737%40googlegroups.com.