apex-terraform-test
Skill216 starsChanged 2 months agoMITView on GitHub
**WORKFLOW SKILL** — Write and run Terraform tests (.tftest.hcl). WHEN: "create terraform test", "write tftest", ".tftest.hcl", "mock provider", "test module", "test assertion". USE FOR: test files, run blocks, assertions, mock providers, plan-mode unit tests, apply-mode integration tests, test troubleshooting. DO NOT USE FOR: Bicep code, architecture decisions, deployment (use apex-azure-deploy).
In this repository40 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- apex-agent-authoringSkill
- apex-azure-adrSkill
- apex-azure-artifactsSkill
- apex-azure-bicep-patternsSkill
- apex-azure-cloud-migrateSkill
- apex-azure-complianceSkill
- apex-azure-computeSkill
- apex-azure-cost-optimizationSkill
- apex-azure-defaultsSkill
- apex-azure-deploySkill
- apex-azure-diagnosticsSkill
- apex-azure-governance-discoverySkill
- apex-azure-kubernetesSkill
- apex-azure-kustoSkill
- apex-azure-prepareSkill
- apex-azure-quotasSkill
- apex-azure-rbacSkill
- apex-azure-reliabilitySkill
- apex-azure-resourcesSkill
- apex-azure-storageSkill
- apex-azure-upgradeSkill
- apex-azure-validateSkill
- apex-context-managementSkill
- apex-entra-app-registrationSkill
- apex-github-operationsSkill
- apex-golden-principlesSkill
- apex-host-debug-log-exportSkill
- apex-host-git-commitSkill
- apex-host-workflow-startSkill
- apex-iac-commonSkill
- apex-mermaidSkill
- apex-microsoft-docsSkill
- apex-python-diagramsSkill
- apex-terraform-patternsSkill
- apex-terraform-search-importSkill
- apex-unslopSkill
- apex-vendor-promptingSkill
- apex-workflow-engineSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 4 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Write, organize, and run Terraform's built-in test framework for Azure infrastructure modules.
- Very specific: line 87
Use mock_provider "azurerm" with mock_resource and mock_data blocks.
- Distinctive: line 108
Use mocks for offline checks, and investigate any resources reported after failed cleanup.
- Very specific: line 113
Plan mode first: Use command = plan for fast, cost-free validation
- Distinctive: line 116
Variable coverage: Test multiple combinations for all code paths
- Distinctive: line 117
Mock for speed: Use mock providers in CI without Azure access
- Very specific: line 118
Negative testing: Use expect_failures for validation rule coverage
- Very specific: line 119
Sequential only when needed: Only chain run blocks via run.<name> when required
- Very specific: line 123
Run terraform init, then use terraform providers schema -json to validate that resource types referenced by assertions exist in the …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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.
Files
Terraform Test Skill
Write, organize, and run Terraform's built-in test framework for Azure infrastructure modules.
Reference: Terraform Testing Documentation
Quick Reference
| Concept | Description | Min Version |
| Test file | .tftest.hcl in tests/ directory | 1.6 |
| Run block | Single test scenario with assertions | 1.6 |
| Assert block | Condition that must be true for test to pass | 1.6 |
| Plan mode | command = plan — validates logic, no resources created | 1.6 |
| Apply mode | command = apply (default) — creates real infrastructure | 1.6 |
| Mock provider | Simulates provider without real API calls | 1.7 |
| Parallel execution | parallel = true on independent run blocks | 1.9 |
| Expect failures | Verify validation rules reject invalid input | 1.6 |
File Structure
my-module/
├── main.tf
├── variables.tf
├── outputs.tf
└── tests/
├── defaults_unit_test.tftest.hcl # Plan mode (fast)
├── validation_unit_test.tftest.hcl # Plan mode (fast)
└── full_stack_integration_test.tftest.hcl # Apply mode (creates resources)Naming convention: *_unit_test.tftest.hcl (plan mode), *_integration_test.tftest.hcl (apply mode).
Test File Components
- 0–1
testblock (test-wide settings) - 1+
runblocks (test scenarios, sequential by default) - 0–1
variablesblock (file-level inputs, highest precedence) - 0+
providerblocks (provider configuration) - 0+
mock_providerblocks (simulated providers, TF 1.7+)
Canonical Example
See references/test-examples.md for a complete Azure Resource Group test
(unit tests, tag validation, expect_failures).
Key Syntax Rules
Run Block Attributes
| Attribute | Type | Default | Description |
command | plan/apply | apply | Test mode |
variables | block | — | Override file-level variables |
module | block | — | Test alternate module (local/registry only) |
assert | block (1+) | — | Validation conditions |
expect_failures | list | — | Expected validation failures |
Assert Syntax
assert {
condition = <boolean expression>
error_message = "Human-readable failure description"
}Assertions can reference: resource attributes, outputs, run.<name>.<output>, var.*, data sources.
Variables precedence: run-block > file-level > all other sources.
See references/test-examples.md for module blocks, plan options, and prior run references.
Mock Providers (TF 1.7+)
Simulate Azure provider without API calls — ideal for unit tests.
Use mock_provider "azurerm" with mock_resource and mock_data blocks.
When to use: Unit tests, CI without Azure credentials, fast local development.
When NOT to use: Integration tests, validating actual Azure API behavior.
See references/mock-providers.md for full mock patterns and examples.
Common Test Patterns
See references/test-examples.md for: conditional resources, tag validation,
resource count with for_each, variables precedence, and prior run references.
Steps
terraform test # All tests
terraform test -filter=tests/defaults_unit_test.tftest.hcl # Specific file
terraform test -verbose # Detailed output
terraform test -test-directory=integration-tests # Custom test directory-filter selects test files, not run-block names. Apply-mode tests create real resources
and attempt cleanup automatically; obtain deployment authorization before running them.
Use mocks for offline checks, and investigate any resources reported after failed cleanup.
Rules
- Naming:
*_unit_test.tftest.hcl/*_integration_test.tftest.hcl - Plan mode first: Use
command = planfor fast, cost-free validation - Clear error messages: Describe what went wrong and expected state
- Test isolation: Independent run blocks where possible
- Variable coverage: Test multiple combinations for all code paths
- Mock for speed: Use mock providers in CI without Azure access
- Negative testing: Use
expect_failuresfor validation rule coverage - Sequential only when needed: Only chain run blocks via
run.<name>when required
Provider Schema Validation
Run terraform init, then use terraform providers schema -json to validate
that resource types referenced by assertions exist in the selected provider.
See apex-azure-defaults/references/terraform-conventions.md for the canonical
metadata source policy.
Reference Index
| File | Contents |
references/test-examples.md | Canonical example, common patterns, variables, module blocks |
references/test-patterns.md | Unit vs integration patterns, CI/CD examples, complex assertions |
references/mock-providers.md | Mock provider setup, mock resources/data sources, override files |
references/test-execution.md | CLI commands, parallel execution, verbose/debug, diagnostics |
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
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.

