Skip to content

Commit

Permalink
Allow vpc peering when accepter doesn't have 1:1 subnet to routing ta…
Browse files Browse the repository at this point in the history
…ble mapping (#3)

* add facility for allowing DNS over multi-account peering

* update the documentation

* trying aknysh's suggestion

* Revert "trying aknysh's suggestion"

This reverts commit 7a3f94c.

* terraform fmt

* Allow this module to work without a 1:1 mapping of subnet to routing table related to fixed in:

hashicorp/terraform-provider-aws#715

* require version >= 1.25

* terraform fmt
  • Loading branch information
chrisdotm authored and aknysh committed Mar 11, 2019
1 parent a803c69 commit bb31edb
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions accepter.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ variable "accepter_allow_remote_vpc_dns_resolution" {

# Accepter's credentials
provider "aws" {
alias = "accepter"
region = "${var.accepter_region}"
alias = "accepter"
region = "${var.accepter_region}"
version = ">= 1.25"

assume_role {
role_arn = "${var.accepter_aws_assume_role_arn}"
Expand Down Expand Up @@ -85,14 +86,14 @@ locals {
}

# Lookup accepter route tables
data "aws_route_table" "accepter" {
count = "${local.enabled ? local.accepter_subnet_ids_count : 0}"
provider = "aws.accepter"
subnet_id = "${element(local.accepter_subnet_ids, count.index)}"
data "aws_route_tables" "accepter" {
count = "${local.count}"
provider = "aws.accepter"
vpc_id = "${local.accepter_vpc_id}"
}

locals {
accepter_aws_route_table_ids = "${distinct(sort(data.aws_route_table.accepter.*.route_table_id))}"
accepter_aws_route_table_ids = "${distinct(sort(data.aws_route_tables.accepter.ids))}"
accepter_aws_route_table_ids_count = "${length(local.accepter_aws_route_table_ids)}"
accepter_cidr_block_associations = "${flatten(data.aws_vpc.accepter.*.cidr_block_associations)}"
accepter_cidr_block_associations_count = "${length(local.accepter_cidr_block_associations)}"
Expand All @@ -105,7 +106,7 @@ resource "aws_route" "accepter" {
route_table_id = "${element(local.accepter_aws_route_table_ids, ceil(count.index / local.requester_cidr_block_associations_count))}"
destination_cidr_block = "${lookup(local.requester_cidr_block_associations[count.index % local.requester_cidr_block_associations_count], "cidr_block")}"
vpc_peering_connection_id = "${join("", aws_vpc_peering_connection.requester.*.id)}"
depends_on = ["data.aws_route_table.accepter", "aws_vpc_peering_connection_accepter.accepter", "aws_vpc_peering_connection.requester"]
depends_on = ["data.aws_route_tables.accepter", "aws_vpc_peering_connection_accepter.accepter", "aws_vpc_peering_connection.requester"]
}

# Accepter's side of the connection.
Expand Down

0 comments on commit bb31edb

Please sign in to comment.