Capstone change, drift and recovery review
Review the evidence, not just the diff
The LedgerLeaf staging environment now has one manually managed database, a new module layout and a changed firewall rule. Your job is to decide which changes can proceed and which require investigation. An infrastructure plan predicts proposed actions based on available inputs and refreshed observations. It does not prove service availability, restore capability or regulatory compliance. Separate adoption, address refactoring, drift correction and data migration into distinct changes. Preserve a clear owner for each object and a single writer for each state.
Evidence bundle (fictional)revision: r17; environment: staging; variant: awsintent: address-only refactor; object: db-demo-01expected: no create/update/delete/replace; state address changes onlyapproval: bound to reviewed plan digest; verification: service checks + identity matchrecovery: data restore drill separate from state backupThe record is a teaching format, not Terraform show -json output. Do not fabricate a plan artifact or use this record as input to terraform apply.
Adopt and refactor without replacing data
Inventory the existing database by account, region, provider identity and external ID. Verify that it is not already owned by another state. Write configuration matching the actual resource and review an import plan. The provider determines the identifier syntax. For address-only refactoring inside the same state, use a moved block after confirming the old and new addresses refer to the same object. The following is static HCL for discussion; the resource declarations and provider configuration are intentionally absent.
# Illustrative only: fictional ID and incomplete configurationimport { to = aws_db_instance.ledger id = "db-demo-01"}# Separate later revision; address move within the same statemoved { from = aws_db_instance.ledger to = module.data.aws_db_instance.ledger}For the import-only stage, require the intended import and no unrelated resource actions. For the later move, require no replacement or data modification. A move across separate states needs a separate reviewed ownership-transfer procedure; do not assume moved solves that. If the plan proposes replacement because an immutable field differs, stop and investigate before applying. Do not delete the database to make the plan clean.
Diagnose drift and choose a response
Drift is divergence between desired configuration and observed infrastructure. Suppose an emergency operator expanded database ingress. Determine who changed it, why, whether the change is still needed and whether it violates the security boundary. A refresh-only plan updates state and outputs to match remote objects; it does not repair public ingress. Normal planning can show a correction toward desired configuration. If the operator change is approved and safe, update configuration and review it; otherwise restore the intended rule through a reviewed corrective change. For an active exposure escalate through the incident process. Avoid broad ignore_changes rules that conceal security drift.
Observed record: database_public = trueDesired record: database_public = falseIncident: investigate access logs, contain, verify identity scopeDecision: HOLD until approved correction and post-change checksNot a fix: merely refreshing stateThe same reasoning applies to manually adjusted capacity. Approved temporary changes need an owner, expiration and reconciliation plan. A refresh-only operation may still read provider APIs and its apply writes state; none of those commands are run in this exercise.
Plan migration and canary release
When moving to the Azure variant, validate data types, queries, transactions, identity and application compatibility before promising migration. Establish a baseline with counts, totals and representative business invariants. Test an isolated copy using synthetic invoices. Use a migration checkpoint, replication or controlled write pause as appropriate to the selected engines. Keep one authoritative writer; do not improvise dual writes. Establish a cutover decision owner, verify data reconciliation, then gradually increase traffic only if rollback or forward recovery has been rehearsed.
Fictional staging gatesobservation >= 30 minutes and >= 1000 requestserror rate <= 1%; p95 latency <= 250 msreplication/checkpoint lag <= 5 minutesinvoice count and total reconcile; no critical alertsapproval matches exact revision and artifactif any evidence missing: HOLDThese thresholds are exercise assumptions. A real team defines meaningful sample sizes, service SLOs and business checks based on traffic. A short canary with zero errors and ten requests is weak evidence. If reconciliation fails, stop expansion and determine whether any customer writes reached the new database.
Recover service and data separately
State recovery restores the mapping between Terraform addresses and objects. Database recovery restores business records. Do not substitute one for the other. LedgerLeaf has a fictional restore drill that took 42 minutes with a 3-minute recovery point, meeting its modeled RTO and RPO. A later incident with 8 minutes of unrecoverable writes would breach the RPO even if the application restarts instantly. Escalate data-loss risk and preserve evidence. Returning traffic to the old version is safe to consider only when schema compatibility and data authority have been verified; otherwise plan a forward correction or controlled recovery with the data owner.
Scenario A: old version healthy + schema compatible + writes reconciled -> review traffic returnScenario B: new writes not reconciled or schema incompatible -> stop expansion; escalate data recoveryScenario C: state backup available but data restore untested -> do not declare recoveredFor recovery evidence record timestamps, authorized operators, selected backup, restore target, observed data loss, integrity checks and elapsed recovery time. Infrastructure replacement, database deletions and external asynchronous operations cannot be undone simply by reverting Git.
Retire resources and complete the evidence package
The required capstone creates no cloud resources. For offline teardown remove only learner-created copies or temporary files after retaining your decision records; no Terraform state or plan is shipped. A hypothetical live retirement would need separate authorization, dependency inventory, retention and legal-hold checks, tested recovery, consumer cutover, a reviewed scoped destroy plan and verification of remaining resources and billing. Do not destroy shared backend storage or a database merely because an application root is retired.
Retirement checklist (fictional)[ ] no remaining consumers or pending operations[ ] data retention and restore evidence signed off[ ] target environment and owned resource scope confirmed[ ] destructive plan separately reviewed and approved[ ] post-retirement inventory and billing checkedUse reference/change-cases.json to defend each decision before reading expected outcomes. Run check_capstone.py for positive and negative assertions. Submit a migration plan, drift diagnosis, recovery decision, teardown plan and risk register. Review the rubric: a passing checker is evidence of this model only, not a provider test. You have completed the planned tutorial chapter sequence once the two capstone lessons and practices are reviewed; publication, native tests and technical inventories are separate work.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Capstone change, drift and recovery review — knowledge check
Review capstone design and operational decisions.
What is the right first action for an adoption plan that replaces a database?
What is a moved block for in this exercise?
Does refresh-only repair an insecure live firewall?
When is traffic return a candidate for review?
What is required before hypothetical durable resource retirement?