CloudOps Observer
← All labs

Azure and Terraform / Intermediate / 25–40 min

The locked Azure Terraform state

Investigate a genuine Azure Blob lease that prevents Terraform from locking its isolated remote state.

LAB IDcloudops-04-azure-state-lockTRACK / cloudops.observer
Engineer working beside connected cloud servers

The scenario

Terraform cannot acquire its remote state lock because a lab-owned lease is holding the state blob. Inspect the failure, identify the holder, and release only the lab lease before checking the state.

Mission objectives

  • Inspect the real Azure Blob lease and Terraform lock error.
  • Release only the known lab lease after confirming its holder.
  • Verify the state and a no-change plan, then destroy the isolated resources.

Watch the explanation

An explanation of Terraform state locking and the error acquiring the state lock.

Watch the video ↗

Lab README

Azure Terraform state lock

This lab provisions a uniquely named Azure resource group, storage account and private blob container with Terraform. A separate Terraform configuration uses one blob for remote state. The lab then deliberately acquires a real Azure blob lease, causing Terraform's next plan to fail to acquire its state lock.

This is a known lab-held lease, not a crashed Terraform process or a stale Terraform-generated lock. Release only the lease created by this exercise. Never disable locking, break leases or force-unlock an active production run. Do not add containers or blobs to the lab account. Teardown refuses unexpected resources or data, and removes the lab state blob and storage account.

Azure Storage and transactions can incur charges. Use an isolated subscription with known safe guardrails and clean up promptly. The storage endpoint is publicly reachable using account credentials, but anonymous blob access is disabled. The account key, Terraform state, plans and lease ID are sensitive; use a private Linux filesystem and never publish them.

Install Azure CLI, Terraform 1.5+, Python 3 and Bash on Linux. Log in and select the intended subscription. Microsoft.Resources and Microsoft.Storage must already be registered, and your identity must be able to read storage account keys. The Blob endpoint must be reachable.

export AZURE_SUBSCRIPTION_ID="your-subscription-id"
./setup.sh "$AZURE_SUBSCRIPTION_ID" northeurope --accept-costs
./lab.sh plan
./lab.sh status

Inspect the failure and the lab-owned holder before releasing it. Use ./lab.sh without arguments for the available lab-only commands, then run ./verify.sh and ./teardown.sh. Teardown releases only this lab's recorded lease and checks identity, contents and the Terraform destroy plan. It retains private state on failure and after cleanup; confirm the group is absent before removing .lab-state.

View Markdown source ↗

Get the lab

Download and inspect the installer before running it. It checks the archive's SHA-256 digest and refuses to overwrite an existing lab directory.

curl -fsSLO https://devops.download/labs/cloudops-04-azure-state-lock.sh
less cloudops-04-azure-state-lock.sh
bash cloudops-04-azure-state-lock.sh
cd labs/cloudops-04-azure-state-lock
./setup.sh "$AZURE_SUBSCRIPTION_ID" northeurope --accept-costs

When you've made your changes, run ./verify.sh. Remove lab resources with ./teardown.sh.

Download the archive instead ↗

Need a nudge?

Hint #1

Run ./lab.sh plan and inspect the lock error and ./lab.sh status before attempting recovery.

Hint #2

The lab owns a deliberately acquired lease. Only its exact lease ID and lab storage account are eligible for release; never use force-unlock on an active production run.

Hint #3 · Deep Dive Runbook on opsbreakfix.com

Read the deep dive runbook ↗

Solved it?

Read the Official Root Cause Analysis & Certification Roadmap on opsbreakfix.com

Continue to opsbreakfix.com ↗

One ecosystem.
Many perspectives.

Follow the connection from a hands-on lab to the knowledge and tools behind it.