Skip to content

Commit

Permalink
use cidr_block_associations to add additional cidr_blocks to the rout…
Browse files Browse the repository at this point in the history
…es (#6)

* use cidr_block_associations to add additional cidr_blocks to the routes

* Run terraform fmt > add last newline to main.tf
  • Loading branch information
Yudi Phanama authored and aknysh committed Oct 6, 2018
1 parent cffc605 commit 8997e06
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ data "aws_route_table" "acceptor" {

# Create routes from requestor to acceptor
resource "aws_route" "requestor" {
count = "${var.enabled == "true" ? length(distinct(sort(data.aws_route_table.requestor.*.route_table_id))) : 0}"
route_table_id = "${element(distinct(sort(data.aws_route_table.requestor.*.route_table_id)), count.index)}"
destination_cidr_block = "${data.aws_vpc.acceptor.cidr_block}"
count = "${var.enabled == "true" ? length(distinct(sort(data.aws_route_table.requestor.*.route_table_id))) * length(data.aws_vpc.acceptor.cidr_block_associations) : 0}"
route_table_id = "${element(distinct(sort(data.aws_route_table.requestor.*.route_table_id)), (ceil(count.index / (length(data.aws_vpc.acceptor.cidr_block_associations)))))}"
destination_cidr_block = "${lookup(data.aws_vpc.acceptor.cidr_block_associations[count.index % (length(data.aws_vpc.acceptor.cidr_block_associations))], "cidr_block")}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.default.id}"
depends_on = ["data.aws_route_table.requestor", "aws_vpc_peering_connection.default"]
}

# Create routes from acceptor to requestor
resource "aws_route" "acceptor" {
count = "${var.enabled == "true" ? length(distinct(sort(data.aws_route_table.acceptor.*.route_table_id))) : 0}"
route_table_id = "${element(distinct(sort(data.aws_route_table.acceptor.*.route_table_id)), count.index)}"
destination_cidr_block = "${data.aws_vpc.requestor.cidr_block}"
count = "${var.enabled == "true" ? length(distinct(sort(data.aws_route_table.acceptor.*.route_table_id))) * length(data.aws_vpc.requestor.cidr_block_associations) : 0}"
route_table_id = "${element(distinct(sort(data.aws_route_table.acceptor.*.route_table_id)), ceil(count.index / (length(data.aws_vpc.requestor.cidr_block_associations))))}"
destination_cidr_block = "${lookup(data.aws_vpc.requestor.cidr_block_associations[count.index % (length(data.aws_vpc.requestor.cidr_block_associations))], "cidr_block")}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.default.id}"
depends_on = ["data.aws_route_table.acceptor", "aws_vpc_peering_connection.default"]
}

0 comments on commit 8997e06

Please sign in to comment.