diff --git a/README.md b/README.md
index 69c99c8..33ab8b4 100644
--- a/README.md
+++ b/README.md
@@ -107,6 +107,7 @@ module "aurora" {
| [aurora\_cluster\_enabled](#input\_aurora\_cluster\_enabled) | Enable creation of an Aurora Cluster | `bool` | `false` | no |
| [aurora\_cluster\_family](#input\_aurora\_cluster\_family) | The family of the DB cluster parameter group | `string` | `"aurora-postgresql14"` | no |
| [aurora\_cluster\_name](#input\_aurora\_cluster\_name) | Database name (default is not to create a database) | `string` | `""` | no |
+| [aurora\_cluster\_name\_override](#input\_aurora\_cluster\_name\_override) | If `true`, this will set a the Aurora Cluster name to what is defined in var.aurora\_cluster\_name.
If `false`, this will prepend ${var.namespace}-${var.environment} to ${var.aurora\_cluster\_name}" | `bool` | `false` | no |
| [aurora\_cluster\_size](#input\_aurora\_cluster\_size) | Number of DB instances to create in the cluster | `number` | `0` | no |
| [aurora\_db\_admin\_password](#input\_aurora\_db\_admin\_password) | Password of the DB admin | `string` | `""` | no |
| [aurora\_db\_admin\_username](#input\_aurora\_db\_admin\_username) | Name of the default DB admin user role | `string` | `""` | no |
@@ -172,6 +173,7 @@ module "aurora" {
| [rds\_instance\_major\_engine\_version](#input\_rds\_instance\_major\_engine\_version) | major\_engine\_version Database MAJOR engine version, depends on engine type | `string` | `"14"` | no |
| [rds\_instance\_multi\_az](#input\_rds\_instance\_multi\_az) | Set to true if multi AZ deployment must be supported | `bool` | `false` | no |
| [rds\_instance\_name](#input\_rds\_instance\_name) | RDS Instance name | `string` | `""` | no |
+| [rds\_instance\_name\_override](#input\_rds\_instance\_name\_override) | If `true`, this will set a the RDS Instance name to what is defined in var.rds\_instance\_name.
If `false`, this will prepend ${var.namespace}-${var.environment} to ${var.rds\_instance\_name}" | `bool` | `false` | no |
| [rds\_instance\_option\_group\_name](#input\_rds\_instance\_option\_group\_name) | Name of the DB option group to associate | `string` | `""` | no |
| [rds\_instance\_publicly\_accessible](#input\_rds\_instance\_publicly\_accessible) | Determines if database can be publicly available (NOT recommended) | `bool` | `false` | no |
| [rds\_instance\_security\_group\_ids](#input\_rds\_instance\_security\_group\_ids) | The IDs of the security groups from which to allow ingress traffic to the DB instance | `list(string)` | `[]` | no |
diff --git a/locals.tf b/locals.tf
index 454edfd..a64bb39 100644
--- a/locals.tf
+++ b/locals.tf
@@ -5,6 +5,7 @@ locals {
rds_instance_option_group_name = length(aws_db_option_group.this) > 0 ? aws_db_option_group.this[0].name : var.rds_instance_option_group_name
## aurora
+ aurora_cluster_name = var.aurora_cluster_name_override == true ? var.aurora_cluster_name : "${var.namespace}-${var.environment}-${var.aurora_cluster_name}"
aurora_ssm_params = var.aurora_cluster_enabled == true ? [
{
name = "/${var.namespace}/${var.environment}/${var.aurora_cluster_name}/cluster_admin_db_password"
@@ -28,6 +29,7 @@ locals {
} : {}
## rds
+ rds_instance_name = var.rds_instance_name_override == true ? var.rds_instance_name : "${var.namespace}-${var.environment}-${var.rds_instance_name}"
rds_instance_ssm_params = var.rds_instance_enabled == true ? [
{
name = "/${var.namespace}/${var.environment}/${var.rds_instance_name}/admin_db_password"
diff --git a/main.tf b/main.tf
index 285b586..3aeef23 100644
--- a/main.tf
+++ b/main.tf
@@ -43,7 +43,7 @@ resource "aws_kms_key" "rds_db_kms_key" {
resource "aws_kms_alias" "rds_db_kms_key" {
count = var.rds_instance_enabled == true ? 1 : 0
- name = "alias/${var.namespace}-${var.environment}-${var.rds_instance_name}"
+ name = "alias/${local.rds_instance_name}"
target_key_id = aws_kms_key.rds_db_kms_key[0].id
}
@@ -142,9 +142,7 @@ module "aurora_cluster" {
source = "git::https://github.com/cloudposse/terraform-aws-rds-cluster.git?ref=1.3.2"
count = var.aurora_cluster_enabled == true ? 1 : 0
- name = var.aurora_cluster_name
- namespace = var.namespace
- stage = var.environment
+ name = local.aurora_cluster_name
engine = var.aurora_engine
engine_mode = var.aurora_engine_mode
@@ -188,7 +186,10 @@ module "aurora_cluster" {
serverlessv2_scaling_configuration = var.aurora_serverlessv2_scaling_configuration
tags = merge(var.tags, tomap({
- Name = var.aurora_cluster_name
+ Name = var.aurora_cluster_name
+ Namespace = var.namespace
+ Environment = var.environment
+ Stage = var.environment
}))
}
@@ -199,9 +200,7 @@ module "db_management" {
source = "git::https://github.com/cloudposse/terraform-aws-s3-bucket?ref=3.0.0"
count = var.rds_enable_custom_option_group == true ? 1 : 0
- name = "${var.rds_instance_name}-db-management"
- stage = var.environment
- namespace = var.namespace
+ name = "${local.rds_instance_name}-db-management"
acl = "private"
enabled = true
@@ -211,7 +210,11 @@ module "db_management" {
kms_master_key_arn = "arn:${data.aws_partition.this.partition}:kms:${var.region}:${var.account_id}:alias/aws/s3"
sse_algorithm = "aws:kms"
- tags = var.tags
+ tags = merge(var.tags, tomap({
+ Namespace = var.namespace
+ Environment = var.environment
+ Stage = var.environment
+ }))
}
################################################################################
@@ -241,7 +244,7 @@ resource "aws_iam_role" "option_group" {
resource "aws_iam_policy" "option_group" {
count = var.rds_enable_custom_option_group == true ? 1 : 0
- name_prefix = "${var.namespace}-${var.environment}-${var.rds_instance_name}-"
+ name_prefix = "${local.rds_instance_name}-"
policy = jsonencode(
{
@@ -302,8 +305,8 @@ resource "aws_iam_role_policy_attachment" "option_group" {
resource "aws_db_option_group" "this" {
count = var.rds_enable_custom_option_group == true ? 1 : 0
- name = "${var.namespace}-${var.environment}-${var.rds_instance_name}-option-group"
- option_group_description = "${var.namespace}-${var.environment}-${var.rds_instance_name} Custom Option Group"
+ name = "${local.rds_instance_name}-option-group"
+ option_group_description = "${local.rds_instance_name} Custom Option Group"
engine_name = var.rds_instance_engine
major_engine_version = var.rds_instance_major_engine_version
@@ -333,7 +336,7 @@ resource "aws_db_option_group" "this" {
}
tags = merge(var.tags, tomap({
- Name = "${var.namespace}-${var.environment}-${var.rds_instance_name}-option-group"
+ Name = "${local.rds_instance_name}-option-group"
}))
}
@@ -352,9 +355,8 @@ module "rds_instance" {
count = var.rds_instance_enabled == true ? 1 : 0
source = "git::https://github.com/cloudposse/terraform-aws-rds?ref=0.40.0"
- stage = var.environment
- name = var.rds_instance_name
- namespace = var.namespace
+ name = local.rds_instance_name
+
dns_zone_id = var.rds_instance_dns_zone_id
host_name = var.rds_instance_host_name
vpc_id = var.vpc_id
@@ -398,7 +400,11 @@ module "rds_instance" {
iam_database_authentication_enabled = var.iam_database_authentication_enabled
timeouts = var.timeouts
- tags = var.tags
+ tags = merge(var.tags, tomap({
+ Namespace = var.namespace
+ Environment = var.environment
+ Stage = var.environment
+ }))
}
################################################################################
diff --git a/variables.tf b/variables.tf
index aa018c4..cd7ee06 100644
--- a/variables.tf
+++ b/variables.tf
@@ -47,6 +47,15 @@ variable "aurora_cluster_enabled" {
default = false
}
+variable "aurora_cluster_name_override" {
+ type = bool
+ description = <<-EOT
+ If `true`, this will set a the Aurora Cluster name to what is defined in var.aurora_cluster_name.
+ If `false`, this will prepend $${var.namespace}-$${var.environment} to $${var.aurora_cluster_name}"
+ EOT
+ default = false
+}
+
variable "aurora_cluster_name" {
type = string
description = "Database name (default is not to create a database)"
@@ -213,6 +222,15 @@ variable "rds_instance_iops" {
default = 0
}
+variable "rds_instance_name_override" {
+ type = bool
+ description = <<-EOT
+ If `true`, this will set a the RDS Instance name to what is defined in var.rds_instance_name.
+ If `false`, this will prepend $${var.namespace}-$${var.environment} to $${var.rds_instance_name}"
+ EOT
+ default = false
+}
+
variable "rds_instance_name" {
type = string
description = "RDS Instance name"