Asterix
Asterix

Reputation: 433

Terraform state rm command

I have created a azure terraform template to create a resource group and a vnet. I have run terraform plan and then apply . Created the environment. Now, for testing purpose some one has created a storage account through Azure portal in the same resource group. Ever since then, whenever I run terraform plan, its showing the resource group to be destroyed state.

Hence I renamed the resource group in the template, and ran the terraform plan. its showing new resource group creation along with the deletion of existing one.

I know this is happening , because terraform state file is having the information of the existing resource group. I am trying to remove the existing resource group from the state file by the below command

terraform state rm azurem_resource_group.rg <"subscription ID of the resource group">

I am getting the below error

enter image description here

Is there a way to remove the reference of existing resource in the state file ,so that it doesnt end up in deletion?

Many thanks in advance.

Upvotes: 0

Views: 2408

Answers (1)

Nancy Xiong
Nancy Xiong

Reputation: 28304

To remove the reference of the existing resource group in the state file, you could run it without providing the specific resource id.

terraform state rm azurerm_resource_group.rg

enter image description here

You also could show the state with terraform state list.

Upvotes: 1

Related Questions