Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 264
capiono Avatar asked Mar 21 '26 18:03

capiono


2 Answers

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 
like image 176
e.wic Avatar answered Mar 23 '26 22:03

e.wic


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
like image 39
Saurav Rout Avatar answered Mar 23 '26 20:03

Saurav Rout



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!