Let’s Get Certified
Module 07 / 09 · State management

Reconcile state, drift and ownership

Choose a shared backend, coordinate writers and distinguish a refresh from a change to the actual object.

Reconcile state, drift and ownership

State records object bindings and cached attributes. A remote backend can centralize state and access control. Locking depends on the backend and its configuration. When a lock blocks an operation, establish whether a legitimate writer is active. Only consider unlocking a confirmed abandoned lock through the backend’s documented process. Preserve state history with versioning or backups.

A normal plan refreshes observations and proposes changes toward configuration. A refresh-only plan shows changes to recorded state and outputs based on remote observations. Applying a refresh-only plan does not update the configuration or repair remote objects. If a team adopts an intentional manual change, record the new intent in configuration. When changing backends, distinguish transferring existing state from starting with a new empty backend.

Without an explicit backend, the local backend normally stores the default workspace in terraform.tfstate in the working directory. To move it, configure the destination in a backend block within terraform, back up the state securely and initialize with terraform init -migrate-state. After migration, use terraform state list to confirm the expected addresses. Starting an empty backend for an existing deployment can produce a plan to create resources it already owns.

Worked case 1

A colleague’s apply holds the state lock while a second pipeline waits. Should the waiting pipeline disable locking?

Check your reasoning

Allow the active writer to finish or coordinate its controlled cancellation. Concurrent writes against the same snapshot can lose updates. Inspect the owner and timestamps before diagnosing a stale lock.

Worked case 2

A manual size increase must stay in service. A refresh-only plan shows the new size. Will applying it make the change permanent in configuration?

Check your reasoning

No. It records the observed state. Update the declared size to the approved value and inspect a normal plan to ensure the next release will retain it.

HashiCorp objective references: 6a–6d.

Terraform state and backends · Official Terraform 004 objectives for this domain

Related lesson in AWS Certified Developer – Associate. Match storage to an access pattern.

Practice with the recording

Two operators initialize a checkout after moving its backend. Which choice could leave them looking at empty state?

Check your reasoning

Migrating copies existing state to the new backend. Reconfiguring accepts a new backend configuration without copying state. Confirm the destination, workspace and state contents before planning any changes against an unexpectedly empty state.

sthithapragna · Terraform Associate 004 full course · 3:52:11

Practice the individual exam skills
  • 6a–6d Move a disposable state from a local backend to a supported locking backend and verify the resulting workspace. Introduce a harmless external change and compare a normal plan with a refresh-only plan. Explain which decision would change configuration, state or the actual object.
Knowledge check

Reconcile state, drift and ownership quiz

Answer 3 questions. Check each answer for an explanation.