1
votes

I am currently writing a Terraform file which should create all required resources in Azure in a specific resource group. As I do not have the permissions to create resource groups I imported an existing resource group following this link.

Now the problem is that when I run terraform destroy, the system also wants to delete the resource group as it was included as a resource. Is there a simple way I can tell Terraform to destroy all created resources except the imported resource group? Or another way to approach this problem?

I tried the lifecycle variable prevent_destroy but it prevents any resource from being destroyed. The solution presented here does not really work for me as I do not want to use multiple commands as this adds the risk of human error. What I am basically looking for is a way to label the resource group in the Terraform file in a way that it is not deleted.

1
if you dont want to manage it, why import?gsb22

1 Answers

1
votes

If you want to refer to a resource but not have Terraform manage the lifecycle of it (either at all or just in that specific Terraform workspace) then you can use data sources.

In your case you could replace the azure_resource_group resource with the azure_resource_group data source.