Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output instance endpoints, add attributes to random_pet that force a new instance #236

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,11 @@ resource "random_pet" "instance" {
count = local.enabled ? 1 : 0
prefix = var.cluster_identifier == "" ? module.this.id : var.cluster_identifier
keepers = {
cluster_family = var.cluster_family
instance_class = var.serverlessv2_scaling_configuration != null ? "db.serverless" : var.instance_type
cluster_family = var.cluster_family
cluster_identifier = coalesce(join("", aws_rds_cluster.primary[*].id), join("", aws_rds_cluster.secondary[*].id))
db_subnet_group_name = join("", aws_db_subnet_group.default[*].name)
engine = var.engine
instance_class = var.serverlessv2_scaling_configuration != null ? "db.serverless" : var.instance_type
}
}

Expand All @@ -336,13 +339,13 @@ module "rds_identifier" {
resource "aws_rds_cluster_instance" "default" {
count = local.cluster_instance_count
identifier = "${module.rds_identifier[0].id}-${count.index + 1}"
cluster_identifier = coalesce(join("", aws_rds_cluster.primary[*].id), join("", aws_rds_cluster.secondary[*].id))
cluster_identifier = random_pet.instance[0].keepers.cluster_identifier
Copy link
Contributor

Choose a reason for hiding this comment

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

this is forcing a replacement in the resource "aws_rds_cluster_instance" "default" { now that these attribute values are changing (even if the end result value is the same). this would cause a recreate of the database instance... see example plan above

Choose a reason for hiding this comment

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

instance_class = random_pet.instance[0].keepers.instance_class
db_subnet_group_name = join("", aws_db_subnet_group.default[*].name)
db_subnet_group_name = random_pet.instance[0].keepers.db_subnet_group_name
db_parameter_group_name = join("", aws_db_parameter_group.default[*].name)
publicly_accessible = var.publicly_accessible
tags = module.this.tags
engine = var.engine
engine = random_pet.instance[0].keepers.engine
engine_version = var.engine_version
auto_minor_version_upgrade = var.auto_minor_version_upgrade
monitoring_interval = var.rds_monitoring_interval
Expand Down Expand Up @@ -371,7 +374,6 @@ resource "aws_rds_cluster_instance" "default" {
aws_iam_role.enhanced_monitoring,
aws_rds_cluster.secondary,
aws_rds_cluster_parameter_group.default,
aws_rds_cluster_instance.default[0],
]

lifecycle {
Expand Down
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ output "dbi_resource_ids" {
description = "List of the region-unique, immutable identifiers for the DB instances in the cluster"
}

output "instance_endpoints" {
value = aws_rds_cluster_instance.default[*].endpoint
description = "List of DNS addresses for the DB instances in the cluster"
}

output "cluster_resource_id" {
value = local.is_regional_cluster ? join("", aws_rds_cluster.primary[*].cluster_resource_id) : join("", aws_rds_cluster.secondary[*].cluster_resource_id)
description = "The region-unique, immutable identifie of the cluster"
Expand Down