Skip to content

Commit

Permalink
Merge pull request #17 from unifio/vgw-prop-support
Browse files Browse the repository at this point in the history
VGW route propagation support
  • Loading branch information
blakeneyops committed Jun 8, 2016
2 parents 8632644 + c6244bf commit 6134b64
Show file tree
Hide file tree
Showing 16 changed files with 159 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Unreleased

## 0.2.3 (June 8, 2016)

#### IMPROVEMENTS:
* Added support for VGW route propagation for routing tables.
* Added support for VPG creation without VPC attachment. Necessary to avoid chicken-and-egg scenario when configuring VPC for VPG route propagation.

## 0.2.2 (June 2, 2016)

#### IMPROVEMENTS:
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ The Base module provisions the VPC, attaches an Internet Gateway, and creates NA
- `enable_hostnames` - (Optional) Specifies whether the instances launched in the VPC get DNS hostnames. Defaults to true.
- `enable_classiclink` - (Optional) Specifies whether ClassicLink is enabled for the VPC. Defaults to false.
- `flow_log_traffic_type` - (Optional) The type of traffic to capture. Valid values: ACCEPT,REJECT,ALL.
- `rt_vgw_prop` - (Optional) Specifies whether virtual gateway route propagation should be enabled on the routing table(s). Valid values: 0 or 1. Defaults to 0 (disabled).
- `vgw_ids` - (Optional) A list of virtual gateways to associate with the routing tables for route propagation.


### Usage ###
Expand Down Expand Up @@ -93,6 +95,7 @@ Creates a VPC VPN Gateway

- `stack_item_label` - Short form identifier for this stack. This value is used to create the "Name" resource tag for resources created by this stack item, and also serves as a unique key for re-use.
- `stack_item_fullname` - Long form descriptive name for this stack item. This value is used to create the "application" resource tag for resources created by this stack item.
- `vpc_attach` - Specifies whether the VPG should be associated with a VPC. Valid value: 0 or 1. Defaults to 0 (unattached).
- `vpc_id` - The VPC to associate the VPG with.

### Usage
Expand All @@ -102,6 +105,7 @@ The usage examples may assume that previous modules in this stack have already b
```js
module "vpg" {
source = "github.com/terraform-aws-vpc//vpg"
vpc_attach = 1
vpc_id = "${module.vpc_base.vpc_id}"
stack_item_fullname = "Stack Item Description"
stack_item_label = "mystack1"
Expand All @@ -128,6 +132,8 @@ In each Availability Zone provided, this module provisions subnets and routing t
- `lans_per_az` - (Optional) The number of private LAN subnets to be provisioned per AZ. You will need to double the CIDR blocks specified in the `lan_cidr` variable for each increase in this value. Defaults to 1.
- `enable_dmz_public_ips` - (Optional) Specify true to indicate that instances launched into the DMZ subnet should be assigned a public IP address. Defaults to true.
- `rt_dmz_id` - The ID of the DMZ routing table.
- `rt_vgw_prop` - (Optional) Specifies whether virtual gateway route propagation should be enabled on the routing table(s). Valid values: 0 or 1. Defaults to 0 (disabled).
- `vgw_ids` - (Optional) A list of virtual gateways to associate with the routing tables for route propagation.

### Usage ###

Expand All @@ -146,6 +152,8 @@ module "AZs" {
lans_per_az = "1"
enable_dmz_public_ips = true
rt_dmz_id = "${module.vpc_base.rt_dmz_id}"
rt_vgw_prop = 1
vgw_ids = "${aws_vpn_gateway.vpg.id}"
}
```

Expand Down
18 changes: 9 additions & 9 deletions az/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ resource "aws_subnet" "lan" {
}

### Provisions routing table
resource "aws_route_table" "rt_lan" {
count = "${length(split(",",var.az)) * var.lans_per_az}"
vpc_id = "${var.vpc_id}"
module "rt_lan" {
source = "../rt"

tags {
Name = "${var.stack_item_label}-lan-${count.index}"
application = "${var.stack_item_fullname}"
managed_by = "terraform"
}
rt_count = "${length(split(",",var.az)) * var.lans_per_az}"
stack_item_label = "${var.stack_item_label}-lan"
stack_item_fullname = "${var.stack_item_fullname}"
vpc_id = "${var.vpc_id}"
vgw_prop = "${signum(var.rt_vgw_prop)}"
vgw_ids = "${var.vgw_ids}"
}

### Associates subnet with routing table
resource "aws_route_table_association" "rta_lan" {
count = "${length(split(",",var.az)) * var.lans_per_az}"
subnet_id = "${element(aws_subnet.lan.*.id,count.index)}"
route_table_id = "${element(aws_route_table.rt_lan.*.id,count.index)}"
route_table_id = "${element(split(",",module.rt_lan.rt_id),count.index)}"
}
2 changes: 1 addition & 1 deletion az/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ output "nat_id" {

## Returns the routing table ID
output "rt_lan_id" {
value = "${join(",",aws_route_table.rt_lan.*.id)}"
value = "${module.rt_lan.rt_id}"
}
12 changes: 12 additions & 0 deletions az/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,15 @@ variable "rt_dmz_id" {
type = "string"
description = "The ID of the DMZ routing table"
}

variable "rt_vgw_prop" {
type = "string"
description = "Specifies whether virtual gateway route propagation should be enabled on the routing table(s)"
default = 0
}

variable "vgw_ids" {
type = "string"
description = "A list of virtual gateways to associate with the routing tables for route propagation."
default = ""
}
15 changes: 8 additions & 7 deletions base/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ resource "aws_internet_gateway" "igw" {
}

## Provisions DMZ routing table
resource "aws_route_table" "rt_dmz" {
vpc_id = "${aws_vpc.vpc.id}"
module "rt_dmz" {
source = "../rt"

tags {
Name = "${var.stack_item_label}-dmz"
application = "${var.stack_item_fullname}"
managed_by = "terraform"
}
rt_count = 1
stack_item_label = "${var.stack_item_label}-dmz"
stack_item_fullname = "${var.stack_item_fullname}"
vpc_id = "${aws_vpc.vpc.id}"
vgw_prop = "${signum(var.rt_vgw_prop)}"
vgw_ids = "${var.vgw_ids}"
}

## Provisions VPC flow log
Expand Down
3 changes: 2 additions & 1 deletion base/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ output "igw_id" {

## Returns ID of the DMZ routing table
output "rt_dmz_id" {
value = "${aws_route_table.rt_dmz.id}"
value = "${module.rt_dmz.rt_id}"
}

## Returns ID of the VPC flow log
output "flow_log_id" {
value = "${aws_flow_log.flow_log.id}"
}
12 changes: 12 additions & 0 deletions base/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ variable "flow_log_traffic_type" {
description = "The type of traffic to capture. Valid values: ACCEPT,REJECT,ALL"
default = "ALL"
}

variable "rt_vgw_prop" {
type = "string"
description = "Specifies whether virtual gateway route propagation should be enabled on the routing table(s)"
default = 0
}

variable "vgw_ids" {
type = "string"
description = "A list of virtual gateways to associate with the routing tables for route propagation."
default = ""
}
11 changes: 11 additions & 0 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ module "vpc_az" {
rt_dmz_id = "${module.vpc_base.rt_dmz_id}"
}

## Configures Virtual Private Gateway
module "vpc_vpg" {
# Example GitHub source
#source = "github.com/unifio/terraform-aws-vpc?ref=master//vpg"
source = "../../vpg"

vpc_attach = 0
stack_item_label = "${var.stack_item_label}"
stack_item_fullname = "${var.stack_item_fullname}"
}

## Configures routing
resource "aws_route" "dmz-to-igw" {
count = "${length(split(",",lookup(var.az,var.region)))}"
Expand Down
3 changes: 3 additions & 0 deletions examples/full_stack/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module "vpc_vpg" {
#source = "github.com/unifio/terraform-aws-vpc?ref=master//vpg"
source = "../../vpg"

vpc_attach = 1
vpc_id = "${module.vpc_base.vpc_id}"
stack_item_label = "${var.stack_item_label}"
stack_item_fullname = "${var.stack_item_fullname}"
Expand All @@ -69,6 +70,8 @@ module "vpc_az" {
lan_cidr = "${cidrsubnet(var.vpc_cidr,4,8)},${cidrsubnet(var.vpc_cidr,4,9)},${cidrsubnet(var.vpc_cidr,4,10)},${cidrsubnet(var.vpc_cidr,4,13)},${cidrsubnet(var.vpc_cidr,4,14)},${cidrsubnet(var.vpc_cidr,4,15)}"
lans_per_az = "${var.lans_per_az}"
rt_dmz_id = "${module.vpc_base.rt_dmz_id}"
rt_vgw_prop = 1
vgw_ids = "${module.vpc_vpg.vpg_id}"
}

## Configures routing
Expand Down
24 changes: 24 additions & 0 deletions rt/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Route table

resource "aws_route_table" "rt" {
count = "${(var.vgw_prop + 1 % 2) * var.rt_count}"
vpc_id = "${var.vpc_id}"

tags {
Name = "${var.stack_item_label}-${count.index}"
application = "${var.stack_item_fullname}"
managed_by = "terraform"
}
}

resource "aws_route_table" "rt_vgw_prop" {
count = "${var.vgw_prop * var.rt_count}"
vpc_id = "${var.vpc_id}"
propagating_vgws = ["${split(",",var.vgw_ids)}"]

tags {
Name = "${var.stack_item_label}-${count.index}"
application = "${var.stack_item_fullname}"
managed_by = "terraform"
}
}
5 changes: 5 additions & 0 deletions rt/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Outputs

output "rt_id" {
value = "${coalesce(join(",",aws_route_table.rt.*.id),join(",",aws_route_table.rt_vgw_prop.*.id))}"
}
27 changes: 27 additions & 0 deletions rt/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Input Variables

## Resource Tags
variable "stack_item_label" {
type = "string"
}

variable "stack_item_fullname" {
type = "string"
}

## VPC parameters
variable "vpc_id" {
type = "string"
}

variable "vgw_prop" {
type = "string"
}

variable "vgw_ids" {
type = "string"
}

variable "rt_count" {
type = "string"
}
11 changes: 11 additions & 0 deletions vpg/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Gateway configuration
resource "aws_vpn_gateway" "vpg" {
count = "${signum(var.vpc_attach)}"
vpc_id = "${var.vpc_id}"

tags {
Expand All @@ -10,3 +11,13 @@ resource "aws_vpn_gateway" "vpg" {
managed_by = "terraform"
}
}

resource "aws_vpn_gateway" "vpg_unattached" {
count = "${signum(var.vpc_attach) + 1 % 2}"

tags {
Name = "${var.stack_item_label}-vpg"
application = "${var.stack_item_fullname}"
managed_by = "terraform"
}
}
2 changes: 1 addition & 1 deletion vpg/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

## Returns ID of the VPG
output "vpg_id" {
value = "${aws_vpn_gateway.vpg.id}"
value = "${coalesce(join(",",aws_vpn_gateway.vpg.*.id),join(",",aws_vpn_gateway.vpg_unattached.*.id))}"
}
22 changes: 19 additions & 3 deletions vpg/variables.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
# Input Variables

## Resource tags
variable "stack_item_label" {}
variable "stack_item_label" {
type = "string"
description = "Short form identifier for this stack. This value is used to create the 'Name' resource tag for resources created by this stack item, and also serves as a unique key for re-use."
}

variable "stack_item_fullname" {}
variable "stack_item_fullname" {
type = "string"
description = "Long form descriptive name for this stack item. This value is used to create the 'application' resource tag for resources created by this stack item."
}

## VPC parameters
variable "vpc_id" {}
variable "vpc_id" {
type = "string"
description = "The ID of the VPC"
default = ""
}

variable "vpc_attach" {
type = "string"
description = "Specifies whether the VPG should be associated with a VPC."
default = 0
}

0 comments on commit 6134b64

Please sign in to comment.