Skip to content

Commit a907849

Browse files
robh007antonbabenko
authored andcommitted
Extended aws_vpn_gateway use case. (terraform-aws-modules#67)
* Extended aws_vpn_gateway use case * Fixed warning from outputs on vgw_id
1 parent e651b0b commit a907849

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

main.tf

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ resource "aws_internet_gateway" "this" {
6262
resource "aws_route_table" "public" {
6363
count = "${var.create_vpc && length(var.public_subnets) > 0 ? 1 : 0}"
6464

65-
vpc_id = "${aws_vpc.this.id}"
66-
propagating_vgws = ["${var.public_propagating_vgws}"]
65+
vpc_id = "${aws_vpc.this.id}"
6766

6867
tags = "${merge(var.tags, var.public_route_table_tags, map("Name", format("%s-public", var.name)))}"
6968
}
@@ -83,8 +82,7 @@ resource "aws_route" "public_internet_gateway" {
8382
resource "aws_route_table" "private" {
8483
count = "${var.create_vpc && local.max_subnet_length > 0 ? local.max_subnet_length : 0}"
8584

86-
vpc_id = "${aws_vpc.this.id}"
87-
propagating_vgws = ["${var.private_propagating_vgws}"]
85+
vpc_id = "${aws_vpc.this.id}"
8886

8987
tags = "${merge(var.tags, var.private_route_table_tags, map("Name", format("%s-private-%s", var.name, element(var.azs, count.index))))}"
9088

@@ -340,6 +338,27 @@ resource "aws_vpn_gateway" "this" {
340338
tags = "${merge(var.tags, map("Name", format("%s", var.name)))}"
341339
}
342340

341+
resource "aws_vpn_gateway_attachment" "this" {
342+
count = "${var.vpn_gateway_id != "" ? 1 : 0}"
343+
344+
vpc_id = "${aws_vpc.this.id}"
345+
vpn_gateway_id = "${var.vpn_gateway_id}"
346+
}
347+
348+
resource "aws_vpn_gateway_route_propagation" "public" {
349+
count = "${var.create_vpc && var.propagate_public_route_tables_vgw && (var.enable_vpn_gateway || var.vpn_gateway_id != "") ? 1 : 0}"
350+
351+
route_table_id = "${element(aws_route_table.public.*.id, count.index)}"
352+
vpn_gateway_id = "${element(concat(aws_vpn_gateway.this.*.id, aws_vpn_gateway_attachment.this.*.vpn_gateway_id), count.index)}"
353+
}
354+
355+
resource "aws_vpn_gateway_route_propagation" "private" {
356+
count = "${var.create_vpc && var.propagate_private_route_tables_vgw && (var.enable_vpn_gateway || var.vpn_gateway_id != "") ? length(var.private_subnets) : 0}"
357+
358+
route_table_id = "${element(aws_route_table.private.*.id, count.index)}"
359+
vpn_gateway_id = "${element(concat(aws_vpn_gateway.this.*.id, aws_vpn_gateway_attachment.this.*.vpn_gateway_id), count.index)}"
360+
}
361+
343362
###########
344363
# Defaults
345364
###########

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ output "vpc_endpoint_dynamodb_id" {
181181
# VPN Gateway
182182
output "vgw_id" {
183183
description = "The ID of the VPN Gateway"
184-
value = "${element(concat(aws_vpn_gateway.this.*.id, list("")), 0)}"
184+
value = "${element(concat(aws_vpn_gateway.this.*.id, aws_vpn_gateway_attachment.this.*.vpn_gateway_id, list("")), 0)}"
185185
}
186186

187187
output "vpc_endpoint_dynamodb_pl_id" {

variables.tf

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,19 @@ variable "enable_vpn_gateway" {
107107
default = false
108108
}
109109

110-
variable "private_propagating_vgws" {
111-
description = "A list of VGWs the private route table should propagate"
112-
default = []
110+
variable "vpn_gateway_id" {
111+
description = "ID of VPN Gateway to attach to the VPC"
112+
default = ""
113113
}
114114

115-
variable "public_propagating_vgws" {
116-
description = "A list of VGWs the public route table should propagate"
117-
default = []
115+
variable "propagate_private_route_tables_vgw" {
116+
description = "Should be true if you want route table propagation"
117+
default = false
118+
}
119+
120+
variable "propagate_public_route_tables_vgw" {
121+
description = "Should be true if you want route table propagation"
122+
default = false
118123
}
119124

120125
variable "tags" {

0 commit comments

Comments
 (0)