-
-
Notifications
You must be signed in to change notification settings - Fork 109
Peer VPCs across AWS Accounts and Regions #71
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
Open
Eric Thompson (ethompsy)
wants to merge
13
commits into
cloudposse:main
Choose a base branch
from
sonatype:multi_region_and_account
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3d3221b
try this
ethompsy cd05a0a
try this
ethompsy 1df33d1
try this
ethompsy 9c7eed1
try this
ethompsy 6b26223
alias both aws providers
ethompsy 533ef44
fixing the pcx
ethompsy 3e99d2d
fixing the pcx
ethompsy 0cf06f1
fixing the pcx
ethompsy d11f499
fixing the pcx
ethompsy 61ded73
fixing the pcx
ethompsy 448fee1
fixing the pcx
ethompsy 6839ebc
fixing the pcx
ethompsy e441923
Merge branch 'main' into multi_region_and_account
ethompsy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,7 @@ | |
|
|
||
| .build-harness | ||
| build-harness/ | ||
|
|
||
| # IDE files | ||
| .vscode | ||
| .history | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,83 @@ | ||
| resource "aws_vpc_peering_connection" "default" { | ||
| provider = aws.requestor | ||
| count = module.this.enabled ? 1 : 0 | ||
| vpc_id = join("", data.aws_vpc.requestor[*].id) | ||
| peer_vpc_id = join("", data.aws_vpc.acceptor[*].id) | ||
| peer_owner_id = data.aws_caller_identity.acceptor[0].account_id | ||
| peer_region = data.aws_region.acceptor[0].name | ||
| auto_accept = false | ||
|
|
||
| auto_accept = var.auto_accept | ||
| tags = module.this.tags | ||
|
|
||
| accepter { | ||
| allow_remote_vpc_dns_resolution = var.acceptor_allow_remote_vpc_dns_resolution | ||
| timeouts { | ||
| create = var.create_timeout | ||
| update = var.update_timeout | ||
| delete = var.delete_timeout | ||
| } | ||
| } | ||
|
|
||
| # Options must be added after PCX is active | ||
| resource "aws_vpc_peering_connection_options" "default" { | ||
| provider = aws.requestor | ||
| count = module.this.enabled ? 1 : 0 | ||
| vpc_peering_connection_id = aws_vpc_peering_connection.default[0].id | ||
|
|
||
| requester { | ||
| allow_remote_vpc_dns_resolution = var.requestor_allow_remote_vpc_dns_resolution | ||
| } | ||
|
|
||
| tags = module.this.tags | ||
| depends_on = [aws_vpc_peering_connection_accepter.default] | ||
| } | ||
|
|
||
| timeouts { | ||
| create = var.create_timeout | ||
| update = var.update_timeout | ||
| delete = var.delete_timeout | ||
| # Accepter's side of the connection. | ||
| resource "aws_vpc_peering_connection_accepter" "default" { | ||
| provider = aws.acceptor | ||
| count = module.this.enabled ? 1 : 0 | ||
| vpc_peering_connection_id = aws_vpc_peering_connection.default[0].id | ||
| auto_accept = var.auto_accept | ||
|
|
||
| accepter { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using |
||
| allow_remote_vpc_dns_resolution = var.acceptor_allow_remote_vpc_dns_resolution | ||
| } | ||
|
|
||
| tags = module.this.tags | ||
| } | ||
|
|
||
| data "aws_region" "acceptor" { | ||
| count = module.this.enabled ? 1 : 0 | ||
| provider = aws.acceptor | ||
| } | ||
|
|
||
| data "aws_caller_identity" "acceptor" { | ||
| count = module.this.enabled ? 1 : 0 | ||
| provider = aws.acceptor | ||
| } | ||
|
|
||
| # Lookup requestor VPC so that we can reference the CIDR | ||
| data "aws_vpc" "requestor" { | ||
| provider = aws.requestor | ||
| count = module.this.enabled ? 1 : 0 | ||
| id = var.requestor_vpc_id | ||
| tags = var.requestor_vpc_tags | ||
| } | ||
|
|
||
| # Lookup acceptor VPC so that we can reference the CIDR | ||
| data "aws_vpc" "acceptor" { | ||
| count = module.this.enabled ? 1 : 0 | ||
| id = var.acceptor_vpc_id | ||
| tags = var.acceptor_vpc_tags | ||
| provider = aws.acceptor | ||
| count = module.this.enabled ? 1 : 0 | ||
| id = var.acceptor_vpc_id | ||
| tags = var.acceptor_vpc_tags | ||
| } | ||
|
|
||
| data "aws_route_tables" "requestor" { | ||
| provider = aws.requestor | ||
| count = module.this.enabled ? 1 : 0 | ||
| vpc_id = join("", data.aws_vpc.requestor[*].id) | ||
| tags = var.requestor_route_table_tags | ||
| } | ||
|
|
||
| data "aws_route_tables" "acceptor" { | ||
| provider = aws.acceptor | ||
| count = module.this.enabled ? 1 : 0 | ||
| vpc_id = join("", data.aws_vpc.acceptor[*].id) | ||
| tags = var.acceptor_route_table_tags | ||
|
|
@@ -59,6 +94,7 @@ locals { | |
|
|
||
| # Create routes from requestor to acceptor | ||
| resource "aws_route" "requestor" { | ||
| provider = aws.requestor | ||
| count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.requestor[0].ids))) * length(local.acceptor_cidr_blocks) : 0 | ||
| route_table_id = element(distinct(sort(data.aws_route_tables.requestor[0].ids)), ceil(count.index / length(local.acceptor_cidr_blocks))) | ||
| destination_cidr_block = local.acceptor_cidr_blocks[count.index % length(local.acceptor_cidr_blocks)] | ||
|
|
@@ -68,6 +104,7 @@ resource "aws_route" "requestor" { | |
|
|
||
| # Create routes from acceptor to requestor | ||
| resource "aws_route" "acceptor" { | ||
| provider = aws.acceptor | ||
| count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.acceptor[0].ids))) * length(local.requestor_cidr_blocks) : 0 | ||
| route_table_id = element(distinct(sort(data.aws_route_tables.acceptor[0].ids)), ceil(count.index / length(local.requestor_cidr_blocks))) | ||
| destination_cidr_block = local.requestor_cidr_blocks[count.index % length(local.requestor_cidr_blocks)] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically, this one won't be needed for the same account/same region case, as it will be treated as the same resource as requester by AWS. For this very reason, the multi-account module exhibits incorrect behavior, trying to rewrite requester tags with accepter tags and vice versa with every next plan/apply cycle, never reaching state convergence. Here, you're using same tags for both requester and accepter, so shouldn't be an issue, however this will break compatibility with multi-account module, if someone tries to migrate from it to this reworked module.