When do you use Terratest instead of `terraform test`?
IntermediateProductionTesting and Policy as Code
Answer
Terratest (Go) is for tests that need more than assertions on Terraform values: calling the deployed endpoint over HTTP, SSHing to a host, retries, parallel test cases and reuse of Go libraries. Typical flow: terraform.InitAndApply, validate, defer terraform.Destroy. For simpler module checks, native terraform test has less overhead and no extra language.
defer terraform.Destroy(t, opts)
terraform.InitAndApply(t, opts)
url := terraform.Output(t, opts, "alb_url")
http_helper.HttpGetWithRetry(t, url, nil, 200, "ok", 30, 10*time.Second)
More on Testing and Policy as Code
How do you test infrastructure code, and what does the testing pyramid look like?BeginnerWhat does the static-analysis layer catch?BeginnerWhat does tflint do, and how is it configured?BeginnerHow do Checkov and Trivy differ?IntermediateHow does `terraform test` work?BeginnerHow do mock providers work in `terraform test`?Advanced