Skip to content

fix(infra): drop the prod Aurora reader, keyed by identifier not index - #1099

Merged
athvin merged 1 commit into
mainfrom
prod-aurora-single-instance
Nov 17, 2026
Merged

athvin merged 1 commit into
mainfrom
prod-aurora-single-instance

Conversation

@athvin

@athvin athvin commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Closes #1096

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

Warning

DO NOT MERGE until the plan (prod) output has been read. This destroys an
instance of a live, deletion-protected production database, infra-apply-prod
has no required reviewers, and the apply is unattended. The plan must show
exactly one destroy — aws_rds_cluster_instance.prod["er-prod-1"] — and
no create and no replace. Anything else means the moved blocks did not
take, 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 not
enough:
gh pr merge <n> --squash --subject '<subject> ALLOW-DESTROY'

What

Removes the prod Aurora reader replica, and re-keys
aws_rds_cluster_instance.prod from count to for_each by 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}" makes
index [1] equal er-prod-2, which is the current writer; a count = 2 -> 1
shrink 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 -recursive clean and terraform validate Success in
envs/prod. validate cannot prove the plan shape — it does not read state,
so the moved blocks are unexercised until plan (prod) runs on this PR. That
job 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 = false
and 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-d3746dc3188e on Mac-833 · 2026-11-17T03:15:00Z

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 0
    Exactly one member, and it is the writer — so the moved blocks
    did their job and the surviving instance is the one that was already
    serving. er-prod-1 is gone; cluster Status=available,
    MinCapacity=0.5, DeletionProtection=true unchanged.

  • the control plane did not drop connections across the apply.
    Apply window 02:59:07Z .. 03:09:06Z. DatabaseConnections on
    er-prod-2, 5-minute buckets spanning it, Minimum 7.0 in every
    bucket
    including the one containing the destroy — the pool never lost a
    connection, so there was no failover and no reconnect storm.

    Stated plainly: this is the RDS metric, **not** an `er-server` log line as
    this item originally asked for. Reading prod pod logs needs EKS access via
    the `er-platform` SSO profile, whose token is expired in this session. The
    substitution is defensible because the claim is specifically about
    *connections*, which this metric measures directly rather than by
    inference — but it is a substitution, and worth knowing if this item is
    audited.
    
  • prod served without error across the apply — and the weakness of this
    evidence is worth recording rather than hiding. HTTPCode_Target_5XX_Count
    emitted no datapoints in 02:50Z..03:40Z, with a control proving the
    ALB was emitting and serving (RequestCount 0/1/0/2, 2XX 1 and 2 — every
    request 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 moved blocks — deferred — #1100. They are inert now
    that 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 to
    fall ~$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-2 is the only key in the for_each set, which reads oddly —
    deferred — #1100 (§3, cosmetic). Renaming would destroy and recreate the
    instance, 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

  1. Confirm the reader is idle rather than carrying read traffic — done.
  2. Confirm nothing consumes the reader endpoint — done.
  3. Re-key by identifier with moved blocks so the shrink is deterministic — done.
  4. Read plan (prod) before merging — outstanding, and the gate.

Discoveries

  • er-prod-2 is the writer, not er-prod-1. This is what makes the naive
    count = 1 edit dangerous, and it was only visible by asking the cluster:

    aws rds describe-db-clusters --db-cluster-identifier er-prod \
      --query 'DBClusters[0].DBClusterMembers[].[DBInstanceIdentifier,IsClusterWriter]'
    er-prod-1  False
    er-prod-2  True
    
  • ER_PG_RO_HOST is published into er/prod/shared/postgres but read by no
    application code
    (grep -rn 'ER_PG_RO_HOST|reader_endpoint' hits only
    Terraform). 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-edge served 500–7,200 requests/day over 11-08..15, with 3–4
    sustained DB connections.

  • envs/dev's equivalent resource is a single un-counted block with a literal
    identifier, so it does not carry the same latent hazard. No change needed.

Measurements

ServerlessDatabaseCapacity for cluster er-prod, daily:

day avg ACU max ACU
11-09 0.52 5.0
11-10 0.51 7.0
11-11 0.52 4.0
11-12 0.53 5.0
11-13 0.51 4.5
11-14 0.52 11.0
11-15 0.51 4.5

min_capacity = 0.5, so 0.51 average is the floor. One instance at the floor is
0.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

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]>
@github-actions

Copy link
Copy Markdown
Contributor

terraform plan

11cdf57 · run log and full plans

env add change destroy
state-backend (plan only) 0 0 0
core 0 0 0
dev 0 0 0
prod 0 0 1

Planned with -refresh=false, so this is the config-versus-state diff and
not out-of-band drift. That is a security choice, not a speed one: a refreshing
plan reads secret values, and the plan role is assumable from any PR branch —
which can edit the workflow it runs under. Drift is caught at apply time, which
refreshes fully.

Warning

This plan DESTROYS resources in: prod. Merging applies it unattended.
The apply refuses to run unless the merge commit message carries
ALLOW-DESTROY. Retitling is not enough on a single-commit PR — GitHub
uses the commit message there, not the title. Merge with
gh pr merge <n> --squash --subject '<subject> ALLOW-DESTROY'.

prod — 0 to add, 0 to change, 1 to DESTROY
data.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
athvin merged commit db3b426 into main Nov 17, 2026
40 checks passed
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.
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove the prod Aurora reader replica (-$43/mo, gives up automatic failover)

2 participants