'Get state from terratest and run manually terraform destroy?

I make test with Terratest but I set wrong timeout and now test failed and resources are still there. I can remove them manually but better way will be using terraform destroy.

Is there way how get state or save them during running test via Terratest?



Solution 1:[1]

Terratest essentially just runs terraform commands with the parameters you give it in your local folder structure.

So, you should just be able to change directories to the module run by terratest (i.e. the TerraformDir) and run typical terraform commands (e.g. terraform plan, terraform destroy).

If you're asking about having the terratest do the destroy automatically for you, you can do that by passing along the same options to terraform.Destroy as in this example. The defer is recommended so that destruction happens after you have validated your resources.

Solution 2:[2]

I had the same problem. But in the output, it tells you the temporary folder where it's putting everything to run. It also had the state file. I was able to run a terraform destroy from that temp folder!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mjgpy3
Solution 2 Bennie