Your goal
Use plans and explicit state operations to understand changes before reconciling them, then remove every workshop resource safely.
Exercise 16 ยท 75 minutes
Detect controlled drift, adopt an approved existing resource, preserve an address change, and finish with a reviewed destruction plan and verified cleanup.
Before you start
Use plans and explicit state operations to understand changes before reconciling them, then remove every workshop resource safely.
Participant task
Use Azure CLI to change the approved tag on one managed identity. Run a refresh-backed plan and explain how Terraform proposes to reconcile configuration and Azure.
az identity update --name <identity-name> --resource-group <resource-group> --set tags.<approved-key>=<drift-value>
terraform planChoose whether configuration or the approved Azure value is authoritative. Implement that decision, save a plan, apply it, and confirm a subsequent plan reports no changes.
Create one instructor-approved disposable managed identity with Azure CLI. Add matching Terraform configuration and an import block that maps its Azure resource ID to the intended address.
az identity create --name <import-name> --resource-group <resource-group> --location <location> --tags <approved-tags>Review the import plan carefully. Resolve any configuration mismatch before apply, then verify the imported address and remove the completed import block.
terraform plan -out import.tfplan
terraform apply import.tfplan
terraform state listRename the imported resource's Terraform address and add a moved block. Require a no-destroy plan and confirm its Azure resource ID remains unchanged.
Save and review a destruction plan. Confirm it contains only your workshop resources, apply that exact plan, and verify both Terraform state and Azure are clean.
terraform plan -destroy -out destroy.tfplan
terraform show destroy.tfplan
terraform apply destroy.tfplan
terraform state listExpected outcome
Describe when import, moved blocks, state repair, and destruction are appropriate, and identify which operations deserve peer review in normal engineering work.
Course complete
Delete local plan files, commit the final configuration and documentation, and provide the cleanup evidence requested by the course owner.