Interview Prep/Azure/Quota, Deployment and IaC Errors

Terraform: `Error: A resource with the ID "/subscriptions/.../resourceGroups/rg-shop-dev" already exists - to be managed via Terraform this resource needs to be imported into the State.`

IntermediateTroubleshootingQuota, Deployment and IaC Errors
Answer

Likely causes → The resource exists in Azure (created manually or by a previous run whose state was lost).

Diagnose → terraform state list | grep rg-shop-dev returns nothing.

Fix →

import {
  to = azurerm_resource_group.main
  id = "/subscriptions/<sub>/resourceGroups/rg-shop-dev"
}

Then terraform plan and apply.

Prevent → Remote state with locking and versioning so state isn't lost.

Azure All Azure questions

More on Quota, Deployment and IaC Errors