How to destroy resources from particular workspace in Terraform?

3.3k Views Asked by At

I have created resources in a different workspace in Terraform but I am not able to destroy resource from one specific workspace. Is there any way to destroy resources by specifying the workspace?

I have tried switched to that specific workspace while destroying resources but it is still pointing to other workspace's state file.

I am using the below commands:

Terraform workspace new test
Terraform apply -var-file terraform.test.tfvars 
Terraform destroy
1

There are 1 best solutions below

3
On

You have to first select the workspace with the following command

terraform workspace select <workspace_name>

Then you can destroy the workspace with

terraform destroy -refresh=false

if you want to list the workspaces created use

terraform workspace list