Commit c1d51438 authored by Anton Babenko's avatar Anton Babenko Committed by GitHub

Add Redshift subnets (#54)

* add cidr_block outputs to public and private subnets

* add cidr_block outputs to database and elasticache subnets

* add redshift subnet option

* fix tag

* add missing route association for redshift

* add vpc_endpoint_s3_pl_id and vpc_endpoint_dynamodb_pl_id outputs

* add redshift to complete-vcp example

* fix domain_name_servers - keep it a list

* fix outputs for TF 0.11

* fix missing *

* Minor corrections in example and in type of dhcp_options_domain_name_servers

* Minor corrections in example

* Updated README
parent 63f3cb97
......@@ -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
......
......@@ -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
......
......@@ -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"
......
......@@ -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}"]
......@@ -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
#####################
......@@ -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)}"
......
......@@ -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}"]
......@@ -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)}"
......@@ -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)}"
}
......@@ -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"
......@@ -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 = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment