Skip to content

Commit

Permalink
Support subnet-specific additional tags (#51)
Browse files Browse the repository at this point in the history
* Added var.public_subnet_tags
* Added var.private_subnet_tags
* Added var.database_subnet_tags
* Added var.elasticache_subnet_tags
* Removed Tier subnet tag

This helps solve a specific issue with Kubernetes, where public &
private subnets must be appropriately tagged for public/private ELBs to
work.
  • Loading branch information
rmt authored and antonbabenko committed Jun 15, 2017
1 parent 7a1408f commit f6ae8a4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ resource "aws_subnet" "private" {
cidr_block = "${var.private_subnets[count.index]}"
availability_zone = "${element(var.azs, count.index)}"
count = "${length(var.private_subnets)}"
tags = "${merge(var.tags, map("Name", format("%s-subnet-private-%s", var.name, element(var.azs, count.index))), map("Tier", "private"))}"
tags = "${merge(var.tags, var.private_subnet_tags, map("Name", format("%s-subnet-private-%s", var.name, element(var.azs, count.index))))}"
}

resource "aws_subnet" "database" {
vpc_id = "${aws_vpc.mod.id}"
cidr_block = "${var.database_subnets[count.index]}"
availability_zone = "${element(var.azs, count.index)}"
count = "${length(var.database_subnets)}"
tags = "${merge(var.tags, map("Name", format("%s-database-subnet-%s", var.name, element(var.azs, count.index))), map("Tier", "database"))}"
tags = "${merge(var.tags, var.database_subnet_tags, map("Name", format("%s-database-subnet-%s", var.name, element(var.azs, count.index))))}"
}

resource "aws_db_subnet_group" "database" {
Expand All @@ -65,7 +65,7 @@ resource "aws_subnet" "elasticache" {
cidr_block = "${var.elasticache_subnets[count.index]}"
availability_zone = "${element(var.azs, count.index)}"
count = "${length(var.elasticache_subnets)}"
tags = "${merge(var.tags, map("Name", format("%s-elasticache-subnet-%s", var.name, element(var.azs, count.index))), map("Tier", "elasticache"))}"
tags = "${merge(var.tags, var.elasticache_subnet_tags, map("Name", format("%s-elasticache-subnet-%s", var.name, element(var.azs, count.index))))}"
}

resource "aws_elasticache_subnet_group" "elasticache" {
Expand All @@ -80,7 +80,7 @@ resource "aws_subnet" "public" {
cidr_block = "${var.public_subnets[count.index]}"
availability_zone = "${element(var.azs, count.index)}"
count = "${length(var.public_subnets)}"
tags = "${merge(var.tags, map("Name", format("%s-subnet-public-%s", var.name, element(var.azs, count.index))), map("Tier", "public"))}"
tags = "${merge(var.tags, var.public_subnet_tags, map("Name", format("%s-subnet-public-%s", var.name, element(var.azs, count.index))))}"

map_public_ip_on_launch = "${var.map_public_ip_on_launch}"
}
Expand Down
20 changes: 20 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,23 @@ variable "tags" {
description = "A map of tags to add to all resources"
default = {}
}

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

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

variable "database_subnet_tags" {
description = "Additional tags for the database subnets"
default = {}
}

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

0 comments on commit f6ae8a4

Please sign in to comment.