When respective code is not there , how to prevent destroy

I have created resource group in azure using terraform, after creating I have removed that code from terraform
and wrote the code to create another resource group but now while creating this resource group why it is going destroy? which while I was implementing terraform apply.

why it is getting removed when it is available in state file?
and also what need to be done to prevent deletion when respective code is not present?

Hi @sk8228402,

Your configuration should describe the desired state for your infrastructure. If you remove a resource block then you are telling Terraform that the corresponding object should be destroyed.

If you don’t intend to destroy the object then you should leave it in the configuration.

1 Like