Infrastructure migration and delivery
What makes a migration safe?
Infrastructure migration means changing how a service is hosted, configured or managed without losing track of its identity or its users. A good delivery plan separates changes to Terraform addresses, resource configuration, application releases and stored data. The fictional Parcel Desk service has a manually created database, a network managed by Terraform and a worker application. The business requires continued order processing and a tested recovery path. Start by documenting what exists rather than creating replacements.
Inventory and classify -> establish baseline -> adopt identity-> review plan and dependencies -> test in isolated staging-> approve exact revision -> canary -> verify service and data-> expand or halt -> reconcile -> retire only after separate approvalEvery arrow is a decision point, not permission to deploy. A failed gate stops expansion. The offline exercise provides records for reviewing decisions, not a cloud deployment.
Build an inventory and baseline
Inventory each object by provider account, region, external ID, current owner, state address (if any), dependencies and business criticality. Also record application versions, data schema, backup timestamp, restoration evidence, service-level objectives and current health. An SLO is a target for observable service behavior, such as successful requests over a stated window. An inventory entry should identify whether a resource contains durable data and whether other services rely on its address, keys or endpoint.
Fictional inventory (not live resource identifiers)orders-db | db-demo-01 | manual | durable | checkout, reportingprivate-net | net-demo-01 | Terraform | shared | database, workersworker | deployment-demo | GitOps | stateless | queue, databasebaseline | 99.9% successful requests | p95 180 ms | sample window 30 minrecovery | tested restore 40 min | observed data lag 3 minThe example targets are not universal thresholds. Identify who may approve downtime and loss of data. RTO is the recovery time objective; RPO is the recovery point objective, or tolerable data loss expressed as time. A backup timestamp alone is not proof that the backup restores within either objective. Confirm access and restoration in a safe environment. Freeze conflicting changes in the affected scope, not necessarily every system in the company.
Adopt first, refactor separately
If a real resource is unmanaged, Terraform import associates its existing identity with a destination address. Write matching configuration, inspect provider-specific import identifiers and check the plan. A successful import does not mean the configuration matches all live attributes. Defaults or omitted arguments can cause changes. For an adoption-only change, require no unrelated creates, updates, replacements or deletes. If a resource already belongs to this state and only its address changes, use a moved block rather than importing a second binding. The snippets below use an imaginary provider and cannot run.
# Illustrative only: fictional provider resource type and IDimport { to = example_database.orders id = "db-demo-01"}resource "example_database" "orders" { name = "orders"}# Later independent change, after adoption is verifiedmoved { from = example_database.orders to = module.data.example_database.orders}# Destination module and provider omitted; not runnable.The destination must be declared in the actual configuration. Verify the planned move and stable external identity, then inspect the post-change plan. Keep published module move declarations when older consumers still need them. Moving between independent state files is a separate ownership-transfer operation; a moved block alone does not move an object across backends.
Review the exact change before delivery
A change record binds the revision, environment, state/backend identity, dependency lock, plan evidence, approver, maintenance window and verification/stop criteria. The reviewer must inspect changed attributes, not just totals: a single database replacement may matter more than hundreds of harmless tags. Check security exposure, identity permissions, encryption, quotas, estimated cost and operational capacity. Tests include static validation, policy and module checks plus integration tests in authorized isolation. Keep plan artifacts access-controlled because they can contain sensitive values. In an approved local CLI workflow, a saved plan can bind review to the operation, but stale plans, changed external conditions or expired approvals require reevaluation.
# Command shapes for an authorized environment only; NOT executedterraform plan -out=reviewed.plan# Review the exact saved plan and separately check service prerequisites.terraform show reviewed.plan# Only after approval and immediately before the approved operation:terraform apply reviewed.planDo not publish the saved plan or run these commands against a real account for this worksheet. Some remote execution systems manage plans differently. The reviewed revision and plan artifact identity should be recorded with the actual runner and mode.
Coordinate infrastructure and data changes
Use an expand-and-contract sequence for a schema change: add compatible schema, deploy software that can work during the transition, backfill and verify, switch reads/writes under an agreed protocol, and remove old fields only after rollback compatibility is no longer needed. For a database move, verify replication health, consistency checks, client connection configuration and a cutover write strategy. Avoid two independent writable primaries unless the system explicitly supports and tests conflict resolution. A canary limits exposure to a small independent environment or user cohort; it is not safe to canary a shared destructive schema change merely by directing 5% of traffic to new application code.
Illustrative Parcel Desk rollout policystaging: integration + restore rehearsal passedcanary: 5% traffic for >= 30 minutes and >= 1000 requestsadvance only if error rate <= 1%, p95 <= 250 ms, lag <= 5 s,no critical alert and business reconciliation passedotherwise stop expansion; assess safe traffic rollback or correctionThese thresholds are deliberately fictional and form the exercise contract. Real monitoring should compare baseline and control groups, ensure adequate samples and check queue backlog and business correctness. A green infrastructure apply is not a service health signal. Canary gates protect the next stage; they do not prove all users or all failure modes are safe.
Recovery is a new decision, not an undo button
Reverting a Git commit may lead Terraform to propose a corrective change. It does not necessarily restore deleted rows, recover an old endpoint, undo an asynchronous request or cancel a replacement already in progress. Inspect current state, provider operation status and service evidence after a failed apply; do not assume nothing happened. A new corrective plan must be reviewed. Before moving traffic back, ensure the old system can read the current schema and contains all required writes; otherwise forward correction or controlled data recovery may be safer.
Failure example: canary error rate 3%, schema still compatibleAction: stop expansion; verify old path is healthy and data current.Failure example: destructive schema cleanup already committedAction: stop writes as authorized; preserve evidence; involve data owner;assess restore or forward repair; do not blindly revert the old binary.Document the decision owner, acceptable outage and data loss, and verification of restored data. Restoration of Terraform state is not restoration of the database. Keep destructive cleanup behind its own approval after the recovery window. Practice by reviewing the supplied case records, then continue to operational ownership.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Infrastructure migration and delivery — knowledge check
Review migration, release and operational ownership decisions.
What should an adoption-only import plan avoid?
When is a moved block appropriate?
What must a canary gate assess?
Can reverting configuration guarantee database recovery?
Why expand schema before contracting it?