简体   繁体   English

从 terratest 获取 state 并手动运行 terraform destroy?

[英]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.我用 Terratest 进行测试,但我设置了错误的超时,现在测试失败,资源仍然存在。 I can remove them manually but better way will be using terraform destroy.我可以手动删除它们,但更好的方法是使用 terraform destroy。

Is there way how get state or save them during running test via Terratest?有没有办法在通过 Terratest 运行测试期间获取 state 或保存它们?

Terratest essentially just runs terraform commands with the parameters you give it in your local folder structure. Terratest 本质上只是使用您在本地文件夹结构中提供的参数运行terraform命令。

So, you should just be able to change directories to the module run by terratest (ie the TerraformDir ) and run typical terraform commands (eg terraform plan , terraform destroy ).因此,您应该能够将目录更改为 terratest 运行的模块(即TerraformDir )并运行典型的 terraform 命令(例如terraform planterraform 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 .如果您要让 terratest 自动为您执行销毁操作,您可以通过将与本例中相同的选项传递给terraform.Destroy来实现。 The defer is recommended so that destruction happens after you have validated your resources.建议使用defer ,以便在您验证资源后进行销毁。

I had the same problem.我有同样的问题。 But in the output, it tells you the temporary folder where it's putting everything to run.但是在 output 中,它会告诉您将所有内容运行的临时文件夹。 It also had the state file.它还具有 state 文件。 I was able to run a terraform destroy from that temp folder!我能够从该临时文件夹运行 terraform 销毁!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM