-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/existing transit gateway support #24
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
base: master
Are you sure you want to change the base?
Changes from all commits
860534e
44a79d5
694c0aa
f838fc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| resource "aws_ram_resource_share" "default" { | ||
| count = var.transit_gateway_enabled ? 1 : 0 | ||
| count = var.transit_gateway_enabled || var.transit_gateway_id != null ? 1 : 0 | ||
|
|
||
| name = "${var.name}-tgw-ram" | ||
| allow_external_principals = true | ||
|
|
@@ -14,14 +14,14 @@ resource "aws_ram_resource_share" "default" { | |
| } | ||
|
|
||
| resource "aws_ram_resource_association" "default" { | ||
| count = var.transit_gateway_enabled ? 1 : 0 | ||
| count = var.transit_gateway_enabled || var.transit_gateway_id != null ? 1 : 0 | ||
|
|
||
| resource_arn = aws_ec2_transit_gateway.default[0].arn | ||
| resource_arn = var.transit_gateway_id != null ? "arn:aws:ec2:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:transit-gateway/${var.transit_gateway_id}" : aws_ec2_transit_gateway.default[0].arn | ||
|
||
| resource_share_arn = aws_ram_resource_share.default[0].arn | ||
| } | ||
|
|
||
| resource "aws_ram_principal_association" "default" { | ||
| count = var.transit_gateway_enabled && var.ram_organization_association ? 1 : 0 | ||
| count = (var.transit_gateway_enabled || var.transit_gateway_id != null) && var.ram_organization_association ? 1 : 0 | ||
|
|
||
| principal = data.aws_organizations_organization.default.arn | ||
| resource_share_arn = aws_ram_resource_share.default[0].arn | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| resource "aws_ec2_transit_gateway" "default" { | ||
| count = var.transit_gateway_enabled ? 1 : 0 | ||
| count = var.transit_gateway_id == null && var.transit_gateway_enabled ? 1 : 0 | ||
|
||
|
|
||
| description = "${var.name}-transit-gateway" | ||
| amazon_side_asn = var.transit_gateway_asn | ||
|
|
@@ -22,7 +22,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "default" { | |
| count = try(var.attachment, false) ? 1 : 0 | ||
|
|
||
| subnet_ids = var.subnet_ids | ||
| transit_gateway_id = data.aws_ec2_transit_gateway.default[0].id | ||
| transit_gateway_id = local.transit_gateway_id | ||
| vpc_id = var.vpc_id | ||
| dns_support = var.dns_support | ||
| security_group_referencing_support = var.security_group_referencing_support | ||
|
|
@@ -40,7 +40,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "default" { | |
| } | ||
|
|
||
| resource "aws_ec2_transit_gateway_route" "blackhole" { | ||
| count = var.transit_gateway_enabled ? 1 : 0 | ||
| count = var.transit_gateway_id == null && var.transit_gateway_enabled ? 1 : 0 | ||
|
|
||
| destination_cidr_block = "0.0.0.0/0" | ||
| blackhole = length(var.public_route) > 0 ? false : true | ||
|
|
||
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.
When
var.transit_gateway_idis null andvar.transit_gateway_enabledis false, this referencesdata.aws_ec2_transit_gateway.default[0].id, but the data source only hascount = try(var.attachment, false) ? 1 : 0in _data.tf. Ifvar.attachmentis false, the data source won't exist, causing an index out of bounds error.