agentleFS
Microsoft AzureKnown publisherAzure/terraform-azure-avm-res-fabric-capacity/.github/skills/avm-tf-testing/SKILL.md

avm-tf-testing

Skill1 starsChanged 13 days agoMITView on GitHub

Use for AVM Terraform validation, provider-mocked unit tests, real-Azure integration tests, E2E example tests, PowerShell hooks, OIDC, policy checks, and Avm.Authoring CI behavior.

231 other projects use a version of this, 4 of them edited.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

16 rules. 6 are common, 0 are distinctive, and 10 are very specific to this project.

  • 6

    Common

    Most of the 4 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 10

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use PowerShell 7.4 or later with the Avm.Authoring module from MAR.

    line 8
  2. Very specific:

    Always name the tier when tests are expected.

    line 29
  3. Very specific:

    Place tests in tests/unit.

    line 35
  4. Very specific:

    Every new resource-deploying module therefore mocks azapi.

    line 37
  5. Very specific:

    Use mocked apply so computed values and resource creation paths can be asserted without Azure.

    line 59
  6. Very specific:

    Place real-Azure Terraform tests in tests/integration.

    line 72
  7. Very specific:

    Use defaults for new modules.

    line 109
  8. Common:

    Use hooks only for required environment preparation or cleanup.

    line 137
  9. Common:

    After reviewing and committing all changes:

    line 149
  10. Common:

    Use the governance-managed reusable Terraform workflow.

    line 159
  11. Common:

    Use OIDC and a user-assigned identity or equivalent secretless federation.

    line 160
  12. Common:

    Keep test environments least privilege and isolate subscriptions where practical.

    line 161
  13. Very specific:

    Treat skipped as different from pass.

    line 162
  14. Common:

    Run the smallest command that reproduces the issue:

    line 184
  15. Very specific:

    Use -Path <module-directory> when testing a module outside the current directory and -Ecosystem terraform when context detection is …

    line 194
  16. Very specific:

    When direct Terraform debugging is necessary, keep its flags consistent with the authoring engine and return to the avm command for final …

    line 196

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

AVM Terraform Testing

Use PowerShell 7.4 or later with the Avm.Authoring module from MAR. Follow the installation prerequisites to upgrade PSResourceGet and register MAR once; it is not registered by default. The old repository launcher, Make targets, Porch flags, and container workflow are retired.

Install-PSResource -Name avm.authoring `
    -Repository MAR `
    -Scope CurrentUser
Import-Module Avm.Authoring
avm version

Test surfaces

SurfaceCommandPurpose
Terraform validationavm testRun Terraform initialization when needed and validate the module.
Unit testsavm test unitRun tests/unit/*.tftest.hcl with mocked providers.
Integration testsavm test integrationRun tests/integration/*.tftest.hcl against real Azure.
E2E examplesavm test e2eApply, idempotency-check, and destroy runnable examples/*.
Policyavm check policyBuild example plan JSON and evaluate APRL and AVMSEC through Conftest.
Full PR gateavm pr-checkRun the clean-worktree PR gauntlet; it does not replace standalone test tiers.

Always name the tier when tests are expected. Bare avm test validates Terraform; it does not run unit, integration, and E2E suites.

For Conftest findings or files under examples/<name>/exceptions, read avm-tf-conftest before changing Rego or suppressing a policy.

Unit tests

Place tests in tests/unit. Mock every provider declared by the module:

Every new resource-deploying module therefore mocks azapi. Declare or mock azurerm only when a test configures or exercises independently justified azurerm_* exception blocks.

mock_provider "azapi" {}
mock_provider "modtm" {}
mock_provider "random" {}

run "creates_the_resource" {
  command = apply

  variables {
    name      = "example"
    parent_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example"
  }

  assert {
    condition     = output.resource_id != null
    error_message = "The module should return the primary resource ID."
  }
}

Use mocked apply so computed values and resource creation paths can be asserted without Azure. Add focused tests for:

  • defaults and optional features;
  • validation failures with expect_failures;
  • conditional resources;
  • outputs;
  • parent-to-submodule propagation; and
  • resource_types, retry, timeouts, and ignore_body_changes wiring.

For detailed .tftest.hcl syntax, mocking, assertions, and troubleshooting patterns, see the Terraform test reference.

Integration tests

Place real-Azure Terraform tests in tests/integration. Do not mock providers. Keep each run focused, use unique names, and verify behaviors that cannot be proven from a mocked plan.

Test configurations, fixtures, and setup or teardown Terraform use AzAPI for every control-plane and ordinary supporting resource. If test scaffolding needs a direct Azure dependency that the module under test does not create, use an AzAPI resource, data source, or action and include Azure/azapi in that Terraform root's required_providers.

AzureRM may be configured or exercised only when required by permitted azurerm_* resource or data-source blocks. Each block must independently implement one specific unsupported data-plane/non-ARM operation, document the exact block and why no applicable AzAPI resource or action can implement it, link the upstream AzAPI issue or pull request, and be replaced when support ships. One valid block does not authorize another.

Authenticate without committed secrets. Local runs can use an authenticated Azure CLI session or supported ARM_* environment variables. CI uses OIDC with least-privilege test identities; integration tests do not require an E2E label.

E2E examples

Each direct child of examples/ is a standalone Terraform root. Discover and target examples with:

avm test e2e --list
avm test e2e --example defaults

Without --example, runnable examples execute sequentially. A .e2eignore marker excludes an example from discovery. E2E performs:

  1. Terraform initialization;
  2. deployment;
  3. a no-change idempotency plan;
  4. cleanup; and
  5. bounded retries for recognized capacity failures.

An idempotency diff is a failure and is never hidden by a retry.

Canonical example requirements

The pending public-spec addition TFNFR42 applies to executable direct roots under examples/:

Module classRequiredWAF-aligned
Resourceexamples/defaults/ and examples/waf-aligned/Required
Patternexamples/defaults/Optional
Utilityexamples/defaults/Optional

Use defaults for new modules. default is retained only for migration compatibility with existing tooling and repositories. Required examples must:

  • deploy and destroy without interactive input;
  • provide required and applicable conditional module inputs;
  • rely on module defaults for optional inputs not needed by the scenario;
  • separate test-harness prerequisites, deployment scope/setup resources, and location/telemetry controls from optional module feature overrides; and
  • omit .e2eignore.

Do not use setup/location/telemetry variables to hide a missing scenario input, and do not copy placeholder values into an example only to clear a warning. A Terraform submodule has no separate required example tree; a parent example must exercise submodule behavior included in the scenario.

An example directory named waf-aligned is not evidence of semantic WAF compliance. The scenario must implement or arrange applicable SFR2 recommendations. Backfill existing repositories by renaming a suitable existing example only; gaps or ambiguity go to the owner, not to deployment rewrites or fabricated copies.

Every runnable example and E2E configuration uses AzAPI for direct Azure setup and control-plane resources, and its required_providers includes Azure/azapi. It may include AzureRM only to configure or exercise independently justified unsupported data-plane/non-ARM blocks. A legacy /azurerm suffix in a published AVM module source is a Registry namespace and is not an AzureRM provider declaration.

For exceptional manual workflows such as distributing examples across subscriptions or retaining deployments for inspection, see the manual example-testing reference.

PowerShell hooks

Supported hooks run in isolated pwsh processes:

  • tests/unit/setup.ps1;
  • tests/integration/setup.ps1;
  • examples/<name>/pre.ps1;
  • examples/<name>/post.ps1; and
  • examples/<name>/tflint-pre.ps1.

Shell equivalents such as setup.sh, pre.sh, post.sh, or tflint-pre.sh are rejected as configuration errors. Port all hooks to PowerShell.

Use hooks only for required environment preparation or cleanup. Keep Terraform assertions in Terraform tests.

Authoring gates

Before committing:

avm pre-commit

For Terraform this applies sync, fixable convention rules, transforms, formatting, and docs. It is not a substitute for unit or real-Azure tests.

After reviewing and committing all changes:

avm pr-check

The worktree must be clean. PR check runs sync, format, transform, lint, policy, convention, validation, and docs. Unit tests are deliberately a separate reusable-workflow job rather than repeated inside PR check.

CI expectations

  • Use the governance-managed reusable Terraform workflow.
  • Use OIDC and a user-assigned identity or equivalent secretless federation.
  • Keep test environments least privilege and isolate subscriptions where practical.
  • Treat skipped as different from pass. If the change requires a test tier, an undiscovered or skipped tier is not evidence.
  • Preserve logs for failed Terraform run blocks, plans, policy findings, and cleanup failures.

PR deployment labels and merge gates

The managed workflow authorizes E2E deployments through labels rather than environment reviewer approvals. Open PRs early and add a deployment label when the changes and examples are ready, avoiding unnecessary cloud cost and runtime.

LabelSelected E2E examples
PR: Run Required E2E TestsApplicable required examples; resource modules require runnable defaults and WAF-aligned examples, while pattern and utility modules require runnable defaults only.
PR: Run All E2E TestsRequired examples and every other runnable optional example.

Static PR checks, unit tests, and integration tests are not label-gated. The Report check status merge gate requires applicable checks and all selected E2E tests to succeed, including optional examples selected by the All label. Existing required examples need either E2E label and must pass before merging; do not use .e2eignore to bypass them.

Missing required examples produce guidance but are not yet a merge failure. A new Terraform composition check may warn about missing or misplaced canonical examples, but it is advisory before v1 and must not become a merge or release gate. If no runnable required examples exist, the Required label cannot create or substitute deployments; use the All label only for actual optional examples. If no runnable examples exist, neither label can create tests. Inspect the discovery summary, sticky PR feedback, and actual test results; label selection, a successful static check, or a skipped job does not prove deployment validation passed. Report absent suites explicitly rather than claiming they passed.

Class-aware Required-label selection for pattern and utility modules and the warning-only missing-canonical-example composition check are pending Avm.Authoring/Tools behavior. The existing shared workflow still runs existing default/defaults and waf-aligned discovery. Do not represent pending behavior as published or use it as a current merge/release blocker.

Labels on fork PRs never authorize privileged deployments. Follow the process skill's reviewed fork handoff using avm release-branch before credentialed E2E testing, then apply the appropriate label to the same-repository follow-up PR. Do not expose credentials or weaken workflow permissions to run fork code.

Debugging

Run the smallest command that reproduces the issue:

avm test unit
avm test integration
avm test e2e --example defaults
avm lint
avm check policy

Use -Path <module-directory> when testing a module outside the current directory and -Ecosystem terraform when context detection is ambiguous. Use --passthru for structured results in automation. Command failures throw; do not rely on $LASTEXITCODE or parse friendly console output.

When direct Terraform debugging is necessary, keep its flags consistent with the authoring engine and return to the avm command for final validation.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.