Skip to content

First plan to first apply

The end-to-end walkthrough for onboarding your first customer. It starts at an empty GitHub organization and a customer Azure tenant, and ends with an applied landing-zone foundation.

Six steps. Budget half a day of hands-on work, plus up to ninety minutes of waiting on the first apply.

Step What it does Hands-on time
1 Run the bootstrap 30 to 45 min
2 Fill in the customer values 20 min
3 Check the repo settings 15 min
4 First pull request and plan 10 min
5 First apply 5 min, then up to 60 to 90 min waiting
6 What next -

Before you start, finish Onboard as an MSP once, and check the customer prerequisites. You need Owner at the scope the deploy identities operate at, a management subscription under that scope, a GitHub organization on the Team plan or higher, the checks App (and the runners App for the self-hosted posture) installed on it, your bootstrap App installed on it (or an operator token as the fallback), and a license with an entitlement for this organization and tenant.

1. Run the bootstrap

The bootstrap is Terraform in nrit-solutions/nrit-alz-bootstrap. It runs once per customer, against the customer tenant. Full detail is on the bootstrap page; this is the shape of the run.

# Copy customers/_example.tfvars into your private operator repository as
# ../<msp>-operator/customers/<customer>.tfvars and fill it in.
az login --tenant <customer-tenant-id>
az account set --subscription <management-subscription-id>

# GitHub auth: the bootstrap App. Its id, installation id and key path
# (github_app_pem_file) sit in the tfvars. Fallback without the App:
# export GITHUB_TOKEN=<pat>                     # classic repo + admin:org, never in tfvars
export TF_VAR_checks_app_private_key="$(cat /path/to/checks-app.pem)"
export TF_VAR_github_runners_app_private_key="$(cat /path/to/runners-app.pem)"  # self_hosted_private only

scripts/create-backend.sh -f ../<msp>-operator/customers/<customer>.tfvars

terraform init \
  -backend-config="resource_group_name=rg-cicd-bootstrap-<loc>" \
  -backend-config="storage_account_name=<printed by the script>" \
  -backend-config="container_name=tfstate" \
  -backend-config="key=bootstrap.tfstate"

# tfpr_license in the tfvars; onboard adds the entitlement, plans, asks, applies.
scripts/onboard.sh -f ../<msp>-operator/customers/<customer>.tfvars

After the apply, the customer has:

  • the customer repository, generated from nrit-alz-customer-template, so it starts with the whole live/ tree and the five caller workflows,
  • the deploy identities, plan (Reader) and apply (Owner), with GitHub Actions federated credentials, so no Azure secrets are stored,
  • the plan and apply environments, each carrying its own AZURE_CLIENT_ID,
  • the state storage account and tfstate container, Entra ID auth only,
  • the require-approved-pr-to-main ruleset, requiring an approved review and a green tfpr / merge-gate to merge, unless you set require_approved_pr = false,
  • the self-hosted runner, when network_posture = self_hosted_private.

The backend firewall allows one IP

scripts/create-backend.sh resets the allowlist to your current public IP. If your IP changes, re-run it before any terraform command. On the very first run the operator role assignment can take a minute to propagate before terraform init succeeds.

2. Clone the customer repository and set the customer values

gh repo clone <customer-org>/<customer-repo>
cd <customer-repo>
git checkout -b onboarding

The customer values are in one file the bootstrap wrote: live/customer.hcl. Check it before the first plan.

live/customer.hcl

locals {
  tenant_root_id          = "<management group name>"
  location                = "westeurope"
  location_short          = "weu"
  business_unit           = "<short name>"
  amba_action_group_email = "alerts@customer.example"
}
  • tenant_root_id is the management group the ALZ hierarchy is created under, as the plain name. The bootstrap derives it from management_group_scope_id. For the tenant root group it is the tenant id, which is what most customers want.
  • location and location_short are the foundation's primary region. live/_foundation/region.hcl reads them, and root.hcl generates them into each unit's context.tf.
  • business_unit becomes the businessunit tag on the platform resources and the AMBA resource group.
  • amba_action_group_email must be a real monitored inbox. Azure Monitor Baseline Alerts is mandatory in the baseline and every AMBA alert routes to this address.

The repository owns the file: edit it here, and a bootstrap re-run never overwrites it.

Get tenant_root_id right before the first apply

For an existing intermediate management group, the group must already exist; this repository does not create it. Changing tenant_root_id after the first apply moves the whole hierarchy to a new parent. Policy assignment scopes and role assignments follow the move, and subscriptions can be left unplaced while it runs. That is a migration, not an edit.

live/_foundation/env.hcl

environment defaults to prod and becomes the env tag. The tag policy allows prod, staging, and dev only, so a foundation that is not the customer's production estate must use one of those.

Optional: a connectivity subscription

live/_foundation/landing-zones/main.tf has connectivity_subscription_id, which defaults to an empty string and omits the connectivity entry from subscription_placement. Set it when the customer has a connectivity subscription. Placement is not permanent: set the id later and re-apply to move the subscription under the Connectivity MG.

Some values are never edited in files

The tenant id, subscription id, and the three backend names arrive as repository variables the bootstrap wrote (AZURE_TENANT_ID, AZURE_SUBSCRIPTION_ID, BACKEND_AZURE_*). The placeholders in live/tenant.hcl and live/_foundation/subscription.hcl are only used for local runs. All units share the one state account; each folder's subscription.hcl is the deploy target, not the state location. See secrets and variables.

The engine pins in the five caller workflows (tfpr-pr.yml, tfpr-unlock.yml, tfpr-review.yml, tfpr.yml, drift.yml) already sit at the template's current release, matching the version statement. Leave them alone for the first onboarding.

Install the toolchain

The lock-file step below runs Terragrunt and Terraform on your machine. Install the versions the repository pins in mise.toml, from the repository root:

mise install

See mise.toml: the pinned toolchain for what it installs.

Generate the provider lock files

The template deliberately ships no .terraform.lock.hcl files, so this repository pins its providers at onboarding, to current versions. Generate one per unit and commit them with the value changes above:

for u in live/_foundation/*/; do
  terragrunt --working-dir "$u" init -backend=false
  TG_NO_AUTO_INIT=true terragrunt --working-dir "$u" run -- providers lock -platform=darwin_arm64 -platform=linux_amd64
done

The second command adds the linux_amd64 hashes (TG_NO_AUTO_INIT keeps Terragrunt from initializing the real backend on the way in). The engine restores Terraform providers from the Actions cache and verifies every cached package against the lock file on the runner, so a lock file written on a Mac alone makes the cache miss and the provider download run on every job. Add your own platform in place of darwin_arm64 if it differs.

Until they exist, provider versions re-resolve on every run, so a tfpr apply can use a different version than the plan that was reviewed. The pre-commit invariants check warns about it, without blocking. Why the template ships none, and how to move a provider version later, is on Versions and upgrades.

3. Check the repo settings

Seven things to check before the first pull request. The bootstrap sets most of them, so for those you only confirm. The checks App and Renovate are installs you do yourself.

The license variables. The caller workflows reference the public nrit-solutions/tfpr entrypoint, which needs no access grant or engine credential. tfpr apply needs the repository variables TFPR_LICENSE and TFPR_ENTITLEMENT, and AZURE_TENANT_ID must be the tenant the entitlement is bound to. scripts/onboard.sh writes both and checks them; confirm with:

gh variable list -R <customer-org>/<customer-repo>

Without them plans run, and tfpr apply is refused with a message that links to the fix. See License.

The checks App. The engine's check rows (the merge gate included) are written under the org's checks App. Create it once per org and install it with "All repositories"; the bootstrap does the rest when the tfvars sets checks_app_client_id and checks_app_id and TF_VAR_checks_app_private_key is exported. If the runners App uses "Only select repositories", add the new repository to its installation now. See the checks App.

The cost gate key. Export the Infracost key as TF_VAR_infracost_api_key when you run the bootstrap. It writes INFRACOST_API_KEY and adds infracost to TFPR_EXTRA_TOOLS. If the customer sets the secret themselves, set infracost_api_key_unmanaged = true in the tfvars instead. Without a key the cost section skips.

Single-writer organizations. If nobody else can review, the ruleset's required_approving_review_count is 0, or the gate is off (require_approved_pr = false), GitHub returns an empty review decision. The bootstrap then sets TFPR_ALLOW_UNREVIEWED_APPLY = true, without which the engine refuses every tfpr apply. Check it is there:

gh variable list --repo <customer-org>/<customer-repo>

The required status check. The bootstrap sets it. Confirm tfpr / merge-gate is required on the main branch.

gh api repos/<customer-org>/<customer-repo>/rulesets

The require-approved-pr-to-main ruleset takes the check context from the bootstrap's required_status_checks variable, which defaults to ["tfpr / merge-gate"], and binds it to the checks App, so a same-named check from another workflow cannot stand in for it. If the tfvars set it to [], put the default back and re-run the bootstrap.

The code owners. The bootstrap writes .github/CODEOWNERS once. It gives /.github/ and /projects.yml to the apply approvers team it created, so a change to the engine callers or to discovery needs that team's review. The repository owns the file after that, and a bootstrap re-run never overwrites it. Open the file on GitHub and check the owner line: GitHub flags an owner it cannot resolve and skips that line, so the path then needs no owner review. A code owner cannot approve their own pull request, so a single-writer organization sets require_code_owner_review = false in its bootstrap tfvars.

Renovate. Install the Renovate GitHub App on this repository only. .github/renovate.json then opens the engine bump pull requests. Mend, which hosts the App, puts a new organization in Silent mode, and Silent mode writes nothing: no pull requests and no Dependency Dashboard issue. Switch the organization to Interactive mode in its settings on the Mend developer portal (developer.mend.io). See Renovate.

Check the license before the first apply

gh variable list --repo <customer-org>/<customer-repo> must show TFPR_LICENSE, TFPR_ENTITLEMENT and AZURE_TENANT_ID. The first plan's check run text says License: valid. when all three are right.

4. Open the first pull request

git commit -am "onboarding: set customer values"
git push -u origin onboarding
gh pr create --fill

Opening the PR runs tfpr plan automatically. The engine plans every impacted unit, one job per unit, in parallel. If you touched live/customer.hcl, which every unit reads, expect the full foundation fan-out.

What to look for:

  • A plan comment per unit. Each run posts a fresh comment led by a headline such as ✅ Plan (management-resources): 0 to add, 1 to change, 0 to destroy, then the plan output, one row per gate, and the tfpr apply instructions last.
  • The gate rows. Policy check (conftest), Security scan (avmsec), Reliability check (APRL), Security scan (checkov) and Cost estimate (infracost), each with a one-line verdict. A row is collapsed when its gate is clean and opens by itself when the gate reports something. On a fresh repository the policy gate reports "No policies found in policy; skipped" until you add conftest policies, and the cost section reports skipped until INFRACOST_API_KEY is set.
  • The tfpr / merge-gate check. It is red until the PR is applied. That is the point: nothing merges with unapplied changes.

Read the plans before approving. The first foundation plan creates the whole management group hierarchy, the policy assignments, the central Log Analytics workspace, and the AMBA alerts. See plan and apply for how the impacted set is worked out.

5. First apply

Get the review. tfpr apply respects the repository's review decision, and the bootstrap defaults the required approving review count to 1. A single-writer organization relies on TFPR_ALLOW_UNREVIEWED_APPLY from step 3 instead.

Then comment on the PR:

tfpr apply

The foundation applies in dependency order automatically: management-resources, then landing-zones, then amba. One unit at a time. The engine reacts to your comment so you can follow progress without opening the run.

Expect up to sixty to ninety minutes

The first foundation apply can be slow because of policy propagation. In a tenant with little existing state it can finish in fifteen minutes. Both are normal and there is nothing to fix. Later applies on the same foundation are much faster.

Success looks like this:

  • every unit posts a ✅ Apply (<unit>) comment,
  • the tfpr / merge-gate check turns green and reads Applied,
  • the PR can merge.

Merge box after the apply: approval met, apply row green, merge gate "Applied"Merge box after the apply: approval met, apply row green, merge gate "Applied"

Merge the PR. Nothing applies on merge; the apply already happened from the comment.

Then run Diagnostic settings remediation once. The bootstrap created its resources before the policy existed, so runner logs are not stored until you do.

6. What next

  • Scenarios: onboard a connectivity hub and the customer's first landing zones.
  • Plan and apply: the day-to-day flow, the comment commands, and how the impacted set is calculated.
  • Policy: what the baseline enforces and how to change it.