Terraform code (resources.tf)
We add a second public and a matching private subnet so that we can distribute the production instances across multiple availability zones.
The aws_subnet
resource creates a subnet named public-2
. It takes attributes such as a VPC ID, CIDR BLOCK and AZs, the values of which we pull from variables. To compute the CIDR and AZ values we use Terraform's interpolation functions (ref: https://www.terraform.io/docs/configuration/interpolation.html):
resource "aws_subnet" "public-2" { vpc_id = "${aws_vpc.terraform-vpc.id}" cidr_block = "${cidrsubnet(var.vpc-cidr, 8, 3)}" availability_zone = "${element(split(",",var.aws-availability-zones), count.index + 1)}" map_public_ip_on_launch = true tags { Name = "Public" } }
Next, we...