Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Dynamically lanuch subnets into multiple AZs
Browse files Browse the repository at this point in the history
This update allows the module to discover the available AZs on an account and use them when deploying subnets.
  • Loading branch information
skenmy authored Sep 20, 2017
1 parent 26372f6 commit b09319a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
data "aws_availability_zones" "available" {
state = "available"
}

### AWS VPC
resource "aws_vpc" "vpc" {
cidr_block = "${var.vpc_cidr_range}"
Expand Down Expand Up @@ -26,9 +30,10 @@ resource "aws_internet_gateway" "internet" {
### Private Subnets
# Loop over this as many times as necessary to create the correct number of Private Subnets
resource "aws_subnet" "private_subnet" {
count = "${var.availability_zones_count}"
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "${element(var.private_subnets, count.index)}"
count = "${var.availability_zones_count}"
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "${element(var.private_subnets, count.index)}"
availability_zone = "${element(data.aws_availability_zones.available.names, count.index)}"

tags {
Environment = "${var.environment}"
Expand All @@ -41,9 +46,10 @@ resource "aws_subnet" "private_subnet" {
### Public Subnets
# Loop over this as many times as necessary to create the correct number of Public Subnets
resource "aws_subnet" "public_subnet" {
count = "${var.availability_zones_count}"
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "${element(var.public_subnets, count.index)}"
count = "${var.availability_zones_count}"
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "${element(var.public_subnets, count.index)}"
availability_zone = "${element(data.aws_availability_zones.available.names, count.index)}"

tags {
Environment = "${var.environment}"
Expand Down

0 comments on commit b09319a

Please sign in to comment.