Repository navigation
fix(infra): drop the prod Aurora reader, keyed by identifier not index - #1099
Merged
Merged
Conversation
Owner cost decision: the prod cluster averages 0.51 ACU against a 0.5 floor, so
the reader was buying failover rather than capacity. Removing it saves ~$43/mo
and gives up automatic failover — an instance or AZ failure becomes an outage
until someone promotes a replacement.
The resource moves from count to for_each keyed by identifier, because
`identifier = "er-prod-${count.index + 1}"` makes index [1] er-prod-2, which is
the CURRENT WRITER. A count 2 -> 1 shrink destroys the highest index, so the
obvious edit would have deleted the writer and forced a failover on a live
database. Which instance is the writer is runtime state that Aurora reshuffles
on every failover, so an index-keyed resource can never express this safely.
Two `moved` blocks carry the existing instances onto the name-keyed addresses;
without them the planner sees no state at either and plans destroy-both.
Closes #1096
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Contributor
terraform plan
Warning This plan DESTROYS resources in: prod. Merging applies it unattended. prod — 0 to add, 0 to change, 1 to DESTROYdata.aws_iam_policy_document.efs_csi_trust: Reading...
data.aws_iam_policy_document.eso_trust: Reading...
data.aws_rds_engine_version.aurora_pg: Reading...
data.aws_iam_policy_document.efs_csi_trust: Read complete after 0s [id=819195744]
data.aws_iam_policy_document.eso_trust: Read complete after 0s [id=819195744]
module.network.data.aws_region.current: Reading...
data.aws_iam_openid_connect_provider.github: Reading...
module.eks.data.aws_iam_policy_document.cluster_trust: Reading...
module.network.data.aws_region.current: Read complete after 0s [id=us-east-2]
module.eks.data.aws_iam_policy_document.cluster_trust: Read complete after 0s [id=1029077455]
module.ses.data.aws_region.current: Reading...
module.ses.data.aws_region.current: Read complete after 0s [id=us-east-2]
data.aws_caller_identity.current: Reading...
module.network.data.aws_availability_zones.available: Reading...
module.eks.data.aws_iam_policy_document.node_trust: Reading...
module.eks.data.aws_iam_policy_document.node_trust: Read complete after 0s [id=2851119427]
data.aws_iam_policy_document.pod_trust: Reading...
data.aws_iam_policy_document.pod_trust: Read complete after 0s [id=819195744]
data.aws_iam_policy_document.openobserve: Reading...
data.aws_iam_policy_document.openobserve: Read complete after 0s [id=2652188337]
data.aws_iam_policy_document.otel_collector: Reading...
data.aws_iam_policy_document.fluent_bit: Reading...
data.aws_iam_policy_document.otel_collector: Read complete after 0s [id=1193716550]
data.aws_iam_policy_document.fluent_bit: Read complete after 0s [id=2978074842]
data.aws_caller_identity.current: Read complete after 0s [id=797781631727]
module.lake.data.aws_iam_policy_document.lake_tls_only: Reading...
module.lake.data.aws_iam_policy_document.lake_tls_only: Read complete after 0s [id=3960055703]
module.ses.data.aws_iam_policy_document.send: Reading...
module.ses.data.aws_iam_policy_document.send: Read complete after 0s [id=3767633194]
data.aws_iam_policy_document.lake_access: Reading...
data.aws_iam_policy_document.lake_access: Read complete after 0s [id=1033619361]
data.aws_iam_policy_document.eso: Reading...
data.aws_iam_policy_document.eso: Read complete after 0s [id=2178872705]
module.network.data.aws_availability_zones.available: Read complete after 0s [id=us-east-2]
data.aws_rds_engine_version.aurora_pg: Read complete after 0s [id=17.9]
data.aws_iam_policy_document.ci_deploy_prod: Reading...
data.aws_iam_policy_document.ci_deploy_prod: Read complete after 0s [id=2891227359]
data.aws_iam_openid_connect_provider.github: Read complete after 0s [id=arn:aws:iam::797781631727:oidc-provider/token.actions.githubusercontent.com]
data.aws_iam_policy_document.ci_deploy_prod_trust: Reading...
data.aws_iam_policy_document.ci_deploy_prod_trust: Read complete after 0s [id=4060172364]
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
- destroy
Terraform will perform the following actions:
# aws_rds_cluster_instance.prod["er-prod-1"] will be destroyed
# (because key ["er-prod-1"] is not in for_each map)
# (moved from aws_rds_cluster_instance.prod[0])
- resource "aws_rds_cluster_instance" "prod" {
- arn = "arn:aws:rds:us-east-2:797781631727:db:er-prod-1" -> null
- auto_minor_version_upgrade = true -> null
- availability_zone = "us-east-2b" -> null
- ca_cert_identifier = "rds-ca-rsa2048-g1" -> null
- cluster_identifier = "er-prod" -> null
- copy_tags_to_snapshot = false -> null
- db_parameter_group_name = "default.aurora-postgresql17" -> null
- db_subnet_group_name = "er-prod" -> null
- dbi_resource_id = "db-CTU7L2OSSPVEYWIPJH6DIRPW7Q" -> null
- endpoint = "er-prod-1.cpoae40oyk3z.us-east-2.rds.amazonaws.com" -> null
- engine = "aurora-postgresql" -> null
- engine_version = "17.9" -> null
- engine_version_actual = "17.9" -> null
- force_destroy = false -> null
- id = "er-prod-1" -> null
- identifier = "er-prod-1" -> null
- instance_class = "db.serverless" -> null
- kms_key_id = "arn:aws:kms:us-east-2:797781631727:key/4a20b7b9-7093-4ef2-9dc8-95384cf19e48" -> null
- monitoring_interval = 0 -> null
- network_type = "IPV4" -> null
- performance_insights_enabled = true -> null
- performance_insights_kms_key_id = "arn:aws:kms:us-east-2:797781631727:key/4a20b7b9-7093-4ef2-9dc8-95384cf19e48" -> null
- performance_insights_retention_period = 7 -> null
- port = 5432 -> null
- preferred_backup_window = "10:28-10:58" -> null
- preferred_maintenance_window = "mon:09:31-mon:10:01" -> null
- promotion_tier = 0 -> null
- publicly_accessible = false -> null
- region = "us-east-2" -> null
- storage_encrypted = true -> null
- tags = {} -> null
- tags_all = {
- "Environment" = "prod"
- "ManagedBy" = "terraform"
- "Project" = "entity-resolution"
} -> null
- writer = false -> null
# (3 unchanged attributes hidden)
}
# aws_rds_cluster_instance.prod[1] has moved to aws_rds_cluster_instance.prod["er-prod-2"]
resource "aws_rds_cluster_instance" "prod" {
id = "er-prod-2"
tags = {}
# (34 unchanged attributes hidden)
}
Plan: 0 to add, 0 to change, 1 to destroy.
|
athvin
pushed a commit
that referenced
this pull request
Nov 17, 2026
Dropping the reader (#1096, PR #1099) made two rows in these references false: prod Aurora is one Serverless v2 instance with no automatic failover. That matters here specifically, because this PR's static `max_locks_per_transaction` needs an instance reboot to activate — which on a single instance is an outage rather than a failover.
14 tasks done
athvin
added a commit
that referenced
this pull request
Nov 21, 2026
…-DESTROY * feat(prod): require verified PostgreSQL TLS * fix(prod): configure the DuckLake maintenance lock budget * docs(infra): regenerate the Aurora resource inventory * docs(prod): record TLS cutover and parameter activation steps * docs(infra): correct the prod Aurora availability claims after #1096 Dropping the reader (#1096, PR #1099) made two rows in these references false: prod Aurora is one Serverless v2 instance with no automatic failover. That matters here specifically, because this PR's static `max_locks_per_transaction` needs an instance reboot to activate — which on a single instance is an outage rather than a failover. --------- Co-authored-by: bmoore813 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1096
Warning
DO NOT MERGE until the
plan (prod)output has been read. This destroys aninstance of a live, deletion-protected production database,
infra-apply-prodhas no required reviewers, and the apply is unattended. The plan must show
exactly one destroy —
aws_rds_cluster_instance.prod["er-prod-1"]— andno create and no replace. Anything else means the
movedblocks did nottake, and merging would destroy both instances.
The destroy guard will also refuse the apply unless the merge commit
carries
ALLOW-DESTROY. This is a single-commit PR, so retitling is notenough:
gh pr merge <n> --squash --subject '<subject> ALLOW-DESTROY'What
Removes the prod Aurora reader replica, and re-keys
aws_rds_cluster_instance.prodfromcounttofor_eachby identifier.Why
Owner cost decision. The cluster averages 0.51 ACU against a 0.5 floor, so
the reader was buying failover rather than capacity: ~$43/month. What is
given up is automatic failover — an instance or AZ failure becomes an outage
until someone promotes a replacement, and a maintenance restart becomes visible
downtime.
The re-keying is not cosmetic.
identifier = "er-prod-${count.index + 1}"makesindex
[1]equaler-prod-2, which is the current writer; acount = 2 -> 1shrink destroys the highest index, so the obvious edit deletes the writer and
forces a failover on a live database instead of removing the idle replica.
Proof
terraform fmt -check -recursiveclean andterraform validateSuccess inenvs/prod.validatecannot prove the plan shape — it does not read state,so the
movedblocks are unexercised untilplan (prod)runs on this PR. Thatjob is the proof, and the acceptance criterion is in the warning above.
Risk & rollback
Highest-risk class in this repo: an unattended apply against production data.
Mitigations are the destroy guard, the plan-before-merge read, and the fact that
the cluster keeps
deletion_protection = true,skip_final_snapshot = falseand 14-day backups. Rollback is
git revert <merge-sha>, which re-adds a reader— Aurora rebuilds it from the cluster volume, so no data is at stake, only the
~20 minutes it takes to come up.
Post-merge ledger
Closed by: agent · session
Claude Code:f14bf995-5565-41eb-9658-d3746dc3188eonMac-833· 2026-11-17T03:15:00Zmainis green with this change on it — merge SHAdb3b42639a4b8de498bcd5876d33b7c6377f60b3; zero non-success/non-skippedcheck-runs on it. infra run
44006893237concludedsuccess.images—n/a— one Terraform file inenvs/prod; nothing that goesinto an image changed, and
detect changesskipped the image path.deploy—n/a— no deployable artifact. The change is an RDS instancecount; nothing was rebuilt or rolled out, so there is no deploy to converge.
mattered, since the apply exists only on push:
apply (prod),apply (dev)andapply (core)allsuccesson the merge SHA.Donethrough the automation rather than byhand, and the issue closed: Remove the prod Aurora reader replica (-$43/mo, gives up automatic failover) #1096 reads
state=CLOSED reason=COMPLETED.Not touched by hand.
movedblocks; re-measure the RDS line in ~3 days to confirm the saving).November 2026 cost review: findings, and why NAT Gateway has no lever #1097 owns the unrelated detached-volume question.
session memory as
aurora-count-index-destroys-the-writer, and thereasoning is in the permanent comment above the resource in
rds.tfso itis read by anyone editing it. November 2026 cost review: findings, and why NAT Gateway has no lever #1097 holds the cost measurement.
Specific to this change
the cluster still has a writer and still serves. Read back live, not
inferred from the apply conclusion:
aws rds describe-db-clusters --db-cluster-identifier er-prod \ --query 'DBClusters[0].DBClusterMembers[].[DBInstanceIdentifier,IsClusterWriter,PromotionTier]' er-prod-2 True 0Exactly one member, and it is the writer — so the
movedblocksdid their job and the surviving instance is the one that was already
serving.
er-prod-1is gone; clusterStatus=available,MinCapacity=0.5,DeletionProtection=trueunchanged.the control plane did not drop connections across the apply.
Apply window
02:59:07Z .. 03:09:06Z.DatabaseConnectionsoner-prod-2, 5-minute buckets spanning it,Minimum7.0 in everybucket including the one containing the destroy — the pool never lost a
connection, so there was no failover and no reconnect storm.
prod served without error across the apply — and the weakness of this
evidence is worth recording rather than hiding.
HTTPCode_Target_5XX_Countemitted no datapoints in
02:50Z..03:40Z, with a control proving theALB was emitting and serving (
RequestCount0/1/0/2,2XX1 and 2 — everyrequest answered 2XX, zero 5XX). But that is 3 requests across 50
minutes, because the apply ran at ~22:00 local. Three successful requests
is weak evidence of availability; the unbroken connection floor above is
what actually carries this.
delete the two
movedblocks —deferred — #1100. They are inert nowthat state sits at the name-keyed addresses, and removing them should plan
as 0/0/0.
confirm the saving landed —
deferred — #1100. Expect the RDS line tofall ~$1.44/day; re-read after ~3 days so Cost Explorer has settled. If it
does not fall, the ~$43/month figure is wrong and that is the finding.
er-prod-2is the only key in thefor_eachset, which reads oddly —deferred — #1100(§3, cosmetic). Renaming would destroy and recreate theinstance, so it is not worth doing alone; fold it into a future change that
already recreates it, or leave it.
Context — plan, discoveries, measurements, files
Plan
movedblocks so the shrink is deterministic — done.plan (prod)before merging — outstanding, and the gate.Discoveries
er-prod-2is the writer, noter-prod-1. This is what makes the naivecount = 1edit dangerous, and it was only visible by asking the cluster:ER_PG_RO_HOSTis published intoer/prod/shared/postgresbut read by noapplication code (
grep -rn 'ER_PG_RO_HOST|reader_endpoint'hits onlyTerraform). With no reader instance Aurora's reader endpoint resolves to the
writer, so the secret entry stays correct either way.
Prod is genuinely live, so this is not an idle-environment teardown:
er-prod-edgeserved 500–7,200 requests/day over 11-08..15, with 3–4sustained DB connections.
envs/dev's equivalent resource is a single un-counted block with a literalidentifier, so it does not carry the same latent hazard. No change needed.
Measurements
ServerlessDatabaseCapacityfor clusterer-prod, daily:min_capacity = 0.5, so 0.51 average is the floor. One instance at the floor is0.5 x $0.12/ACU-hr x 730 = ~$43.80/month. RDS was $71.22 month-to-date
across both environments.
Full November cost breakdown, and the separate NAT Gateway result (no lever —
three closed paths), are recorded in #1097.
Files
infra/terraform/envs/prod/rds.tf