Terraform provider test patterns
Covers acceptance tests for Terraform providers with terraform-plugin-testing: test steps, state and plan checks, import, disappears and regression tests, sweepers and ephemeral resources. Use when writing, reviewing or debugging provider acceptance tests.
provider-test-patterns- Author
- HashiCorp
- Source
- hashicorp/agent-skills/plugins/terraform/skills/provider-test-patterns @ 5e30fa5
- License
- MPL-2.0
About this skill
What it does
The skill is a reference for acceptance tests of Plugin Framework providers written with terraform-plugin-testing. It starts from the test lifecycle: every step runs plan, apply, refresh and a final plan, a non-empty final plan fails the test unless ExpectNonEmptyPlan is set, and destroy plus CheckDestroy run at the end, so drift is caught without extra assertions. Tables list the TestCase and TestStep fields for config and import mode. It prefers ConfigStateChecks over legacy Check functions and says not to mix them in one step. Scenario patterns cover basic plus update in one test, import with ImportStateKind, a disappears step, ExpectError for validation, and regression tests committed before the fix so a reviewer can watch them fail. Helpers include custom statecheck.StateCheck types for exists and disappears, a destroy check and a PreCheck.
references/checks.md covers knownvalue types, tfjsonpath, CompareValue across steps and plan checks at each phase. references/sweepers.md shows how to register sweepers that clean up leaked test infrastructure, with dependencies and a TF_ACC=1 go test ... -sweep=<region> run. references/ephemeral.md tests ephemeral resources, which need Terraform 1.10 or later, by capturing their data with the echoprovider package.
When to use it, and when not
Use it when writing, reviewing or debugging a provider's acceptance tests, moving old Check assertions to state checks, or setting up sweepers. Acceptance tests call the real API, so they need its credentials.
It is not for .tftest.hcl tests of Terraform modules, and running a suite and reading its failures is left to HashiCorp's run-acceptance-tests skill.
How to run it
We do not copy this skill: its files are under MPL-2.0, a file-level copyleft licence outside the set we copy under. Install it from HashiCorp's repository with the button to the source: one skill via npx skills add hashicorp/agent-skills/plugins/terraform/skills/provider-test-patterns, or the whole terraform plugin via claude plugin marketplace add hashicorp/agent-skills, then claude plugin install terraform@hashicorp. In Codex: codex plugin marketplace add hashicorp/agent-skills, then install terraform from /plugins and start a new session. In Claude Code, the plugin's skill may appear as /terraform:provider-test-patterns.
- Claude Code:
/provider-test-patterns, or ask for the skill by name. - Codex:
$provider-test-patterns. - Cursor: type
/in the Agent chat and pickprovider-test-patterns.
Example: /provider-test-patterns Rewrite the Check blocks in widget_resource_test.go as ConfigStateChecks and add a disappears test.
How it differs from similar skills
Terraform provider resources writes the resource and names the minimum tests; this skill is the full reference it points to. Terraform tests tests Terraform configuration in HCL with run blocks and mock providers, not provider code in Go. Unit test writer and API contract tests are general testing skills with nothing on terraform-plugin-testing.
Install
This skill is not copied to the catalog: its licence allows a copy only under the same licence, and the catalog does not copy under such licences. Install it from the author's repository.
Connect through AnyModel API
This skill runs on whatever model your agent uses. Point Claude Code, Codex or Cursor at AnyModel to run it on Claude, GPT, Gemini and more with one key — pay per token, no subscription.
AnyModel