Skip to content

Commit 2923f1d

Browse files
committed
Fixed aws_vpn_gateway_route_propagation for default route table
1 parent a907849 commit 2923f1d

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

examples/complete-vpc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Complete VPC
33

44
Configuration in this directory creates set of VPC resources which may be sufficient for staging or production environment (look into [simple-vpc](../simple-vpc) for more simplified setup).
55

6-
There are public, private, database, ElastiCache subnets, NAT Gateways created in each availability zone.
6+
There are public, private, database, ElastiCache subnets, NAT and VPN Gateways created across several availability zones.
77

88
Usage
99
=====

examples/complete-vpc/main.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module "vpc" {
1515
create_database_subnet_group = false
1616

1717
enable_nat_gateway = true
18-
enable_vpn_gateway = true
18+
single_nat_gateway = true
1919

2020
enable_s3_endpoint = true
2121
enable_dynamodb_endpoint = true
@@ -24,6 +24,11 @@ module "vpc" {
2424
dhcp_options_domain_name = "service.consul"
2525
dhcp_options_domain_name_servers = ["127.0.0.1", "10.10.0.2"]
2626

27+
enable_vpn_gateway = true
28+
propagate_private_route_tables_vgw = true
29+
propagate_public_route_tables_vgw = true
30+
propagate_default_route_tables_vgw = true
31+
2732
tags = {
2833
Owner = "user"
2934
Environment = "staging"

main.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,13 @@ resource "aws_vpn_gateway_route_propagation" "private" {
359359
vpn_gateway_id = "${element(concat(aws_vpn_gateway.this.*.id, aws_vpn_gateway_attachment.this.*.vpn_gateway_id), count.index)}"
360360
}
361361

362+
resource "aws_vpn_gateway_route_propagation" "default" {
363+
count = "${var.create_vpc && var.propagate_default_route_tables_vgw && (var.enable_vpn_gateway || var.vpn_gateway_id != "") ? 1 : 0}"
364+
365+
route_table_id = "${element(aws_default_route_table.this.*.id, count.index)}"
366+
vpn_gateway_id = "${element(concat(aws_vpn_gateway.this.*.id, aws_vpn_gateway_attachment.this.*.vpn_gateway_id), count.index)}"
367+
}
368+
362369
###########
363370
# Defaults
364371
###########
@@ -378,6 +385,12 @@ resource "aws_default_route_table" "this" {
378385
default_route_table_id = "${aws_vpc.this.default_route_table_id}"
379386

380387
tags = "${merge(var.tags, var.default_route_table_tags, map("Name", format("%s-default", var.name)))}"
388+
389+
lifecycle {
390+
# When attaching VPN gateways it is common to define aws_vpn_gateway_route_propagation
391+
# resources that manipulate the attributes of the routing table (typically for the private subnets)
392+
ignore_changes = ["propagating_vgws"]
393+
}
381394
}
382395

383396
resource "aws_main_route_table_association" "this" {

variables.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,17 @@ variable "vpn_gateway_id" {
113113
}
114114

115115
variable "propagate_private_route_tables_vgw" {
116-
description = "Should be true if you want route table propagation"
116+
description = "Should be true if you want privateroute table propagation"
117117
default = false
118118
}
119119

120120
variable "propagate_public_route_tables_vgw" {
121-
description = "Should be true if you want route table propagation"
121+
description = "Should be true if you want public route table propagation"
122+
default = false
123+
}
124+
125+
variable "propagate_default_route_tables_vgw" {
126+
description = "Should be true if you want default route table propagation"
122127
default = false
123128
}
124129

0 commit comments

Comments
 (0)