What it does
Terratest is a Go library for integration and end-to-end tests of infrastructure code. Its helpers can run Terraform or OpenTofu, query outputs, make HTTP requests, and interact with cloud providers, containers, or Kubernetes. A test supplies the infrastructure definition, its expected behavior, and any required credentials. Unlike a static linter, Terratest can exercise a deployed test environment, so authors need a plan for resource cleanup and any resulting cloud charges.
Terratest is for checks that exercise infrastructure as a running system. In the official quick start, a Go test initializes and applies an OpenTofu configuration for a small AWS web server, reads its public IP, sends HTTP requests, asserts the response, and destroys the resources afterward. The guide illustrates running a selected test with go test -v -run TestTerraformAwsHelloWorldExample -timeout 30m. That command is an example from the documentation, not something run for this listing.
Before using the pattern, provide a Go test module, the Terraform or OpenTofu configuration, and any cloud credentials needed by the provider. The current quick-start requirements call for Go 1.26 or newer and one of Terraform or OpenTofu. The README describes additional helpers for Docker, Packer, AWS, Azure, GCP, Kubernetes, Helm, HTTP requests, and shell commands.
Because an integration test can apply real resources to an account, use a dedicated test environment, scope permissions, and arrange cleanup even when a test fails. The quick start's example explicitly destroys infrastructure after the assertion. Terratest is a test library, not an infrastructure host or a guarantee that a deployment is safe. The official repository is Apache-2.0 licensed.
Strengths
- Uses Go test functions to verify infrastructure behavior rather than only inspecting configuration syntax.
- Provides helpers for Terraform and OpenTofu as well as cloud, container, Kubernetes, and HTTP workflows.
- The quick start demonstrates applying, checking, and destroying a temporary infrastructure environment.
Watch out for
- A usable test setup needs Go plus the infrastructure tool and provider configuration relevant to the code under test.
- Tests that apply cloud resources need credentials, cleanup, and cost controls because they can create real resources.
Best for
- Platform teams testing Terraform or OpenTofu modules against a test environment
- Go developers checking infrastructure behavior after deployment
- Teams validating containers, cloud services, or Kubernetes resources in automated integration tests
Sources
- Quick start (Oct 25, 2026)
- gruntwork-io/terratest README (Oct 25, 2026)
- Apache License, Version 2.0 (Oct 25, 2026)
