capiono
capiono

Reputation: 2997

Error: Cannot import non-existent remote object

I'm trying to import an existing resources into the terraform state. I used the following:

terraform import azurerm_resource_group.main_rg /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-cm-main

The resource group exist in the subscription with the name and ID.

but when I run the command, I get this error:

Error: Cannot import non-existent remote object

do I need to do anything special in my script before I ran this command?

Upvotes: 11

Views: 20510

Answers (2)

Saurav Rout
Saurav Rout

Reputation: 49

Here is the solution that worked for me.

export ARM_SUBSCRIPTION_ID=xxxxxxx-0000-4938-0000-cf87aexxxxxxx
terraform init -var-file="../env/${TFENV}/global.tfvars" -backend-config="../env/${TFENV}/backend.tfvars"
terraform import azurerm_resource_group.resource_group /subscriptions/xxxxxxx-0000-4938-0000-cf87aexxxxxxx/resourceGroups/xxxcore-dev-rg

Upvotes: 2

e.wic
e.wic

Reputation: 383

I've seen the problem as well. For me it worked to set the correct subscription in my az cli tool. For some reason it was trying to find the resource via az cli in the wrong subscription.

az account list -o table
az account set -s 

Upvotes: 29

Related Questions