0
votes

Can we destroy a particular resource.

For example : An azure sql database only, without affecting the sql server or any firewalls.

will the below work and what is the resource address.

terraform destroy -target xxx

2

2 Answers

0
votes

yes terraform has that functionality to destroy selected resources, but first you have to detached the dependent resources from the target resource and then try this command terraform destroy -target RESOURCE_TYPE.NAME

0
votes

Yes, you can destroy specific resources, one at a time.

Following the terraform azure sql example : https://www.terraform.io/docs/providers/azurerm/r/sql_database.html

When the resources are created, they are registered in the terraform state file. You can list the resources in the state file :

$ terraform state list
azurerm_resource_group.test
azurerm_sql_database.test
azurerm_sql_server.test

You can then destroy the sql database only with this command :

$ terraform destroy -target=azurerm_sql_database.test