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

Add Redshift subnets #54

Merged
merged 13 commits into from
Jan 11, 2018
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ These types of resources are supported:
* [VPC Endpoint](https://www.terraform.io/docs/providers/aws/r/vpc_endpoint.html) (S3 and DynamoDB)
* [RDS DB Subnet Group](https://www.terraform.io/docs/providers/aws/r/db_subnet_group.html)
* [ElastiCache Subnet Group](https://www.terraform.io/docs/providers/aws/r/elasticache_subnet_group.html)
* [Redshift Subnet Group](https://www.terraform.io/docs/providers/aws/r/redshift_subnet_group.html)
* [DHCP Options Set](https://www.terraform.io/docs/providers/aws/r/vpc_dhcp_options.html)

Usage
Expand Down
1 change: 1 addition & 0 deletions examples/complete-vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module "vpc" {
public_subnets = ["10.10.11.0/24", "10.10.12.0/24", "10.10.13.0/24"]
database_subnets = ["10.10.21.0/24", "10.10.22.0/24", "10.10.23.0/24"]
elasticache_subnets = ["10.10.31.0/24", "10.10.32.0/24", "10.10.33.0/24"]
redshift_subnets = ["10.10.41.0/24", "10.10.42.0/24", "10.10.43.0/24"]

create_database_subnet_group = false

Expand Down
5 changes: 5 additions & 0 deletions examples/complete-vpc/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ output "elasticache_subnets" {
value = ["${module.vpc.elasticache_subnets}"]
}

output "redshift_subnets" {
description = "List of IDs of redshift subnets"
value = ["${module.vpc.redshift_subnets}"]
}

# NAT gateways
output "nat_public_ips" {
description = "List of public Elastic IPs created for AWS NAT Gateway"
Expand Down
32 changes: 31 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ resource "aws_route" "public_internet_gateway" {
# There are so many route-tables as the largest amount of subnets of each type (really?)
#################
resource "aws_route_table" "private" {
count = "${max(length(var.private_subnets), length(var.elasticache_subnets), length(var.database_subnets))}"
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}"]
Expand Down Expand Up @@ -139,6 +139,29 @@ resource "aws_db_subnet_group" "database" {
tags = "${merge(var.tags, map("Name", format("%s", var.name)))}"
}

##################
# Redshift subnet
##################
resource "aws_subnet" "redshift" {
count = "${length(var.redshift_subnets)}"

vpc_id = "${aws_vpc.this.id}"
cidr_block = "${var.redshift_subnets[count.index]}"
availability_zone = "${element(var.azs, count.index)}"

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

resource "aws_redshift_subnet_group" "redshift" {
count = "${length(var.redshift_subnets) > 0 ? 1 : 0}"

name = "${var.name}"
description = "Redshift subnet group for ${var.name}"
subnet_ids = ["${aws_subnet.redshift.*.id}"]

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

#####################
# ElastiCache subnet
#####################
Expand Down Expand Up @@ -277,6 +300,13 @@ resource "aws_route_table_association" "database" {
route_table_id = "${element(aws_route_table.private.*.id, count.index)}"
}

resource "aws_route_table_association" "redshift" {
count = "${length(var.redshift_subnets)}"

subnet_id = "${element(aws_subnet.redshift.*.id, count.index)}"
route_table_id = "${element(aws_route_table.private.*.id, count.index)}"
}

resource "aws_route_table_association" "elasticache" {
count = "${length(var.elasticache_subnets)}"

Expand Down
25 changes: 25 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ output "database_subnet_group" {
value = "${element(concat(aws_db_subnet_group.database.*.id, list("")), 0)}"
}

output "redshift_subnets" {
description = "List of IDs of redshift subnets"
value = ["${aws_subnet.redshift.*.id}"]
}

output "redshift_subnets_cidr_blocks" {
description = "List of cidr_blocks of redshift subnets"
value = ["${aws_subnet.redshift.*.cidr_block}"]
}

output "redshift_subnet_group" {
description = "ID of redshift subnet group"
value = "${element(concat(aws_redshift_subnet_group.redshift.*.id, list("")), 0)}"
}

output "elasticache_subnets" {
description = "List of IDs of elasticache subnets"
value = ["${aws_subnet.elasticache.*.id}"]
Expand Down Expand Up @@ -113,6 +128,11 @@ output "vpc_endpoint_s3_id" {
value = "${element(concat(aws_vpc_endpoint.s3.*.id, list("")), 0)}"
}

output "vpc_endpoint_s3_pl_id" {
description = "The prefix list for the S3 VPC endpoint."
value = "${element(concat(aws_vpc_endpoint.s3.*.prefix_list_id, list("")), 0)}"
}

output "vpc_endpoint_dynamodb_id" {
description = "The ID of VPC endpoint for DynamoDB"
value = "${element(concat(aws_vpc_endpoint.dynamodb.*.id, list("")), 0)}"
Expand All @@ -123,3 +143,8 @@ output "vgw_id" {
description = "The ID of the VPN Gateway"
value = "${element(concat(aws_vpn_gateway.this.*.id, list("")), 0)}"
}

output "vpc_endpoint_dynamodb_pl_id" {
description = "The prefix list for the DynamoDB VPC endpoint."
value = "${element(concat(aws_vpc_endpoint.dynamodb.*.prefix_list_id, list("")), 0)}"
}
11 changes: 11 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ variable "database_subnets" {
default = []
}

variable "redshift_subnets" {
type = "list"
description = "A list of redshift subnets"
default = []
}

variable "elasticache_subnets" {
type = "list"
description = "A list of elasticache subnets"
Expand Down Expand Up @@ -141,6 +147,11 @@ variable "database_subnet_tags" {
default = {}
}

variable "redshift_subnet_tags" {
description = "Additional tags for the redshift subnets"
default = {}
}

variable "elasticache_subnet_tags" {
description = "Additional tags for the elasticache subnets"
default = {}
Expand Down