Agent skill · hashicorp

provider-test-patterns

Terraform provider acceptance test patterns using terraform-plugin-testing with the Plugin Framework. Covers test structure, TestCase/TestStep fields, ConfigStateChecks with custom statecheck.StateCheck implementations, plan checks, CompareValue for cross-step assertions, config helpers, import testing with ImportStateKind, sweepers, and scenario patterns (basic, update, disappears, validation, regression), and ephemeral resource testing with the echoprovider package. Use when writing, reviewing, or debugging provider acceptance tests, including questions about statecheck, plancheck, TestCheckFunc, CheckDestroy, ExpectError, import state verification, ephemeral resources, or how to structure test files.

What it needs

About 5k tokens when loaded.

What this skill does

Provider Acceptance Test Patterns Patterns for writing acceptance tests using terraform-plugin-testing with the Plugin Framework. Source: HashiCorp Testing Patterns References (load when needed): references/checks.md — statecheck, plancheck, knownvalue types, tfjsonpath, comparers references/sweepers.md — sweeper setup, TestMain, dependencies references/ephemeral.md — ephemeral resource testing, echoprovider, multi-step patterns --- Test Lifecycle The framework runs each TestStep through: plan → apply → refresh → final plan. If the final plan shows a diff, the test fails (unless ExpectNonEmptyPlan is set). After all steps, destroy runs followed by CheckDestroy. This means every test automatically verifies that configurations apply cleanly and produce no drift — no assertions needed for that. --- Test Function Structure Use resource.ParallelTest by default. Use resource.Test only when tests share state or cannot run concurrently. --- Provider Factory --- TestCase Fields Field Purpose ------- --------- PreCheck func() — verify prerequisites (env vars, API access) ProtoV6ProviderFactories Plugin Framework provider factories CheckDestroy TestCheckFunc — verify resources destroyed after all steps Steps []TestStep — sequential test operations TerraformVersionChecks []tfversion.TerraformVersionCheck — gate by CLI version --- TestStep Fields Config Mode Field Purpose ------- --------- Config Inline HCL string to apply ConfigStateChecks []statecheck.StateCheck — modern assertions (preferred) ConfigPlanChecks resource.ConfigPlanChecks{PreApply: []plancheck.PlanCheck{...}} ExpectError regexp.Regexp — expect failure matching pattern ExpectNonEmptyPlan bool — expect non-empty plan after apply PlanOnly bool — plan without applying Destroy bool — run destroy step PreConfig func() — setup before step Import Mode Field Purpose ------- --------- ImportState true to enable import mode ImportStateVerify Verify imported state matches prior state ImportStateVerifyIgnore []string — attrib …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills hashicorp/provider-test-patterns--20c4cd

View the source on GitHub

Browse the @skills marketplace