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

avm-tf-testing

Skill0 starsChanged 46 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.

232 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use avm-tf-pattern-review.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • Microsoft AzureSkill

    avm-tf-pattern-review

    Review an existing Azure Verified Modules (AVM) Terraform pattern module against current PTN conventions, implementation behavior, examples, and CI. Use for 'review this AVM pattern module', 'check Terraform AVM conventions', 'is this pattern AVM-ready', or 'audit AVM module compliance'. Read-only by default; verifies mocked test discovery, minimum Terraform compatibility, provider policy, and example wiring. Not a module generator, automatic fixer, or deployment workflow.

    Also in 188 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

15 rules. About 0 are common, 6 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    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.

    line 8
  2. Very specific:

    Always name the tier when tests are expected.

    line 27
  3. Very specific:

    Place tests in tests/unit.

    line 33
  4. Very specific:

    Every new resource-deploying module therefore mocks azapi.

    line 35
  5. Very specific:

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

    line 57
  6. Very specific:

    Place real-Azure Terraform tests in tests/integration.

    line 70
  7. Distinctive:

    Use hooks only for required environment preparation or cleanup.

    line 113
  8. Distinctive:

    After reviewing and committing all changes:

    line 125
  9. Distinctive:

    Use the governance-managed reusable Terraform workflow.

    line 135
  10. Distinctive:

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

    line 136
  11. Distinctive:

    Keep test environments least privilege and isolate subscriptions where practical.

    line 137
  12. Very specific:

    Treat skipped as different from pass.

    line 138
  13. Distinctive:

    Run the smallest command that reproduces the issue:

    line 143
  14. Very specific:

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

    line 153
  15. 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 155

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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. The old repository launcher, Make targets, Porch flags, and container workflow are retired.

Install-PSResource -Name Avm.Authoring -Repository PSGallery -TrustRepository
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 identities and protected environments.

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 default

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.

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.

Debugging

Run the smallest command that reproduces the issue:

avm test unit
avm test integration
avm test e2e --example default
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.