Skip to content

Commit

Permalink
Fix eventual consistency issues (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
aknysh authored Apr 6, 2018
1 parent e3e1081 commit aac934e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@ data "aws_vpc" "requestor" {
id = "${var.requestor_vpc_id}"
}

# Lookup requestor subnets
data "aws_subnet_ids" "requestor" {
vpc_id = "${var.requestor_vpc_id}"
}

# Lookup requestor route tables
data "aws_route_table" "requestor" {
count = "${var.enabled == "true" ? length(distinct(sort(data.aws_subnet_ids.requestor.ids))) : 0}"
subnet_id = "${element(distinct(sort(data.aws_subnet_ids.requestor.ids)), count.index)}"
}

# Lookup requestor subnets
data "aws_subnet_ids" "requestor" {
count = "${var.enabled == "true" ? 1 : 0}"
vpc_id = "${data.aws_vpc.requestor.id}"
}

# Lookup acceptor VPC so that we can reference the CIDR
data "aws_vpc" "acceptor" {
count = "${var.enabled == "true" ? 1 : 0}"
Expand All @@ -52,7 +53,8 @@ data "aws_vpc" "acceptor" {

# Lookup acceptor subnets
data "aws_subnet_ids" "acceptor" {
vpc_id = "${var.acceptor_vpc_id}"
count = "${var.enabled == "true" ? 1 : 0}"
vpc_id = "${data.aws_vpc.acceptor.id}"
}

# Lookup acceptor route tables
Expand All @@ -61,18 +63,20 @@ data "aws_route_table" "acceptor" {
subnet_id = "${element(distinct(sort(data.aws_subnet_ids.acceptor.ids)), count.index)}"
}

# Create a route from requestor to 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}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.default.id}"
depends_on = ["data.aws_route_table.requestor", "aws_vpc_peering_connection.default"]
}

# Create a route from acceptor to requestor
# 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}"
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 aac934e

Please sign in to comment.