CloudOps Observer
← All labs

Azure and Terraform / Intermediate / 20–35 min

The Azure resource Terraform cannot create

Investigate an existing Azure resource group missing from Terraform state and safely bring it under management.

LAB IDcloudops-02-azure-terraform-importTRACK / cloudops.observer
Engineer working beside connected cloud servers

The scenario

Terraform wants to create a resource group that already exists. The isolated group was created by this lab, then deliberately removed from its state. Import it without deleting or recreating it.

Mission objectives

  • Inspect the existing lab resource and the Terraform error.
  • Import the existing resource into the correct state without changing it.
  • Confirm the state and a no-change plan, then destroy the lab resources.

Watch the explanation

Why Terraform can try to create an existing Azure resource, and how to import it and review the plan without deleting it.

Watch the video ↗

Lab README

Azure Terraform import

This lab creates a real, uniquely named Azure resource group with Terraform, then removes it from local Terraform state without deleting it. An empty resource group normally has no direct charge, but Azure services and billing policies vary. Do not add resources to the group; unexpected contents block teardown. Use a disposable subscription with known safe guardrails.

Install Azure CLI, Terraform 1.5+, Python 3 and Bash on Linux. Log in and select the intended subscription. Microsoft.Resources must already be registered.

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

Terraform's state and backups are private. Run from a private Linux filesystem, not a shared or world-readable mount. Setup refuses to overwrite an existing .lab-state; preserve it if setup fails. Review plans before applying them. Never import a real resource into a second active Terraform state.

terraform -chdir=.lab-state plan -input=false
./verify.sh
./teardown.sh

Teardown checks the generated name, ownership tag, Azure contents and Terraform state before importing a missing lab resource into the state and destroying it. It refuses to delete a group with resources in it. It keeps local state afterward; remove .lab-state only after independently confirming cleanup.

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-02-azure-terraform-import.sh
less cloudops-02-azure-terraform-import.sh
bash cloudops-02-azure-terraform-import.sh
cd labs/cloudops-02-azure-terraform-import
./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

Compare the resource group in Azure with terraform state list in .lab-state.

Hint #2

Use an import block or terraform import to bring the existing lab resource into this state; do not delete and recreate it.

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.