Back to Terraform

AWS Data Services: RDS, Aurora, DynamoDB and Recovery Boundaries

November 6, 2026 Wasil Zafar 22 min read

Choose a database lifecycle and prove what Terraform replacement, backup restore and schema migration can each do

Table of Contents

  1. Choose Relational or Key-Value Persistence by Access Pattern
  2. Connect Subnet Groups, Security and Parameter Configuration
  3. Handle Credentials Without Assuming Sensitive Means Absent
  4. Version Schema Migrations Outside Resource Creation
  5. Test Restore and Document Irreversible Changes

Choose Relational or Key-Value Persistence by Access Pattern

Start from the query, not from the engine name. Write down the five access patterns that carry the product, with their predicates and sort order. If they join several entities, enforce constraints, or change shape under reporting, the data wants a relational engine. If every request names its key and returns one item or one page, a key-value table removes work the relational engine would do for nothing.

RDS and Aurora share a protocol, not an ownership model. An RDS instance is a database server you size: engine, class, storage and backup window are all arguments you choose. An Aurora cluster is a storage volume that grows on its own, with one writer and optional readers attached; the writer and reader endpoints are the contract the application sees. Both still leave you owning the schema, the migration order and the restore drill.

DynamoDB removes the server and moves the design into the key. There is no subnet group, no security group and no maintenance window; capacity is a table setting and the partition key decides how load spreads. That trade is real: an access pattern you did not design for becomes a scan, and a scan is a bill and a latency problem rather than a missing index.

Availability is a property of the service, not a flag you can reason about later. A single-AZ RDS instance lives in one zone; Multi-AZ adds a synchronous standby and a DNS change on failover. Aurora keeps six copies of its storage across three zones and promotes a reader, while DynamoDB replicates each table across zones in the region without a failover step. The recovery plan differs because the unit that fails differs.

The flow below follows the first three questions a team should answer, including the branch where the answer is "redesign the key".

Choose Relational or Key-Value Persistence by Access Pattern
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["List the five queries
that carry the product"] --> B{"Joins, constraints
or ad-hoc SQL?"} B -->|"yes"| C{"Traffic steady enough
to size an instance?"} B -->|"no"| D{"Every request names
its partition key?"} C -->|"yes"| E["RDS instance
engine, class and storage"] C -->|"no"| F["Aurora cluster
storage grows with compute"] D -->|"yes"| G["DynamoDB table
key design is the schema"] D -->|"no"| H["Stop: a scan is not
an access pattern"] E --> I["Write the restore drill
before the first apply"] F --> I G --> I H --> J["Reshape the key or
keep a relational store"] J --> A classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class A,B,C,D primary; class E,F,G secondary; class I ok; class H danger; class J warn;

Terraform owns the container in every case. That is the boundary the rest of this article tests: the plan can create, resize, protect and replace a database, and it never reads the rows inside it.

Three layers of an AWS data service: configuration, service controls and data Terraform declares an RDS instance, an Aurora cluster or a DynamoDB table. AWS owns backup retention, deletion protection and parameter settings. Rows, Aurora storage and DynamoDB items sit below every plan and are not recreated by an apply. Terraform owns the container; the service owns the data Each layer has a different recovery route, and only the top layer is rebuilt by an apply. Configuration — declared in Terraform state RDS instance engine, class and storage identifier is a creation choice Aurora cluster writer and reader endpoints instances attach to one volume DynamoDB table partition key and indexes capacity mode Service boundary — controls AWS enforces Backup retention one to thirty-five days zero disables PITR Deletion protection blocks destroy, not drift turn it off deliberately Parameter group family matches the engine static values need a reboot Data plane — outside every plan Rows and write-ahead log the only copy of the data a plan never reads it Aurora storage volume shared by every instance survives an instance replace Items and indexes item shape is application code Terraform sees the key only Destroy crosses every layer: the container is removed, protection stops, and the data goes with it.

Read the figure from the top down. The plan is the smallest layer and the only one that is reproducible from Git. The middle layer is policy you can review but not own. The bottom layer is the one that needs a restore you have actually performed.

The decision is reversible only at the start. Once rows or items exist, changing the engine or the key is a migration project, not a configuration edit. The comparison below is therefore about which change you are willing to perform under pressure.

DecisionRDS instanceAurora clusterDynamoDB table
Unit that scalesinstance class and storagecluster storage plus reader countpartition throughput
Network placementsubnet group and security groupsubnet group and security groupVPC endpoint and IAM
Backup controlretention, snapshots, PITRretention, snapshots, PITR, backtrackPITR and on-demand backup
Change that destroys dataengine or identifier replacementcluster identifier or engine replacementpartition key replacement or delete
Who owns the schemamigration runnermigration runnerapplication code and key design

Connect Subnet Groups, Security and Parameter Configuration

Placement is a chain: VPC, subnet group, security group, endpoint. The networking article built private subnets and a gateway endpoint; this section connects them to a database and checks each link in the order a packet takes it. A missing link fails at connect time, not at plan time, which is why the check belongs in the module rather than in a runbook.

A subnet group is a name for a set of private subnets. It is the object an instance or cluster points at, and it should span at least two Availability Zones so a failover or a replacement has somewhere to land. Renaming the group replaces it, while adding a subnet updates it in place; keep the name stable and let the subnet list change.

The database port is opened to a group, not to a CIDR. Put the application in one security group, reference that group as the source of the database rule, and keep the database private. Set publicly_accessible to false explicitly so a later module cannot flip it silently, and remove the default egress rule that allows everything outward if the engine does not need it.

DynamoDB has no subnet group and no security group. Reach it through a gateway endpoint in the private route tables, and treat the endpoint policy plus IAM as the security boundary. In a subnet without a NAT gateway, the endpoint is not an optimization; it is the only path.

The diagram separates the two paths and keeps the failure branches visible, because a timeout and a policy denial are diagnosed differently.

Connect Subnet Groups, Security and Parameter Configuration
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    APP["Application in a private subnet"] --> Q{"Which store?"}
    Q -->|"relational"| SG{"DB security group allows
the application group?"} SG -->|"yes"| DB["RDS or Aurora endpoint
on the engine port"] SG -->|"no"| TMO["Timeout, not a reset:
the packet was dropped"] Q -->|"key-value"| EP{"Gateway endpoint in
the private route table?"} EP -->|"yes"| POL{"Endpoint policy and
IAM both allow the call?"} EP -->|"no"| NAT["Call leaves for the
internet or fails"] POL -->|"yes"| TBL["DynamoDB table"] POL -->|"no"| DENY["AccessDeniedException"] PG["Parameter group family
matches the engine major?"] -->|"no"| ERR["Apply fails on
an invalid family"] PG -->|"yes"| STATIC{"Static parameter
changed?"} STATIC -->|"yes"| REB["Pending reboot
until the window"] STATIC -->|"no"| LIVE["Applied immediately"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class Q,SG,EP,POL,PG,STATIC primary; class APP,DB,TBL secondary; class TMO,NAT,DENY,ERR danger; class REB warn; class LIVE ok;

A parameter group is versioned by family, not by name. The family must match the engine major, and changing the family replaces the group; a rename does the same. The database keeps running with the old group until its argument points at the new one, so the replacement is harmless only if the new group already carries every setting.

The apply method is part of the value change. The provider defaults every parameter to immediate while AWS defaults some to pending-reboot, and AWS rejects a change that alters only the method. Change the value in the same edit, or set the method to match the service default so the next plan is empty.

Engine versions are two contracts on Aurora and one on RDS. A cluster and its instances must agree on the engine version, and a major upgrade needs the explicit allow flag on the instance. Pin the full version when reproducibility matters; a prefix such as 8.0 lets a minor upgrade move underneath you while the configuration still looks settled.

Read the plan for the replacement marker, not the diff count. A parameter group replacement costs nothing; an instance replacement costs the data unless a snapshot or point-in-time restore is already part of the change. Treat every argument marked as forcing a new resource as a data decision, not a formatting decision.

Handle Credentials Without Assuming Sensitive Means Absent

Sensitive is a display flag, not a storage boundary. The provider documentation says the master password is stored in raw state as plain text, and a saved plan carries it too. Marking an argument sensitive redacts the terminal, not the file, so encrypt the backend and treat every plan artifact as a secret.

Absent from the plan is a different guarantee, and Terraform has a name for it. A write-only argument is accepted during apply and never persisted in the plan or state. RDS exposes the master password that way as password_wo, paired with password_wo_version; the version is what you change to rotate, and it is the only part of the pair that remains in state.

A managed secret is the default when rotation matters. Setting manage_master_user_password hands the password to Secrets Manager and removes it from your configuration; it cannot be combined with a literal or write-only password. Rotation is then a service setting, every seven days by default, and the application reads the current value rather than a copy.

The secret block is computed, and its ARN is not the secret. Reference master_user_secret[0].secret_arn so the value resolves after the database is available, and check secret_status before wiring the application. The ARN is safe to pass between modules; the value behind it is not, so grant read access to the workload role and to nobody else.

The application should not need the master password at all. Enable IAM database authentication on the instance and let the workload request a short-lived token; the master secret stays for administration and migrations. DynamoDB has no password to manage, so the same discipline becomes an IAM role and a scoped policy rather than a secret.

Write-only and ephemeral solve different halves of the problem. An ephemeral value is generated for one run and never stored; a write-only argument is not stored either, but the version integer is, and only a version change triggers an update. Regenerating the ephemeral value on every run while leaving the version alone is a no-op, which is safe but easy to mistake for rotation.

Choose the path by who rotates the password, not by which syntax looks safest. A managed secret suits a platform team that wants rotation without a release; write-only suits a pipeline that already owns generation; a literal password is only defensible in a disposable lab with a disposable state file.

Version Schema Migrations Outside Resource Creation

Terraform creates the database; it has never created the schema. The instance resource takes an initial database name, and for some engines a character set, but not tables, columns or indexes. Aurora is the same container with a shared storage volume, and DynamoDB is the exception that proves the rule: its key attributes are resource arguments, while every non-key attribute is application shape that Terraform cannot see.

The migration runner owns the schema, and it keeps its own ledger. A numbered file per change, a ledger table inside the database, and one pipeline allowed to apply them is the whole contract. Flyway, Liquibase and Alembic differ in syntax; they agree that the database, not the Terraform state, is the authority on which change ran.

A provisioner is not a migration system. Running SQL from a local-exec hook hides an imperative step inside a declarative apply: there is no ledger, the step re-runs when the resource is replaced, and a failure leaves the graph and the schema half-changed at the same time. Keep the migration in a job whose output is the database's own ledger.

Order the release infrastructure, then schema, then code. Terraform can order the database before the application, but it cannot place your SQL between them because the migration is not an object in its graph. A pipeline that applies the migration after the new code ships a query for a column that does not exist yet.

Expand, migrate, contract, and never rename in one release. Add a nullable column, deploy code that writes both shapes, backfill in batches, switch reads, then drop the old column in a later release. A rename is two releases for the same reason: old code keeps running while the new version rolls out.

Aurora migrations target the writer endpoint. The reader endpoint can lag, and DDL sent there is rejected because readers are read-only. Pin the migration job to the writer and let the application use the reader for reads.

DynamoDB schema changes are key and index changes. Replacing the partition key creates a new table, while adding a global secondary index updates in place and backfills in the background. Only one global secondary index can be created or deleted at a time, so a release that adds two indexes needs two waits, not one.

The figure shows the three-release sequence and the exact point where a code rollback stops being a safe undo.

Expand and contract across three releases, with the rollback window closing at the read switch Release N adds a nullable column and writes both shapes. Release N plus one backfills and switches reads. Release N plus two drops the old column. A rollback is safe in release N, unsafe after the read switch, and requires a data restore after the drop. A schema change is a sequence, not an apply Each release is backward compatible with the one before it. The rollback window closes when reads switch. Release N — expand Release N+1 — migrate Release N+2 — contract Add a nullable column the old code still writes no read depends on it yet the ledger gains one row Backfill, then switch reads batches keep the load bounded both shapes still accepted the new column is authoritative Drop the old column constraints added last the old shape is gone a restore is the only undo Write both shapes reads still use the old column one release of overlap old code is still correct Read new, write both the overlap absorbs a rollback deploy order matters verify counts before release Read and write new the old shape is dead code drop it in a later change not in the same window Rollback is safe old code ignores the new column Rollback is unsafe old code reads a stale column No code undo restore the data, then the code A rename is two releases: add the new name, dual-write, switch reads, then remove the old name.

The rollback window is the middle release. Before the read switch, rolling code back is free. After it, the old code reads a column that is no longer authoritative, so the fix is forward or a restore. Document that boundary in the release record, because it is the fact an incident responder needs first.

Test Restore and Document Irreversible Changes

A backup is a copy; a restore is a procedure. Retention tells you what the service kept, not whether your team can turn it into a running database. The only evidence that matters is a restore performed against a scratch target, timed, queried and written down.

RDS retention is bounded by two numbers and one flag. Automated backups cover one to thirty-five days through backup_retention_period, and zero disables point-in-time recovery as well. Deletion removes those backups immediately unless delete_automated_backups is turned off, so a delete is a data-loss event unless a final snapshot or an export already exists.

Deletion protection changes the failure mode of destroy, which is the point. With protection on, a destroy fails before anything is removed, and the operator has to disable it deliberately. The final snapshot path has its own trap: the instance resource requires an identifier whenever skip_final_snapshot is false, which is the default, and reusing that identifier makes the second destroy fail on the existing snapshot.

Restores create new resources, so cutover is part of recovery. A snapshot_identifier or a restore_to_point_in_time block produces a new instance with a new endpoint; it does not rewind the old one. On Aurora the provider documentation warns that a point-in-time restored cluster starts with the default security group, so reattach the application group and the parameter group before the application is pointed at it.

DynamoDB recovery has a bounded window and a new table name. Point-in-time recovery keeps thirty-five days by default, and a restore creates another table from the chosen timestamp rather than rewinding the original. The application keeps reading the old name until you switch it, so the cutover is a configuration change with its own review.

Some changes have no undo at all. Turning encryption on for an existing unencrypted database is a restore and cutover, not a toggle; an engine change is a new database; a DynamoDB partition key change is a new table; and scheduling a KMS key for deletion makes every snapshot encrypted with it unrestorable. A dropped column is equally final once the last backup that contained it expires.

The lab below turns those claims into a trace you can run in a disposable account, including the deletion step most drills skip.

Lab

Test Restore and Document Irreversible Changes

Execution status: design-only. This trace was written against Terraform 1.17.1 and hashicorp/aws 6.72.0 on 6 November 2026. It was not run against a live account, so every expected result below is documented behavior rather than a measurement.

Prerequisites. A disposable AWS account, a VPC with two private subnets in different zones, a DynamoDB gateway endpoint, an SSO profile allowed to create RDS, DynamoDB and Secrets Manager resources, and a state bucket you can destroy. Use the smallest instance class the engine offers, and never point the restore step at a database you intend to keep.

The change under test. One nullable column on an orders table, plus point-in-time recovery enabled on a DynamoDB table. The drill restores both to a timestamp before a known write, then deletes the copies and records what disappeared.

  1. Baseline the pair. Apply the root, confirm a second plan is empty, and record the instance identifier, the retention days and the recovery status in one line of the release record.
  2. Turn on recovery before writing. Enable point-in-time recovery on the table and wait for the status to read enabled; the provider notes it can take ten minutes on a new table.
  3. Write one known fact. Insert an order with a fixed key, and record the UTC time to the minute immediately before the write. That timestamp is the restore target, not the time on your laptop.
  4. Restore RDS to a scratch name. Wait until the recorded time sits inside the restorable window, then run a point-in-time restore and expect a new endpoint with the row absent. Confirm the original instance is still serving.
  5. Restore the table. Restore to a new table name at the same timestamp, then query the fixed key directly. Do not trust the item count, which is a periodic estimate.
  6. Break the copy. Delete the scratch instance with the final snapshot skipped and automated backup deletion left at its default, then confirm the instance and its own automated backups are gone. This is the irreversible step, performed only on the disposable copy.
  7. Time the recovery. Measure from the restore request to the first successful query, and write the duration into the record beside the timestamp.
  8. Clean up and compare. Destroy the scratch root, confirm the restored table and instance are gone, and keep the record rather than the credentials.
ObservationPassing resultFailing result means
Restore target existsnew endpoint or table name, original untouchedthe block was treated as an in-place edit
Known row after restoreabsent at the chosen timethe timestamp was after the write
Table item counttreated as an estimate, key queried directlythe drill trusted a stale number
Delete with skip and defaultsinstance and its automated backups gonedelete_automated_backups was overridden
Application cutoverconnection string changed in one reviewed placethe old name is still hard-coded

Cost dimensions. The instance runs for the hours the drill takes, storage bills per GB-month, and backup storage bills beyond the free allowance. DynamoDB bills per request and for the recovered copy; delete both copies the same day.

Sources. The RDS point-in-time restore behavior follows the RDS User Guide, the DynamoDB window follows the DynamoDB Developer Guide, and the argument behavior follows the 6.72.0 provider documentation.

Next in the Series

In Serverless AWS: Lambda Artifacts, API Gateway and Event Permissions, we'll explore Promote immutable application code and wire API and event sources with precise execution identities.