Terraform Contribution Flow
This guide covers the end-to-end contribution flow for AVM Terraform modules.
Whether you are a module owner or an external contributor, the core workflow is the same — the key differences are called out using tabs below.
Important
Every new AVM Terraform module MUST use AzAPI for every control-plane resource and supported data-plane operation. AzureRM is permitted only for a specific unsupported data-plane/non-ARM API operation under the narrow TFFR3 exception. The same rule applies to submodules, examples, end-to-end tests, Terraform tests, fixtures, and documentation snippets.
This guide MUST be used in conjunction with the Terraform specifications. All AVM modules must meet the requirements described in those specifications.
Prerequisites
Install PowerShell 7.4 or later, start pwsh, and follow the prerequisites to upgrade PSResourceGet and register Microsoft Artifact Registry (MAR). Then install the Avm.Authoring module:
Install-PSResource -Name avm.authoring `
-Repository MAR `
-Scope CurrentUser
Import-Module Avm.AuthoringRun avm with no arguments to list the supported verbs, then verify the installed version and diagnose your local environment:
avm
avm version
avm doctorTo update from MAR, repeat the install command with -Reinstall, then start a new PowerShell session; avm update still uses PowerShell Gallery. Avm.Authoring downloads, verifies, and caches Terraform, TFLint, terraform-docs, Conftest, and mapotf on demand. Docker or Podman is not required. You can inspect or manage the tool cache:
avm tool list
avm tool which terraform
avm tool install terraform
avm doctor --installWarning
The local Avm.Authoring migration and the centrally managed CI workflow rollout are separate changes. The CI guidance below applies after the updated workflow is rolled out. Do not pre-emptively rename required checks; use the exact Report check status context reported by the updated workflow.
Overview
---
config:
nodeSpacing: 20
rankSpacing: 20
diagramPadding: 50
padding: 5
flowchart:
wrappingWidth: 300
padding: 5
layout: elk
elk:
mergeEdges: true
nodePlacementStrategy: LINEAR_SEGMENTS
---
flowchart TD
Z("1 - Fork [optional]")
click Z "#1-fork-optional"
A(2 - Branch)
click A "#2-branch"
B(3 - Implement your code change)
click B "#3-implement-your-code-change"
C(4 - Run avm pre-commit)
click C "#4-run-avm-pre-commit"
C2(5 - Run pr-check and test tiers locally)
click C2 "#5-run-pr-check-and-test-tiers-locally"
D(6 - Raise or Update PR)
click D "#6-raise-or-update-pr"
E("7 - Approve and monitor CI tests [owner]")
click E "#7-approve-and-monitor-ci-tests"
F{Tests passing?}
G(8 - Review and merge PR)
click G "#8-review-and-merge-pr"
H(9 - Cut a release)
click H "#9-cut-a-release"
Z --> A
A --> B
B --> C
C --> C2
C2 --> D
D --> E
E --> F
F -->|no| B
F -->|yes| G
G --> H
1. Fork [optional]
Note
This step is only needed if you do not have write access to the module repository. Module owners and invited collaborators can skip to step 2.
A fork is your own copy of the repository under your GitHub account. It lets you make changes without needing write access to the upstream repo. Once your changes are ready, you raise a pull request from your fork back to the original repository.
Navigate to the module repository in the
AzureGitHub organization.Click the Fork button in the top right.
Select your GitHub account (or organization) as the destination.
Click Create fork.
Clone your fork locally:
git clone https://github.com/<your-username>/terraform-azure-avm-res-<rp>-<modulename>.git cd terraform-azure-avm-res-<rp>-<modulename>
Keep your fork in sync with the upstream repository before creating a new branch. You can do this from the GitHub UI by clicking Sync fork on your fork’s main page, or locally:
git remote add upstream https://github.com/Azure/terraform-azure-avm-res-<rp>-<modulename>.git
git fetch upstream
git checkout main
git merge upstream/mainUse the GitHub CLI to fork and clone in one step. This automatically configures the upstream remote for you:
gh repo fork Azure/terraform-azure-avm-res-<rp>-<modulename> --clone
cd terraform-azure-avm-res-<rp>-<modulename>Verify the remotes are set up correctly:
git remote -v
# origin https://github.com/<your-username>/terraform-azure-avm-res-<rp>-<modulename>.git (fetch)
# upstream https://github.com/Azure/terraform-azure-avm-res-<rp>-<modulename>.git (fetch)2. Branch
Create a branch from main to work on your changes:
git checkout -b <your-branch-name>If this is a new module and the repository does not exist yet, module owners should first follow the Repository Creation Process.
Note
If the module repository does not exist yet, check the Terraform Resource Modules index for the module owner’s contact details (PrimaryModuleOwnerGHHandle column).
3. Implement your code change
Before writing code, review the Terraform specifications and composition guidelines to ensure your contribution complies with AVM’s design principles. For a new module, confirm first that every control-plane resource and supported data-plane operation uses AzAPI. Any AzureRM block must satisfy and document the unsupported data-plane exception in TFFR3.
Initialize local metadata for a new module
For a root module, avm init creates and sets up the GitHub repository, including its root metadata.json. Only module owners run it, through the owner-only repository creation process.
For a new direct child under modules/, specify its approved path and inherit ownership from the root:
avm init -Ecosystem terraform -ModuleType resource -Path './modules/<child-module>' -ChildModuleUse the approved -ModuleType for pattern or utility modules instead. With -ChildModule, the command is local-only. It prompts for missing required metadata in an interactive terminal (or accepts -InputObject for automation), creates the target directory if needed, and writes only metadata.json. It never overwrites an existing metadata file or creates Terraform source files, examples, or tests; add those yourself according to the composition guidelines. See the metadata guide for required fields and child ownership.
Once you’ve made your changes, stage, commit, and push them:
git add -A
git commit -m "feat: description of your change"
git pushLifecycle hooks
Some examples need setup work before Terraform runs — deploying prerequisites, generating a terraform.tfvars, or seeding a random prefix. AVM supports optional hook scripts for this:
Terraform configurations created for examples, end-to-end tests, tests, or fixtures are part of the module repository and MUST follow TFFR3. Use AzAPI for every supporting control-plane resource. AzureRM may be configured or exercised only when the test covers the module’s documented unsupported data-plane operation; it must not be used to make setup more convenient.
| Hook | Location | Runs |
|---|---|---|
pre.ps1 | examples/<name>/ | before Terraform commands for the example during policy checks and e2e tests |
post.ps1 | examples/<name>/ | after the example, including when its pre-hook or Terraform initialization fails |
tflint-pre.ps1 | examples/<name>/ | after terraform init, before TFLint |
setup.ps1 | tests/<tier>/ or modules/<name>/tests/<tier>/ | before terraform init and terraform test for the target |
Warning
Hooks must be PowerShell. Avm.Authoring rejects per-example pre.sh, post.sh, and tflint-pre.sh files, plus setup.sh and teardown.sh files under tests/<tier>/, on presence alone. Adding a .ps1 while leaving the corresponding .sh in place still fails before Terraform runs:
The terraform unit test engine runs PowerShell hooks only.
Refactor these shell hooks to '.ps1': tests/unit/setup.shLegacy root-level examples/setup.sh and examples/teardown.sh files are different: Avm.Authoring does not execute or reject them, and there is no global PowerShell equivalent. Move required logic into idempotent per-example pre.ps1 and post.ps1 hooks. Coordinate removal of legacy global hooks with the repository’s centrally managed CI workflow migration.
Each hook runs in its own isolated pwsh subprocess, so environment variables it exports do not reach subsequent Terraform commands. An e2e pre.ps1 can pass values by writing KEY=VALUE lines to examples/<name>/.env; the runner reads the file after the hook and passes the values to the example’s Terraform subprocesses. A unit or integration setup.ps1 uses a .env file at its target root: the repository root or modules/<name>/. For these test hooks, the .env file is two directories above setup.ps1, not beside it.
Because hooks are invoked from an isolated process, anchor paths on $PSScriptRoot rather than relying on the current working directory. Note also that PowerShell does not stop on a failed native command the way set -e does in bash — check $LASTEXITCODE after each Terraform call and throw so a failed hook surfaces immediately instead of later as a confusing downstream error.
4. Run avm pre-commit
Before raising a pull request, run pre-commit to update your files:
avm pre-commitFor Terraform modules, this command:
- Synchronizes the centrally governed managed files, which can add, update, or remove files.
- Applies deterministic fixes for AVM convention rules.
- Runs mapotf transformations.
- Formats Terraform files.
- Regenerates documentation.
The command intentionally updates the working tree. Review every change it makes, then commit and push again:
git add -A
git commit -m "chore: pre-commit fixes"
git push5. Run pr-check and test tiers locally
After committing the pre-commit changes, run the broader pull request checks:
az login
avm pr-checkavm pr-check requires a clean Git working tree and Azure credentials because its Conftest policy checks create Terraform plans for the examples. It checks managed-file, formatting, and transformation drift, then runs TFLint, Conftest policy checks, AVM convention checks, terraform validate, and documentation drift checks. It does not run the Terraform test tiers; those remain separate commands so failures are reported independently.
Unit testing
AVM convention checks require a unit test fixture under tests/unit. Use mocked providers to keep unit tests fast and free of external dependencies:
avm test unitThe command also runs unit test tiers found under direct modules/<name>/ submodules.
Integration testing
Integration tests under tests/integration deploy real resources and require Azure credentials:
az login
avm test integrationThe command also runs integration test tiers found under direct modules/<name>/ submodules. A repository without integration tests reports the tier as skipped rather than passed.
Local e2e testing
Run the e2e test tier to deploy, check idempotency, and destroy resources for each example:
az login
avm test e2eThis tier requires real Azure credentials. Azure CLI authentication is sufficient for local development; no environment variables or service principals are needed. To run one example while iterating:
avm test e2e --example <name>An example containing .e2eignore is excluded locally. Existing required examples cannot be ignored to bypass checks. The required set is examples/defaults/ for every module class and examples/waf-aligned/ for resource modules; examples/waf-aligned/ is optional for pattern and utility modules. The legacy examples/default/ spelling remains migration-compatible, but new modules must use examples/defaults/. Apply failures caused by transient region, SKU capacity, or quota errors are destroyed and retried up to two times by default; use -MaxRetry 0 to disable retries.
Local e2e testing is especially useful for external contributors, since only module owners can approve credentialed CI e2e runs.
6. Raise or Update PR
Tip
Raise your PR early — don’t wait until everything is perfect. An early PR lets you get validation and test feedback sooner. You can continue pushing commits to the same branch; fork contributions require the handoff below for authenticated e2e testing.
- Navigate to the upstream repository on GitHub and click New pull request.
- Set the base repository to the upstream AVM repo and base branch to
main. - Set your head repository and compare branch to your fork and branch.
- Click Create pull request.
- Navigate to the repository on GitHub and click New pull request.
- Set the base branch to
mainand the compare branch to your branch. - Click Create pull request.
7. Approve and monitor CI tests
Note
Coordinate credentialed CI runs with a module owner. Unit tests do not require Azure credentials, but external contributors should still run avm pr-check and all applicable test tiers locally before this step.
PR validation and applicable unit and integration tests run automatically. Automatic PR e2e tests require a label on a same-repository PR. A centrally managed Azure test subscription is provided for credentialed jobs, so contributors do not configure CI credentials themselves.
Open a PR early and use these checks while iterating. When the contribution is ready for deployment tests, request an e2e label; delaying those tests avoids unnecessary cloud costs and runtime.
What CI runs
The centrally managed workflow keeps validation and test tiers in separate jobs so a failure produces an actionable signal:
- PR validation — runs the equivalent of
avm pr-check: managed-file and generated-file drift checks, Terraform formatting, mapotf transformations, TFLint, Conftest policy checks, AVM convention checks,terraform validate, and documentation checks. - Unit tests — runs
avm test unit. - Integration tests — runs
avm test integrationwhen the repository has integration tests. - End-to-end tests — when selected by a label, tests each selected example independently with the equivalent of
avm test e2e --example <name>.
An authorized maintainer must apply at least one of these labels to a same-repository PR:
PR: Run Required E2E Testsruns the applicable required examples for the module class. Resource modules require bothdefaultsandwaf-aligned; pattern and utility modules requiredefaultsonly. The legacydefaultspelling is accepted only for migration compatibility.PR: Run All E2E Testsruns the applicable required examples and all optional examples.
Each e2e job deploys the example, checks idempotency with terraform plan, and destroys the resources. Optional examples containing .e2eignore are excluded; existing required examples cannot be ignored to bypass checks. Missing required examples produce a warning, and that warning is distinct from the existing e2e merge gate.
The current workflow executes present default/defaults baseline examples and waf-aligned. Updated class-aware behavior that makes WAF optional for pattern and utility modules depends on the Tools workflow rollout. Until it is available, do not infer that a workflow label or warning proves this policy is already implemented.
Every selected example must pass the single Report check status merge gate. Manual dispatch is a separate operator path; merge queues are not supported.
If tests fail
Go back to step 3 — fix the issue, run avm pre-commit again, and push your changes. Applicable CI tests re-run on the same PR; automatic e2e execution requires a label to remain on it. For a fork, follow the handoff recovery guidance below.
Running e2e for external contributions
Fork PRs cannot access upstream credentials; a label does not grant them access. An authorized FTE must perform this handoff so the same-repository follow-up PR can run authenticated e2e tests and satisfy the merge gate. Immediately before the handoff, the FTE must review the source code, dependencies and workflow changes for security at the exact current PR head. Review the new head again if it changes. Ensure the GitHub CLI (gh) is authenticated as an authorized FTE with access to the upstream repository, then run the shared Avm.Authoring command:
avm release-branch `
--repository <owner>/<terraform-module-repository> `
--pull-request 123The command cannot verify which commit was reviewed. It captures the current head and stops if it changes during the handoff. It creates a release branch from main, retargets and merges the fork PR into that branch, then opens a follow-up PR from the release branch to main. An authorized maintainer must apply one of the e2e labels to that follow-up PR. Restrict write access to the release branch and review any later changes before E2E testing or merging the follow-up PR. The FTE’s invocation runs the handoff; no separate confirmation prompt is required. Use --whatif to preview without making changes. The command stops rather than bypassing repository protections. The follow-up PR still goes through the repository’s normal review and CI gates.
If the handoff itself fails, inspect the fork PR and release branch before recovering manually; do not blindly rerun it. If E2E tests fail after a successful handoff, the original fork PR has been merged. Open a new fork PR containing the original changes and fixes, review its current head, and perform a new handoff. Inspect the existing follow-up PR and release branch before proceeding.
Running e2e for your own contributions
For your own same-repository PRs, apply the appropriate label and monitor the selected tests and Report check status gate.
8. Review and merge PR
Important
PR approvals are enforced on all AVM Terraform module repositories. A PR cannot be merged until it has been approved by an authorized module owner.
Finding an approver
- First port of call — find a friendly module owner. Look up another active Terraform module owner from the
azure-verified-modules-module-contributorsEntra group and request a review from them directly. This is the fastest path to approval. - If no module owner is available, fall back to the AVM core team:
- Assign the
@Azure/azure-verified-modules-engineering-ownersGitHub team as a reviewer on the PR.
- Assign the
This approval guidance applies to Terraform module repositories. See the Terraform review and merge process.
| PR is submitted by a module owner | PR is submitted by anyone, other than the module owner | |
| Module has a single module owner | An eligible AVM core team member or another Terraform module owner approves the PR | Module owner approves the PR |
| Module has multiple module owners | Another owner of the module (other than the submitter) approves the PR | One of the owners of the module approves the PR |
Changes to metadata.json require approval from an eligible member of either @Azure/azure-verified-modules-engineering-owners or @Azure/azure-verified-modules-module-owners. Either team is sufficient; approval from both is not required. Being listed in the module’s owners array does not by itself authorize approval. Follow the metadata review process; code changes in the same pull request still need the normal reviews described above.
- Address any review comments and push updates to your branch.
- Request a re-review once changes are made.
- The module owner will merge the PR once approved and tests pass.
For a brand new module being published for the first time, get the module reviewed by the AVM Core team by following the AVM Review Process before merging.
Owner responsibilities
- Keep the root
metadata.jsonup to date, including every approved owner, through the metadata review process. Complete owner access approval separately. - Watch PR and issue activity for your module and respond in a timely manner as per SNFR11.
- Familiarize yourself with Team Definitions & RACI and TF Issue Triage.
9. Cut a release
Note
This step is performed by the module owner only. Skip it for metadata-only changes: updates to metadata.json must not trigger a module release. See the metadata maintenance process.
After the PR is merged to main, create a release via GitHub Releases:
- Go to the Releases tab and click Draft a new release.
- Set Target to the
mainbranch. - Type a new tag (e.g.
v0.1.0for first publish, or increment for subsequent releases). Tags MUST include thevprefix. - Use Generate release notes and credit external contributors.
- Click Publish release.
First module publish
For a brand new module, contact the AVM core team (e.g. via the AVM - Module Triage project) to request initial publication to the HashiCorp Registry. Subsequent releases are published automatically.
Important
Continue publishing in the v0.x.y range (e.g., v0.1.0, v0.1.1, v0.2.0) until the AVM team notifies you that v1.0.0 is allowed.
Common mistakes to avoid
- Search and update
TODOcomments that come from the template — remove them once addressed. - Do not commit
terraform.lock.hcl— it is excluded by.gitignore. - Update
_header.mdandSUPPORT.md. - Do not commit
terraform.tfvarsfiles. - Do not commit
.envfiles created by lifecycle hooks. - Do not add shell (
.sh) lifecycle hooks — see Lifecycle hooks.