Interview Prep/Terraform/Testing and Policy as Code

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)
All Terraform questions Roadmap: Terraform in production

More on Testing and Policy as Code