TerraformTerraformKnown error
Terraform: resource already exists
It exists in Azure, not in your state
Terraform state
What the error looks like
- Error code
- WHO โ identity
- WHAT โ action
- WHERE โ scope
- Policy
- Correlation / trace
โ Error: A resource with the IDCODE "/subscriptions/00000000-1111-4222-8333-444444444444/resourceGroups/rg-platformWHERE" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_resource_group" for more information.
โ
โ with azurerm_resource_group.platform,
โ on main.tf line 12, in resource "azurerm_resource_group" "platform":
โ 12: resource "azurerm_resource_group" "platform" {What you told me
โTerraform is broken.โ
you ยท just now
Let's read it.
RTFE ยท seen
What it actually says
The resource exists in Azure but isn't in Terraform state. Terraform refuses to silently take ownership of it.
Azure outage? No. Terraform is protecting you from overwriting something it doesn't own.
The fix
- 01Confirm the existing resource is the one you intend to manage.
- 02Import it into state (import block on Terraform โฅ 1.5, or terraform import).
- 03Run plan and make sure it's a no-op or an expected diff.
import {
to = azurerm_resource_group.platform
id = "<resource-id-from-error>"
}terraform import azurerm_resource_group.platform "<resource-id-from-error>"Read it faster next time
The resource ID you need for import is right there in the error.