Free — no signup required

Acceptance Testing

1 min read

Testing Providers the Right Way

Unit tests can validate your schema definitions and data transformation logic, but they cannot verify that your provider actually works against a real API. For that, the Terraform ecosystem uses acceptance tests — integration tests that spin up real resources against a real (or sandbox) API, verify the full CRUD lifecycle, and then clean up.

The Plugin Framework ships with a testing helper package (github.com/hashicorp/terraform-plugin-testing) that provides a test runner aware of the Terraform lifecycle.

A typical acceptance test walks through the resource's full lifecycle in three steps: apply a config that creates the resource and assert on the resulting attributes (an ID got set, the name was saved correctly, a default the API applies came through as expected), then verify the resource can be re-imported by ID alone and reconstructs identical state, then apply an updated config and assert the change took effect. Running these tests requires an explicit opt-in environment variable — a safety gate that prevents accidental real API calls during a normal test run; without it, the test framework skips all acceptance tests entirely.

The ImportState step is particularly important. It verifies that your Read method can reconstruct complete state from just an ID — which is what terraform import does. If your Read method omits any attributes, ImportStateVerify will catch the discrepancy.

This is one of 18 chapters

Every chapter is free — Kubernetes, Terraform, SRE, distributed systems, and more — with fast daily review built in.

Sign up free