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

Redshift public subnets #222

Merged
merged 7 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
add public subnet for redshift to enable access for kinesis
  • Loading branch information
bmihaescu committed Feb 20, 2019
commit d4fd1e13d3eaf207507c055567fda7fe8e015be6
24 changes: 24 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,30 @@ resource "aws_redshift_subnet_group" "redshift" {
tags = "${merge(map("Name", format("%s", var.name)), var.tags, var.redshift_subnet_group_tags)}"
}

##################
# Redshift public subnet
##################
resource "aws_subnet" "redshift_public" {
count = "${var.create_vpc && length(var.redshift_public_subnets) > 0 ? length(var.redshift_public_subnets) : 0}"

vpc_id = "${local.vpc_id}"
cidr_block = "${var.redshift_public_subnets[count.index]}"
availability_zone = "${element(var.azs, count.index)}"
map_public_ip_on_launch = "${var.map_public_ip_on_launch}"

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

resource "aws_redshift_subnet_group" "redshift_public" {
count = "${var.create_vpc && length(var.redshift_public_subnets) > 0 && var.create_redshift_public_subnet_group ? 1 : 0}"

name = "${lower(var.name)}"
description = "Redshift public subnet group for ${var.name}"
subnet_ids = ["${aws_subnet.redshift_public.*.id}"]

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

#####################
# ElastiCache subnet
#####################
Expand Down
15 changes: 15 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ output "redshift_subnet_group" {
value = "${element(concat(aws_redshift_subnet_group.redshift.*.id, list("")), 0)}"
}

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

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

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

output "elasticache_subnets" {
description = "List of IDs of elasticache subnets"
value = ["${aws_subnet.elasticache.*.id}"]
Expand Down
26 changes: 26 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ variable "redshift_subnet_suffix" {
default = "redshift"
}

variable "redshift_public_subnet_suffix" {
description = "Suffix to append to redshift subnets name"
default = "redshift_public"
}

variable "elasticache_subnet_suffix" {
description = "Suffix to append to elasticache subnets name"
default = "elasticache"
Expand Down Expand Up @@ -75,6 +80,12 @@ variable "redshift_subnets" {
default = []
}

variable "redshift_public_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 @@ -117,6 +128,11 @@ variable "create_redshift_subnet_group" {
default = true
}

variable "create_redshift_public_subnet_group" {
description = "Controls if redshift public subnet group should be created"
default = true
}

variable "create_database_internet_gateway_route" {
description = "Controls if an internet gateway route for public database access should be created"
default = false
Expand Down Expand Up @@ -403,6 +419,16 @@ variable "redshift_subnet_group_tags" {
default = {}
}

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

variable "redshift_public_subnet_group_tags" {
description = "Additional tags for the redshift public subnet group"
default = {}
}

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