Skip to content

Commit

Permalink
Adds routing for Transit Gateway VPN attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
danvaida committed May 6, 2020
1 parent f61fe6c commit 34819b6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
7 changes: 7 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ data "aws_ec2_transit_gateway" "this" {
values = [data.aws_ram_resource_share.this.tags.transit-gateway-id]
}
}

data "aws_ec2_transit_gateway_route_table" "this" {
filter {
name = "transit-gateway-id"
values = [data.aws_ec2_transit_gateway.this.id]
}
}
6 changes: 5 additions & 1 deletion examples/complete/variables.auto.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ cgw_bgp_asn = 65000
cgw_ip_address = "1.1.1.1"

transit_gateway_hub_name = "test-tgw-fixture"
static_routes_only = false
static_routes_only = true
static_routes_destinations = [
"192.168.0.0/24",
"192.168.1.0/24"
]

tunnel1_inside_cidr = "169.254.6.0/30"
tunnel2_inside_cidr = "169.254.7.0/30"
Expand Down
19 changes: 15 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,19 @@ resource "aws_vpn_connection" "this" {
tags = merge(var.tags, map("Name", var.name))
}

resource "aws_vpn_connection_route" "this" {
count = var.static_routes_only ? length(var.static_routes_destinations) : 0
vpn_connection_id = aws_vpn_connection.this.id
destination_cidr_block = element(var.static_routes_destinations, count.index)
resource "aws_ec2_transit_gateway_route_table_association" "this" {
transit_gateway_attachment_id = aws_vpn_connection.this.transit_gateway_attachment_id
transit_gateway_route_table_id = data.aws_ec2_transit_gateway_route_table.this.id
}

resource "aws_ec2_transit_gateway_route_table_propagation" "this" {
transit_gateway_attachment_id = aws_vpn_connection.this.transit_gateway_attachment_id
transit_gateway_route_table_id = data.aws_ec2_transit_gateway_route_table.this.id
}

resource "aws_ec2_transit_gateway_route" "this" {
count = var.static_routes_only ? length(var.static_routes_destinations) : 0
destination_cidr_block = element(var.static_routes_destinations, count.index)
transit_gateway_attachment_id = aws_vpn_connection.this.transit_gateway_attachment_id
transit_gateway_route_table_id = data.aws_ec2_transit_gateway_route_table.this.id
}

0 comments on commit 34819b6

Please sign in to comment.