Skip to content
This repository was archived by the owner on Jul 3, 2023. It is now read-only.

Commit 8d8642f

Browse files
committed
added consistent tagging for rds
1 parent eccc09e commit 8d8642f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

rds/main.tf

+20-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ variable "name" {
22
description = "RDS instance name"
33
}
44

5+
variable "environment" {
6+
description = "Environment tag, e.g prod, if missing defaults to name"
7+
}
8+
59
variable "engine" {
610
description = "Database engine: mysql, postgres, etc."
711
default = "postgres"
@@ -112,6 +116,10 @@ variable "subnet_ids" {
112116
type = "list"
113117
}
114118

119+
locals {
120+
environment = "${coalesce(var.environment, var.name)}"
121+
}
122+
115123
resource "aws_security_group" "main" {
116124
name = "${var.name}-rds"
117125
description = "Allows traffic to RDS from other security groups"
@@ -139,14 +147,20 @@ resource "aws_security_group" "main" {
139147
}
140148

141149
tags {
142-
Name = "RDS (${var.name})"
150+
Name = "RDS ${var.name}"
151+
Environment = "${local.environment}"
143152
}
144153
}
145154

146155
resource "aws_db_subnet_group" "main" {
147156
name = "${var.name}"
148157
description = "RDS subnet group"
149158
subnet_ids = ["${var.subnet_ids}"]
159+
160+
tags {
161+
Name = "RDS Subnet ${var.name}"
162+
Environment = "${local.environment}"
163+
}
150164
}
151165

152166
resource "aws_db_instance" "main" {
@@ -179,6 +193,11 @@ resource "aws_db_instance" "main" {
179193
db_subnet_group_name = "${aws_db_subnet_group.main.id}"
180194
vpc_security_group_ids = ["${aws_security_group.main.id}"]
181195
publicly_accessible = "${var.publicly_accessible}"
196+
197+
tags {
198+
Name = "RDS Instance ${var.name}"
199+
Environment = "${local.environment}"
200+
}
182201
}
183202

184203
output "addr" {

0 commit comments

Comments
 (0)