CheckOps home

Tools directory

T

CheckOps

Terratest

Terratest is an Apache-2.0 Go library from Gruntwork for writing automated tests that deploy real Terraform, Packer, Docker and Kubernetes infrastructure, validate it and tear it down.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

Introduction

Terratest is a Go library that provides patterns and helper functions for testing infrastructure code. Its site describes first-class support for Terraform, Packer, Docker, Kubernetes, AWS, GCP and more. Gruntwork, the company behind the Terragrunt tooling, maintains it.

The approach is deliberately end to end. A Terratest test runs your real infrastructure-as-code tool to deploy real infrastructure in a real environment, for example terraform apply against an AWS sandbox account. It then validates that the infrastructure works by making HTTP requests, API calls or SSH connections, and finally destroys everything with a deferred terraform destroy. The website summarises the flow as deploy, validate and undeploy.

Because tests are ordinary Go tests, they run with go test, use the standard testing package and any Go assertion library, and fit into existing CI. Terratest supplies modules for each tool and cloud: terraform for init, apply, output and destroy; http-helper for retrying HTTP checks; k8s for kubectl and Helm; aws, gcp and azure helpers for querying resources; docker and packer modules; and test-structure for splitting a long test into stages you can skip while iterating.

Real deployments are slow and cost money, so Terratest encourages practices that keep suites manageable: unique resource names per run so tests can run in parallel, retries for eventually consistent cloud APIs, dedicated test accounts, and cleanup tools for resources left behind by failed runs.

In the quality loop, Terratest sits at the integration stage for infrastructure. Static checks such as TFLint or Checkov catch mistakes in code; Terratest catches the problems that only appear when the code meets a real cloud, such as IAM permissions, networking and service limits.

The source code is at gruntwork-io/terratest on GitHub under the Apache-2.0 licence, with about 8,000 stars; the most recent commit was on 11 November 2026.

Because Terratest creates real infrastructure, cost and cleanup need attention. Run tests in a dedicated account, tag resources with a test identifier, always defer destroy calls, and run a scheduled cleanup job for anything left behind after a failed run.

Features

  1. Terraform module: Init, apply, plan, output and destroy helpers, with structured plan parsing.
  2. Packer and Docker: Build images and run containers as part of a test.
  3. Kubernetes and Helm: Apply manifests, install charts and wait for pods and services.
  4. Cloud helpers: Query AWS, GCP and Azure resources to verify what was created.
  5. HTTP and SSH checks: Retry-aware helpers to validate endpoints and hosts.
  6. Retries: Utilities for flaky, eventually consistent cloud operations.
  7. Test stages: test-structure lets you skip deploy or teardown while iterating.
  8. Parallel runs: Unique IDs and namespacing so tests can run side by side.
  9. Plain Go tests: Runs with go test and standard tooling.
  10. Examples: The repository has many example modules paired with tests.

Pros

  1. Tests real behaviour: Catches problems static analysis cannot, such as permissions and connectivity.
  2. Flexible: Any Go code can be used inside a test.
  3. Free to use: Open source under the Apache-2.0 licence, so the core tool costs nothing to use.
  4. Actively maintained: The repository had commits as recent as 11 November 2026.
  5. Community: About 8,000 GitHub stars.

Cons

  1. Slow and costly: Real deployments take minutes and incur cloud charges.
  2. Go required: Teams that do not write Go face a learning curve.
  3. Cleanup risk: Interrupted runs can leave resources that need separate cleanup.
  4. Overlaps native tests: Terraform’s built-in terraform test now covers some simpler cases.

A typical test:

func TestWebServer(t *testing.T) {
  t.Parallel()
  opts := &terraform.Options{
    TerraformDir: "../examples/web",
    Vars: map[string]interface{}{"name": "tt-" + random.UniqueId()},
  }
  defer terraform.Destroy(t, opts)
  terraform.InitAndApply(t, opts)

  url := terraform.Output(t, opts, "url")
  http_helper.HttpGetWithRetry(t, url, nil, 200, "Hello", 30, 5*time.Second)
}
go test -v -timeout 30m ./test/

Practical tips:

  1. Always defer the destroy step before apply.
  2. Use a dedicated sandbox account and a scheduled cleanup job.
  3. Set a long -timeout; Go’s default ten minutes is too short for most infrastructure.

Resources:

Pricing

Terratest is free and open source under the Apache-2.0 licence.

  1. Teams publishing reusable Terraform modules that need proof they work.
  2. Platform teams validating Kubernetes, Packer or Docker builds end to end.
  3. Go-literate infrastructure engineers.
  4. Not ideal for quick checks that terraform validate, TFLint or terraform test can cover.

Conclusion

Terratest is the established way to test infrastructure code against reality. Deploying, validating and destroying real resources gives confidence that modules work, not just that they parse.

Use it for the modules that matter most, keep static checks for everything else, and budget for the time and cloud cost that real tests require.

On CheckOps, Terratest is filed under the Integration testing and Release & CI gates stages. Related tools listed here include Test Kitchen, terraform-compliance, TFLint, Checkov, Conftest and Testcontainers. Which one fits best depends mostly on your stack, your team’s size and skills, and whether you prefer to run tools yourself or pay for a managed service. This page reflects the official website, documentation and repository as they stood on 11 November 2026.

Alternatives

Other tools on CheckOps that cover similar ground. Open a page, or compare one with Terratest side by side.