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

added consistent tagging for rds #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
21 changes: 20 additions & 1 deletion rds/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ variable "name" {
description = "RDS instance name"
}

variable "environment" {
description = "Environment tag, e.g prod, if missing defaults to name"
}

variable "engine" {
description = "Database engine: mysql, postgres, etc."
default = "postgres"
Expand Down Expand Up @@ -112,6 +116,10 @@ variable "subnet_ids" {
type = "list"
}

locals {
environment = "${coalesce(var.environment, var.name)}"
}

resource "aws_security_group" "main" {
name = "${var.name}-rds"
description = "Allows traffic to RDS from other security groups"
Expand Down Expand Up @@ -139,14 +147,20 @@ resource "aws_security_group" "main" {
}

tags {
Name = "RDS (${var.name})"
Name = "RDS ${var.name}"
Environment = "${local.environment}"
}
}

resource "aws_db_subnet_group" "main" {
name = "${var.name}"
description = "RDS subnet group"
subnet_ids = ["${var.subnet_ids}"]

tags {
Name = "RDS Subnet ${var.name}"
Environment = "${local.environment}"
}
}

resource "aws_db_instance" "main" {
Expand Down Expand Up @@ -179,6 +193,11 @@ resource "aws_db_instance" "main" {
db_subnet_group_name = "${aws_db_subnet_group.main.id}"
vpc_security_group_ids = ["${aws_security_group.main.id}"]
publicly_accessible = "${var.publicly_accessible}"

tags {
Name = "RDS Instance ${var.name}"
Environment = "${local.environment}"
}
}

output "addr" {
Expand Down