Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eventual consistency issues #3

Merged
merged 1 commit into from
Apr 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
}