Skip to content
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

Extended aws_vpn_gateway use case. #67

Merged
merged 3 commits into from
Feb 10, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ resource "aws_route_table" "public" {
count = "${length(var.public_subnets) > 0 ? 1 : 0}"

vpc_id = "${aws_vpc.this.id}"
propagating_vgws = ["${var.public_propagating_vgws}"]

tags = "${merge(var.tags, var.public_route_table_tags, map("Name", format("%s-public", var.name)))}"
}
Expand All @@ -78,7 +77,6 @@ resource "aws_route_table" "private" {
count = "${max(length(var.private_subnets), length(var.elasticache_subnets), length(var.database_subnets), length(var.redshift_subnets))}"

vpc_id = "${aws_vpc.this.id}"
propagating_vgws = ["${var.private_propagating_vgws}"]

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

Expand Down Expand Up @@ -333,3 +331,24 @@ resource "aws_vpn_gateway" "this" {

tags = "${merge(var.tags, map("Name", format("%s", var.name)))}"
}

resource "aws_vpn_gateway_attachment" "vgw" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename vgw to this. VPN gateway has at most just one attachment.

count = "${var.attach_vpn_gateway != "default" ? 1 : 0}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this PR to support the conditional creation of VPC, which I have introduced earlier today. (count will change in all VPC resources you are adding)


vpc_id = "${aws_vpc.this.id}"
vpn_gateway_id = "${var.attach_vpn_gateway}"
}

resource "aws_vpn_gateway_route_propagation" "public" {
count = "${var.public_propagating_vgws && var.enable_vpn_gateway || var.public_propagating_vgws && var.attach_vpn_gateway != "default " ? length(var.public_subnets) : 0}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar here, as for private


route_table_id = "${element(aws_route_table.public.*.id, count.index)}"
vpn_gateway_id = "${element(concat(aws_vpn_gateway.this.*.id, aws_vpn_gateway_attachment.vgw.*.vpn_gateway_id), count.index)}"
}

resource "aws_vpn_gateway_route_propagation" "private" {
count = "${var.private_propagating_vgws && var.enable_vpn_gateway || var.private_propagating_vgws && var.attach_vpn_gateway != "default" ? length(var.private_subnets) : 0}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

count can be updated like this:

count = "${var.create_vpc && var.propagate_private_route_tables_vgw && (var.enable_vpn_gateway || var.vpn_gateway_id = "") ? length(var.private_subnets) : 0}"


route_table_id = "${element(aws_route_table.private.*.id, count.index)}"
vpn_gateway_id = "${element(concat(aws_vpn_gateway.this.*.id, aws_vpn_gateway_attachment.vgw.*.vpn_gateway_id), count.index)}"
}
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ output "vpc_endpoint_dynamodb_id" {
# VPN Gateway
output "vgw_id" {
description = "The ID of the VPN Gateway"
value = "${element(concat(aws_vpn_gateway.this.*.id, list("")), 0)}"
value = "${element(concat(aws_vpn_gateway.this.*.id, aws_vpn_gateway_attachment.vgw.*.vpn_gateway_id, list("")), 0)}"
}

output "vpc_endpoint_dynamodb_pl_id" {
Expand Down
13 changes: 9 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,19 @@ variable "enable_vpn_gateway" {
default = false
}

variable "attach_vpn_gateway" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vpn_gateway_id is a better name for such variable

description = "ID of VPN Gateway to attach to the VPC"
default = "default"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default = "" is better, because it means "it was not specified".

}

variable "private_propagating_vgws" {
description = "A list of VGWs the private route table should propagate"
default = []
description = "Should be true if you want route table propagation"
default = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable type is changed from list to boolean. Usually, it makes more sense to keep backward compatibility for as long as possible, but here I don't see how we can make it. If you have a suggestion, please tell.

private_propagating_vgws should be renamed to propagate_private_route_tables_vgw (or smth like that).

public_propagating_vgws should be renamed to propagate_public_route_tables_vgw.

}

variable "public_propagating_vgws" {
description = "A list of VGWs the public route table should propagate"
default = []
description = "Should be true if you want route table propagation"
default = false
}

variable "tags" {
Expand Down