Terraform Terratest报错:Destroy函数未定义问题求助
Terraform.Destory未定义错误解决方案
我尝试使用Terratest测试用于部署AWS实例并托管静态网站的Terraform代码,但运行测试模块后,出现了Destroy函数未定义的错误。
问题代码
package test import ( "fmt" http_helper "github.com/gruntwork-io/terratest/modules/http-helper" "github.com/gruntwork-io/terratest/modules/terraform" "testing" "time" ) func TestTerraformHelloWorldExample(t *testing.T) { t.Parallel() // Construct the terraform options with default retryable errors to handle the most common // retryable errors in terraform testing. terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ // Set the path to the Terraform code that will be tested. TerraformDir: "../project-3/webserver", }) terraform.InitAndApply(t, terraformOptions) defer terraform.Destory(t, terraformOptions) publicIp := terraform.Output(t, terraformOptions, "public_ip") url := fmt.Sprintf("http://%s:8080", publicIp) http_helper.HttpGetWithRetry(t, url, nil, 200, "I have made a Terraform module", 30, 5*time.Second) }
错误输出
> go test webserver_test.go # command-line-arguments [command-line-arguments.test] ./webserver_test.go:23:18: undefined: terraform.Destory FAIL command-line-arguments [build failed] FAIL
解决方案
问题源于拼写错误:你调用的terraform.Destory是错误写法,Terratest中正确的销毁函数是terraform.Destroy(单词正确拼写为Destroy,而非Destory)。
修正后的代码行应为:
defer terraform.Destroy(t, terraformOptions)
将该行拼写修正后,重新运行测试即可解决该错误。
内容的提问来源于stack exchange,提问作者NIRAJ BAIS
相关产品推荐
相关产品推荐

