Terratest vs Terraform Test: Which One Should You Actually Use?
by Gary Worthington, More Than Monkeys

Testing infrastructure has always been awkward. You want enough coverage to feel confident, but you don’t want to spin up half of AWS every time you push a commit. For a long time, Terratest was the go-to answer; a Go-based framework that lets you write automated tests for your Terraform modules.
Then, in Terraform 1.6, HashiCorp introduced Terraform Test: a lightweight, native testing framework built right into Terraform itself.
The result is that we now have two very different ways to test the same thing. Both are useful. Both have limits. The trick is knowing which to use, and probably more importantly when.
Understanding the two tools
Terratest is a Go library built by Gruntwork. It’s been around for years and is used by thousands of teams to perform end-to-end and integration testing of Terraform, Packer, and Kubernetes modules. It’s incredibly flexibl. You can deploy real infrastructure, make HTTP requests, and assert that everything works in practice.
Terraform Test, on the other hand, is HashiCorp’s official testing framework. Tests are written in HCL or JSON (.tftest.hcl or .tftest.json) and run directly via the Terraform CLI. It’s designed to test Terraform itself (not the infrastructure it creates) by validating plans, outputs, and logic. Think of it as “unit testing for Terraform modules.”
Comparing Terratest and Terraform Test
Terraform now gives you two very different ways to test your infrastructure code: the long-standing Terratest, and HashiCorp’s newer Terraform Test.
Both aim to increase confidence in your infrastructure, but they sit at different ends of the testing spectrum.
1. Language and ergonomics
Terratest lives in the Go ecosystem. You write tests just like any Go program, using go test and Gruntwork’s helpers. It’s developer-friendly, expressive, and powerful — but it means introducing another language and runtime to your stack.
Terraform Test keeps things inside Terraform. Tests are written in HCL or JSON with run and assert blocks. There’s no need to touch Go or manage extra dependencies.
If your team already works in Go, Terratest feels natural. If not, Terraform Test keeps things simple and familiar.
2. Scope and depth
Terratest operates in the real world. It can stand up actual infrastructure, make API calls, and confirm that the system behaves as expected.
Terraform Test is more focused on validation at the Terraform layer — confirming that outputs are correct, variables behave as expected, and modules produce the right plan. With the introduction of mock providers, it’s becoming increasingly capable of “unit-style” testing.
In practice:
Terraform Test proves your code is right.
Terratest proves your infrastructure works.
3. Speed and cost
Terratest’s realism comes at a price: time and money. Spinning up infrastructure takes minutes and may incur cloud costs if you forget to clean up.
Terraform Test is fast and free. It runs in memory, often without creating any resources at all. That makes it ideal for quick checks in CI pipelines.
A good balance is to run Terraform Test on every commit and reserve Terratest for integration pipelines or pre-release checks.
4. Flexibility and expressiveness
Terratest gives you the full power of Go. You can use loops, conditions, custom assertions, and even external API calls. It’s perfect for complex workflows that cross multiple systems.
Terraform Test is deliberately constrained. It’s declarative, readable, and predictable, but it won’t handle dynamic logic or branching flows.
That simplicity is part of the appeal, fewer moving parts, fewer surprises, but it means some real-world behaviours are out of reach without Terratest.
5. Maintenance and learning curve
Terratest introduces Go into your stack, along with dependency management and structure that mirrors software projects. For teams comfortable with Go, it’s fine; for others, it’s overhead.
Terraform Test has almost no learning curve. If you know Terraform, you can write tests immediately. The syntax mirrors standard HCL, which keeps everything consistent and familiar.
Over time, Terratest codebases can grow large and intricate, while Terraform Test files tend to stay small and focused. Each suits different levels of complexity.
6. Maturity and ecosystem
Terratest has been in production for years. There’s a wealth of community examples, helper libraries, and patterns across AWS, GCP, and Kubernetes.
Terraform Test is newer and still maturing. Documentation is improving, and adoption is growing quickly as teams move to Terraform 1.6+, but it doesn’t yet match Terratest’s ecosystem.
If you need proven, production-ready tooling today, Terratest is safer. If you’re building for the future, Terraform Test is where HashiCorp’s attention is heading.
7. Versioning and compatibility
Terratest works with almost any Terraform version, including older stacks.
Terraform Test only exists from version 1.6 onwards.
For modern greenfield projects, that’s fine. For legacy or mixed environments, Terratest gives you broader compatibility.
8. Isolation and side effects
Terratest interacts with the real world, which means managing teardown and avoiding resource leaks. It’s powerful, but it carries risk.
Terraform Test is clean and deterministic. Mock providers and plan-based assertions make it safe to run repeatedly with no side effects.
Think of Terratest as a live-fire exercise, and Terraform Test as a simulator. In my opinion, you need both for confidence.
9. CI and automation
Terratest integrates with any CI that can run go test, but tests take longer and require real credentials.
Terraform Test runs directly through terraform test, which makes it trivial to add to pipelines.
My general feeling is:
Run Terraform Test on every pull request for fast feedback.
Run Terratest less often for deep validation before production.
Using both together
You don’t have to pick sides. The most effective setups use both tools in layers.
- Start with Terraform Test to validate that your modules behave as expected — inputs, outputs, and logic.
- Add Terratest when you want to test how those modules behave for real in a deployed environment.
- Use frequency to balance cost and confidence: run Terraform Test on every build, and Terratest nightly or before release.
- Leverage mock providers to reduce the need for live infrastructure when testing Terraform logic.
- Evolve gradually: start lightweight, and add deeper testing as your system grows in complexity.
This layered approach gives you quick, cheap validation where it matters most and realistic assurance when it really counts.
The bottom line
Terratest and Terraform Test aren’t rivals. They’re complementary tools designed for different depths of testing.
Terraform Test gives you rapid feedback, integrated directly into Terraform.
Terratest gives you the ability to validate how your infrastructure behaves in the real world.
Use Terraform Test to move fast, and Terratest to sleep well.
Gary Worthington is a software engineer, delivery consultant, and fractional CTO who helps teams move fast, learn faster, and scale when it matters. He writes about modern engineering, product thinking, and helping teams ship things that matter.
Through his consultancy, More Than Monkeys, Gary helps startups and scaleups improve how they build software — from tech strategy and agile delivery to product validation and team development.
Visit morethanmonkeys.co.uk to learn how we can help you build better, faster.
Follow Gary on LinkedIn for practical insights into engineering leadership, agile delivery, and team performance.