Skip to content

Commit

Permalink
fixing subnet configuration (#16)
Browse files Browse the repository at this point in the history
* fixing subnet configuration

* adding readme and fixing route_table count
  • Loading branch information
Luca Venturelli authored Aug 7, 2017
1 parent 444fa64 commit 655b8fc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Creates a number of subnets and divides them in different parts based on the inp
* [`project`]: String(required): the name of the project these subnets belong to
* [`environment`]: String(required): the name of the environment these subnets belong to (prod,stag,dev)
* [`num_subnets`]: String(optional): default to 3. the number of subnets we want to create
* [`route_tables`]: List(optional): the list of route tables to associate to the created subnet. This will associate the route table to the created subnet sequentially. If the subnet number is greater than the number of route tables, the route table will be selected using a standard mod algorithm
* [`num_route_tables`]: String(optional): default to 0. the number of route tables passed in route_tables. NOTE: this is due to a bug in terraform that cannot iterate over count param

### Output
* [`ids`]: List: the ids of the subnets created
Expand Down Expand Up @@ -77,7 +79,6 @@ It will also create the required route tables for the private subnets. The priva
* [`netnum_private_app`]: String(optional): default to 20. First number of subnet to start of for private_app subnets
* [`netnum_private_db`]: String(optional): default to 30. First number of subnet to start of for private_db subnets
* [`tags`]: Map(optional): optional tags
* [`route_tables`]: List(optional): the list of route tables to associate to the created subnet. This will associate the route table to the created subnet sequentially. If the subnet number is greater than the number of route tables, the route table will be selected using a standard mod algorithm


### Output:
Expand Down
2 changes: 1 addition & 1 deletion subnets/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resource "aws_subnet" "subnets" {
}

resource "aws_route_table_association" "subnet_association" {
count = "${length(var.route_tables) >0 ? "${var.num_subnets}" : 0 }"
count = "${var.num_route_tables >0 ? "${var.num_subnets}" : 0 }"
subnet_id = "${element(aws_subnet.subnets.*.id, count.index)}"
route_table_id = "${element(var.route_tables, count.index)}"
}
3 changes: 3 additions & 0 deletions subnets/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ variable "route_tables" {
type = "list"
default = []
}
variable "num_route_tables" {
default = "0"
}
5 changes: 5 additions & 0 deletions vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module "public_nat-bastion_subnets" {
project = "${var.project}"
tags = "${var.tags}"
route_tables = "${aws_route_table.public.*.id}"
num_route_tables = "1"
}

module "public_lb_subnets" {
Expand All @@ -37,6 +38,7 @@ module "public_lb_subnets" {
project = "${var.project}"
tags = "${var.tags}"
route_tables = "${aws_route_table.public.*.id}"
num_route_tables = "1"
}

module "private_app_subnets" {
Expand All @@ -51,6 +53,7 @@ module "private_app_subnets" {
project = "${var.project}"
tags = "${var.tags}"
route_tables = "${aws_route_table.private.*.id}"
num_route_tables = "${var.number_private_rt}"
}

module "private_db_subnets" {
Expand All @@ -65,6 +68,7 @@ module "private_db_subnets" {
project = "${var.project}"
tags = "${var.tags}"
route_tables = "${aws_route_table.private.*.id}"
num_route_tables = "${var.number_private_rt}"
}

module "private_management_subnets" {
Expand All @@ -79,6 +83,7 @@ module "private_management_subnets" {
project = "${var.project}"
tags = "${var.tags}"
route_tables = "${aws_route_table.private.*.id}"
num_route_tables = "${var.number_private_rt}"
}

# Create internet gateway
Expand Down

0 comments on commit 655b8fc

Please sign in to comment.