The module toolkit
terraform, http-helper, aws, k8s.
Terratest is a collection of modules, each a helper library for a technology, and knowing what exists saves you writing glue. terraform drives Terraform. http-helper makes HTTP requests with retries (great for “is the service up?”). aws/azure/gcp query cloud resources directly to assert they exist and are configured right. k8s and helm test Kubernetes. There are also ssh, docker, and retry modules. You compose these to express “deploy X, then verify Y.”
import ("github.com/gruntwork-io/terratest/modules/terraform"http_helper "github.com/gruntwork-io/terratest/modules/http-helper""github.com/gruntwork-io/terratest/modules/aws")// after apply:url := terraform.Output(t, opts, "alb_url")http_helper.HttpGetWithRetry(t, url, nil, 200, "OK", 30, 5*time.Second) // poll until 200region := "us-east-1"bucket := terraform.Output(t, opts, "bucket_id")aws.AssertS3BucketVersioningEnabled(t, region, bucket) // query AWS directly
Assert on behavior and on the cloud
Two complementary assertion styles. Behavioral: hit the deployed endpoint with http-helper and confirm it returns what it should — proving the whole stack works end to end. Cloud-state: use the aws/azure/gcp modules to query the provider API and confirm a resource has the security-relevant configuration you expect (encryption on, versioning enabled, no public access). The best tests do both — the thing works, and it is configured safely.