Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ Available targets:
| <a name="input_performance_insights_retention_period"></a> [performance\_insights\_retention\_period](#input\_performance\_insights\_retention\_period) | Amount of time in days to retain Performance Insights data. Either 7 (7 days) or 731 (2 years) | `number` | `null` | no |
| <a name="input_promotion_tier"></a> [promotion\_tier](#input\_promotion\_tier) | Failover Priority setting on instance level. The reader who has lower tier has higher priority to get promoted to writer.<br/><br/>Readers in promotion tiers 0 and 1 scale at the same time as the writer. Readers in promotion tiers 2–15 scale independently from the writer. For more information, see: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-serverless-v2.how-it-works.html#aurora-serverless-v2.how-it-works.scaling | `number` | `0` | no |
| <a name="input_publicly_accessible"></a> [publicly\_accessible](#input\_publicly\_accessible) | Set to true if you want your cluster to be publicly accessible (such as via QuickSight) | `bool` | `false` | no |
| <a name="input_rds_cluster_identifier_prefix_enabled"></a> [rds\_cluster\_identifier\_prefix\_enabled](#input\_rds\_cluster\_identifier\_prefix\_enabled) | Set to `true` to use `identifier_prefix` to name the cluster. Set to `false` to use `identifier` instead | `bool` | `false` | no |
| <a name="input_rds_cluster_parameter_group_name"></a> [rds\_cluster\_parameter\_group\_name](#input\_rds\_cluster\_parameter\_group\_name) | The name to give to the created `aws_rds_cluster_parameter_group` resource.<br/>If omitted, the module will generate a name. | `string` | `""` | no |
| <a name="input_rds_monitoring_interval"></a> [rds\_monitoring\_interval](#input\_rds\_monitoring\_interval) | The interval, in seconds, between points when enhanced monitoring metrics are collected for the DB instance. To disable collecting Enhanced Monitoring metrics, specify 0. The default is 0. Valid Values: 0, 1, 5, 10, 15, 30, 60 | `number` | `0` | no |
| <a name="input_rds_monitoring_role_arn"></a> [rds\_monitoring\_role\_arn](#input\_rds\_monitoring\_role\_arn) | The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs | `string` | `null` | no |
Expand Down
57 changes: 29 additions & 28 deletions docs/terraform.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions examples/complete/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ enhanced_monitoring_role_enabled = true
rds_monitoring_interval = 30

intra_security_group_traffic_enabled = true

parameter_group_name_prefix_enabled = true

rds_cluster_identifier_prefix_enabled = true
3 changes: 3 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ module "rds_cluster" {
allocated_storage = var.allocated_storage
intra_security_group_traffic_enabled = var.intra_security_group_traffic_enabled

parameter_group_name_prefix_enabled = var.parameter_group_name_prefix_enabled
rds_cluster_identifier_prefix_enabled = var.rds_cluster_identifier_prefix_enabled

cluster_parameters = [
{
name = "character_set_client"
Expand Down
12 changes: 12 additions & 0 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,15 @@ variable "intra_security_group_traffic_enabled" {
default = false
description = "Whether to allow traffic between resources inside the database's security group."
}

variable "parameter_group_name_prefix_enabled" {
type = bool
default = true
description = "Set to `true` to use `name_prefix` to name the cluster and database parameter groups. Set to `false` to use `name` instead"
}

variable "rds_cluster_identifier_prefix_enabled" {
type = bool
default = false
description = "Set to `true` to use `identifier_prefix` to name the cluster. Set to `false` to use `identifier` instead"
}
25 changes: 17 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ resource "aws_rds_reserved_instance" "default" {
# The name "primary" is poorly chosen. We actually mean standalone or regional.
# The primary cluster of a global database is actually created with the "secondary" cluster resource below.
resource "aws_rds_cluster" "primary" {
count = local.enabled && local.is_regional_cluster ? 1 : 0
cluster_identifier = var.cluster_identifier == "" ? module.this.id : var.cluster_identifier
database_name = var.db_name
count = local.enabled && local.is_regional_cluster ? 1 : 0

cluster_identifier_prefix = var.rds_cluster_identifier_prefix_enabled ? (var.cluster_identifier == "" ? "${module.this.id}${module.this.delimiter}" : var.cluster_identifier) : null
cluster_identifier = !var.rds_cluster_identifier_prefix_enabled ? (var.cluster_identifier == "" ? module.this.id : var.cluster_identifier) : null

database_name = var.db_name
# manage_master_user_password must be `null` or `true`. If it is `false`, and `master_password` is not `null`, a conflict occurs.
manage_master_user_password = var.manage_admin_user_password ? var.manage_admin_user_password : null
master_user_secret_kms_key_id = var.admin_user_secret_kms_key_id
Expand Down Expand Up @@ -231,9 +234,12 @@ resource "aws_rds_cluster" "primary" {

# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster#replication_source_identifier
resource "aws_rds_cluster" "secondary" {
count = local.enabled && !local.is_regional_cluster ? 1 : 0
cluster_identifier = var.cluster_identifier == "" ? module.this.id : var.cluster_identifier
database_name = var.db_name
count = local.enabled && !local.is_regional_cluster ? 1 : 0

cluster_identifier_prefix = var.rds_cluster_identifier_prefix_enabled ? (var.cluster_identifier == "" ? "${module.this.id}${module.this.delimiter}" : var.cluster_identifier) : null
cluster_identifier = !var.rds_cluster_identifier_prefix_enabled ? (var.cluster_identifier == "" ? module.this.id : var.cluster_identifier) : null

database_name = var.db_name
# manage_master_user_password must be `null` or `true`. If it is `false`, and `master_password` is not `null`, a conflict occurs.
manage_master_user_password = var.manage_admin_user_password ? var.manage_admin_user_password : null
master_user_secret_kms_key_id = var.admin_user_secret_kms_key_id
Expand Down Expand Up @@ -347,8 +353,11 @@ module "rds_identifier" {
}

resource "aws_rds_cluster_instance" "default" {
count = local.cluster_instance_count
identifier = "${module.rds_identifier[0].id}-${count.index + 1}"
count = local.cluster_instance_count

identifier_prefix = var.rds_cluster_identifier_prefix_enabled ? "${module.rds_identifier[0].id}${module.this.delimiter}${count.index + 1}${module.this.delimiter}" : null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unique name for the aws_rds_cluster_instance should be controlled by the random_pet that feeds into the module.rds_identifier. Why is that not working here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you know it's not working?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see what you're saying. The random pet does go into the rds_identifier. Hmm, maybe I'm not using it correctly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nitrocode there is some history here, I made some changes in #236 but after some FUD some of the changes were taken out in #242. You would probably need to add cluster_identifier back into the random_pet to get the features you want.

identifier = !var.rds_cluster_identifier_prefix_enabled ? "${module.rds_identifier[0].id}${module.this.delimiter}${count.index + 1}" : null

cluster_identifier = local.deployed_cluster_identifier
instance_class = local.instance_class
db_subnet_group_name = local.db_subnet_group_name
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,12 @@ variable "parameter_group_name_prefix_enabled" {
description = "Set to `true` to use `name_prefix` to name the cluster and database parameter groups. Set to `false` to use `name` instead"
}

variable "rds_cluster_identifier_prefix_enabled" {
type = bool
default = false
description = "Set to `true` to use `identifier_prefix` to name the cluster. Set to `false` to use `identifier` instead"
}

variable "enable_global_write_forwarding" {
type = bool
default = null
Expand Down