Task 05: Configure Environment Variables
DOCUMENT CATEGORY: Runbook Step
SCOPE: CI/CD pipeline variable configuration
PURPOSE: Configure environment variables for Azure authentication
MASTER REFERENCE: See platform-specific docs below
Status: Active
Objective
Configure CI/CD pipeline environment variables for each target Azure subscription.
Prerequisites
- Environments created (Task 04)
- The app registration from Task 01 (
azure.automation_identity); withdevops.authentication.method: client_secret, its secret in Key Vault, named by the reference indevops.authentication.client_secret
Values from infrastructure.yml
No value of a deployment is written in a pipeline file. Every value the toolkit's pipelines read (the sign-in, the state, the runner, the approval environments, the infrastructure file and handoff paths, the tool versions and the job timeouts) is a key of infrastructure.yml (schema 5), and this task sets it on the platform. Run it again after you change the file. The script reads the devops (including devops.pipelines, devops.state and devops.runners[]), azure, deployment, key_vaults and landing_zone sections. A key that is not set takes its registry default. Each key, with its type, default and example, is in the variables reference.
Every variable the pipelines read
On GitHub each is a repository variable (vars.NAME; the sign-in values also per environment), on GitLab a project CI/CD variable (scope *; the sign-in values also per environment), on Azure DevOps an entry of the variable group devops.pipelines.variable_group (the repository group the pipelines read, and one per environment, <name>-<environment>), or a compile-time variable the script writes into pipelines/azure-devops/variables/pipeline-settings.yml or approval-environments.yml (D126: no run parameter carries a deployment value).
| Variable | Key in infrastructure.yml | GitHub | GitLab | Azure DevOps |
|---|---|---|---|---|
ARM_CLIENT_ID | azure.automation_identity.client_id (else the app registration Task 01 made) | variable | variable | variable group |
ARM_TENANT_ID | azure.tenant_id | variable | variable | variable group |
ARM_SUBSCRIPTION_ID | azure.subscription_id | variable | variable | variable group |
ARM_USE_OIDC (method oidc) or ARM_CLIENT_SECRET (method client_secret, read from devops.authentication.client_secret) | devops.authentication.method | variable / secret | variable / masked | variable group (secret) |
AZL_AUTH_METHOD | devops.authentication.method (oidc or client_secret) | variable | variable | variable group |
TF_BACKEND_RG, TF_BACKEND_SA, TF_BACKEND_CONTAINER, TF_BACKEND_KEY | devops.state.resource_group, .storage_account, .container, .azure_local_key | variable | variable | variable group |
AZL_RUNNER_LABEL | devops.pipelines.runner_label | variable | variable | (the pool: AZL_AGENT_POOL of pipeline-settings.yml, from devops.runners[].pool) |
AZL_RUNNER_OS | devops.runners[].os_type of the general runner | variable | ||
AZL_ENVIRONMENT_OS_CONFIGURATION, _OS_CONFIGURATION_CLEAR_STORAGE, _ARM_DEPLOYMENT, _CICD_INFRA, _TERRAFORM_DEPLOYMENT, _OPERATIONS | devops.pipelines.environments.* | variable | variable | the variable of the same name in pipelines/azure-devops/variables/approval-environments.yml (written once, in a pull request; see below) |
AZL_INFRASTRUCTURE_FILE | devops.pipelines.infrastructure_file | variable | variable | pipeline-settings.yml |
AZL_HANDOFF_PATH | devops.pipelines.handoff_path | variable | variable | pipeline-settings.yml |
AZL_TERRAFORM_VERSION, AZL_PYTHON_VERSION, AZL_ANSIBLE_CORE_VERSION, AZL_ANSIBLE_LINT_VERSION, AZL_AZ_POWERSHELL_VERSION, AZL_POWERSHELL_YAML_VERSION, AZL_AZ_KEYVAULT_VERSION | devops.pipelines.tool_versions.terraform, .python, .ansible_core, .ansible_lint, .az_powershell, .powershell_yaml, .az_keyvault | variable | variable | variable group |
AZL_VALIDATE_JOB_TIMEOUT_MINUTES, AZL_DEPLOY_JOB_TIMEOUT_MINUTES | deployment.validate_timeout_minutes, deployment.deploy_timeout_minutes, each plus 60 minutes | variable | ||
AZL_DEFAULT_BRANCH | devops.repository.default_branch | variable group | ||
AZL_RUNNER_SSH_PUBLIC_KEY | devops.runners[].admin_ssh_public_key of the Linux runner (the key, or a reference the script reads through the secret resolver) | variable | variable | variable group |
Each name is registered in the toolkit's registry (tools.cicd_infra, as a pipeline_inputs or pipeline_variables entry with the key as source_key), and the table is $script:AzlPipelineVariable in scripts/common/cicd-infra/AzlCicdInfra.psm1. Nothing else is set by hand: no DOMAIN_ADMIN_PASSWORD, CLUSTER_NAME or CLUSTER_RESOURCE_GROUP, and no AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_SUBSCRIPTION_ID or AZURE_AUTH (the pipelines read ARM_* and AZL_AUTH_METHOD).
The runner label and the approval environments of the pipelines
From schema 5.6.25 the toolkit's pipeline files hold no runner label, agent pool or environment name. These keys give them:
| Key | What it is |
|---|---|
devops.pipelines.runner_label | The one label by which the pipelines choose the general runner: runs-on on GitHub (after self-hosted and linux) and tags on GitLab. It must be an entry of devops.runners[].labels of the general runner, and a label no other runner of the repository has. Azure DevOps chooses the runner by its pool, devops.runners[].pool, and ignores this key. |
devops.pipelines.environments.os_configuration | The environment that gates the Apply job of the OS configuration pipelines. |
devops.pipelines.environments.os_configuration_clear_storage | The environment of the second approval in front of a storage wipe (stage ConfirmStorageWipe of the Azure DevOps OS configuration pipeline). Use other approvers than for os_configuration where you can. |
devops.pipelines.environments.arm_deployment | The environment that gates the Deploy job of the ARM deployment pipelines. |
devops.pipelines.environments.cicd_infra | The environment that gates the Apply job of the CI/CD infrastructure pipelines (the runners). |
devops.pipelines.environments.terraform_deployment | The environment that gates the Terraform apply and the on-premises Ansible jobs of the Terraform and Ansible sample pipelines. |
devops.pipelines.environments.operations | Schema 5.6.28. The one environment that gates every validation and day 2 job that changes the cluster or puts load on it: the update, the node maintenance, the changing cluster operations and the storage load test of the validation pipeline. One environment on purpose: on Azure DevOps its Exclusive lock check keeps an update and a node reboot from running together. Give it the approvers of your change process. |
Each environment value is the name of an entry of devops.environments[] that has approval_required: true. Two pipelines may use the same entry.
The script sets them as GitHub repository variables or GitLab project CI/CD variables: AZL_RUNNER_LABEL and one AZL_ENVIRONMENT_... variable per pipeline. Azure DevOps reads the pool before any variable exists, so there the script writes it as AZL_AGENT_POOL into pipelines/azure-devops/variables/pipeline-settings.yml. A label that the general runner does not have, or an environment that devops.environments[] does not list with approval_required: true, stops the task.
On Azure DevOps the approval environments are not run parameters. With a run parameter, whoever queues a run could type the name of an environment with no approval check, and the change would run without an approval. So every Azure DevOps pipeline that changes something reads its environment from a variable of pipelines/azure-devops/variables/approval-environments.yml, a YAML file of the repository, when the pipeline is compiled. The toolkit ships the variables empty. The script writes the value of each one into that file from infrastructure.yml (D126; an environment that is not set stays empty, so the pipeline refuses the change); commit the file in a pull request:
Variable in approval-environments.yml | Value the script lists | Used by |
|---|---|---|
AZL_ENVIRONMENT_OS_CONFIGURATION | devops.pipelines.environments.os_configuration | os-configuration.yml, stage Apply |
AZL_ENVIRONMENT_OS_CONFIGURATION_CLEAR_STORAGE | devops.pipelines.environments.os_configuration_clear_storage | os-configuration.yml, stage ConfirmStorageWipe |
AZL_ENVIRONMENT_ARM_DEPLOYMENT | devops.pipelines.environments.arm_deployment | arm-deployment.yml, stage Deploy; pre-cluster-verification.yml, stage VerifyWithChanges |
AZL_ENVIRONMENT_CICD_INFRA | devops.pipelines.environments.cicd_infra | cicd-infra.yml, stage Apply |
AZL_ENVIRONMENT_TERRAFORM_DEPLOYMENT | devops.pipelines.environments.terraform_deployment | azure-local-deploy.yml, stages DeployFoundation, ConfigureOnPrem and ConfigureOperations |
AZL_ENVIRONMENT_OPERATIONS | devops.pipelines.environments.operations | day2-update.yml, day2-node-maintenance.yml and day2-cluster-operations.yml, stage Apply; validation.yml, stage StoragePerformance |
While a variable is empty, the stages that change something do not exist. A run that would change something fails in the stage ApprovalEnvironmentNotSet (for the storage wipe, ConfirmStorageWipe) and changes nothing. The read-only stages run as before. See Azure DevOps: Approval environments.
GitHub and GitLab follow the same rule. While an AZL_ENVIRONMENT_* variable is empty, a job that would change something does not run without an approval: a refusal job (approval-environment-not-set on GitHub, <pipeline>-approval-environment-not-set on GitLab) fails with a message that names the variable, and nothing is sent to any machine.
Create the variables (or run this task) before the first pipeline run. With AZL_RUNNER_LABEL empty, a job has no label to select a runner by. On GitLab, for the first run of the CI/CD infrastructure stage, before the runners exist, give AZL_RUNNER_LABEL a shared runner tag when you run the pipeline.
On GitLab, a person who starts a pipeline by hand can override a variable in the run form, AZL_ENVIRONMENT_ARM_DEPLOYMENT of the pre-cluster verification job included. Restrict who may set pipeline variables (project Settings > CI/CD > Variables, the minimum role to use pipeline variables) and protect the environment.
The service connection and the variable group (Azure DevOps)
From schema 5.6.27 the Azure DevOps pipeline files hold no service connection or variable group name either. GitHub and GitLab ignore these keys.
| Key | What it is |
|---|---|
devops.pipelines.service_connection | The name of the Azure Resource Manager service connection (workload identity federation) that task 05 creates and that the Azure DevOps pipelines sign in through. Task 01 puts the same name in the subject of the federated credential. Example: iic-azure-local. |
devops.pipelines.variable_group | The name of the variable group (Pipelines > Library) task 05 writes the sign-in values (ARM_*) and the state settings (TF_BACKEND_*) to. With entries in devops.environments[] there is one group per environment, named <variable_group>-<environment>. Example: iic-azure-credentials. |
On Azure DevOps both keys are required: task 01 and task 05 stop with a message when one is missing. The pipelines read the names as AZL_SERVICE_CONNECTION and AZL_VARIABLE_GROUP of pipelines/azure-devops/variables/pipeline-settings.yml, which the script writes (D126: not run parameters). Before schema 5.6.27 the names were fixed (AzureLocal-ServiceConnection and azure-credentials). To keep what an earlier task 05 created, set the keys to those names.
The paths, the tool versions and the state key
From schema 5.6.28 (registry 5.0.62) the pipeline files hold no infrastructure file path, handoff path, tool version or state file name either. These keys are optional; a key the file leaves out takes its registry default:
| Key | What it is | Default |
|---|---|---|
devops.pipelines.infrastructure_file | The path, in the deployment repository, of the infrastructure file the pipelines pass to the scripts (-InfrastructureFile) | config/infrastructure.yml |
devops.pipelines.handoff_path | The repository path of the ZTP handoff files (a handoff file or a directory of *.ztp-handoff.json) the OS configuration pipelines pass to the script | ztp-state |
devops.pipelines.tool_versions.terraform | The Terraform release the pipelines install | 1.16.3 |
devops.pipelines.tool_versions.python | The Python minor version of the Ansible jobs | 3.12 |
devops.pipelines.tool_versions.ansible_core | The ansible-core release the Ansible jobs install with pip | 2.21.5 |
devops.pipelines.tool_versions.ansible_lint | The ansible-lint release the lint jobs install with pip | 26.10.1 |
devops.pipelines.tool_versions.az_powershell | The Az PowerShell module version | 16.3.0 |
devops.pipelines.tool_versions.powershell_yaml | The powershell-yaml module version the pipelines install to read infrastructure.yml | 0.4.12 |
devops.pipelines.tool_versions.az_keyvault | The Az.KeyVault module version the pipelines install to read keyvault:// secrets | 6.6.1 |
devops.state.azure_local_key | Blob name of the state of the azure-local Terraform environment (TF_BACKEND_KEY) | azure-local.tfstate |
devops.runners[].admin_ssh_public_key | The SSH public key of the administrator of a Linux runner (AZL_RUNNER_SSH_PUBLIC_KEY): the key itself or a reference |
The same versions are installed on GitHub, GitLab and Azure DevOps: hashicorp/setup-terraform, actions/setup-python and Install-Module on GitHub, TerraformInstaller@1, UsePythonVersion and AzurePowerShell@5 on Azure DevOps, and pipelines/gitlab/Use-AzlGitLabTool.ps1 on GitLab.
The schedule of the check for updates
From schema 5.6.28 one key says when the scheduled day 2 pipeline runs:
| Key | What it is | Default |
|---|---|---|
devops.pipelines.schedules.check_for_updates | When the day 2 check for updates runs (day2-check-updates.yml). A five-field cron expression in UTC. Empty means no schedule | 17 4 * * * (every day at 04:17 UTC) |
No platform reads a schedule from a variable, so the script applies the key where each platform keeps it (D126: the key works on all three; the line Pipeline schedule of the output says what it did):
| Platform | What the script does |
|---|---|
| GitHub | Writes the value into the cron line of on.schedule of day2-check-updates.yml (.github/workflows/ when the workflow is there, else pipelines/github-actions/; -GitHubWorkflowDirectory names another folder). Commit it |
| GitLab | Creates or updates the project pipeline schedule Azure Local day 2: check for updates (CI/CD > Schedules) on the default branch, in UTC; deactivates it when the key is empty |
| Azure DevOps | Writes the value into the cron line, and devops.repository.default_branch into the branch, of the schedules block of pipelines/azure-devops/day2-check-updates.yml. Commit it. A scheduled run needs no parameter: see Azure DevOps: the schedule |
A value that is not a five-field cron expression (each field in its range) stops the script. An empty value means no schedule: remove the schedule block of the GitHub and Azure DevOps files in a pull request.
Required Variables
The sign-in values, set for the repository and for each environment:
| Variable | Description | Sensitivity |
|---|---|---|
ARM_TENANT_ID | Entra ID tenant ID (azure.tenant_id) | Plain (an identifier) |
ARM_SUBSCRIPTION_ID | Azure subscription ID (azure.subscription_id) | Plain (an identifier) |
ARM_CLIENT_ID | App registration client ID (azure.automation_identity, from Task 01) | Plain (an identifier) |
ARM_USE_OIDC | true, only with devops.authentication.method: oidc (no secret) | Plain |
ARM_CLIENT_SECRET | Only with devops.authentication.method: client_secret: the script reads it from Key Vault (devops.authentication.client_secret); never typed in | Secret / masked |
With a state storage account in devops.state, the script also sets the Terraform state settings that the Azure DevOps, GitHub and GitLab pipelines pass to terraform init:
| Variable | Source | Sensitivity |
|---|---|---|
TF_BACKEND_RG | devops.state.resource_group | Plain |
TF_BACKEND_SA | devops.state.storage_account | Plain |
TF_BACKEND_CONTAINER | devops.state.container | Plain |
TF_BACKEND_KEY | devops.state.azure_local_key, the state file of the azure-local environment (the same key New-IacVariableFiles.ps1 writes to backend.hcl) | Plain |
Procedure
- GitHub
- GitLab
- Azure DevOps
Configure Repository Variables
The script sets them. To check or set them by hand:
- Navigate to your repository → Settings → Secrets and variables → Actions
- On the Variables tab, click New repository variable for each variable of the table Every variable the pipelines read (the workflows read
vars.NAME):
| Variable | Value |
|---|---|
ARM_TENANT_ID | azure.tenant_id |
ARM_SUBSCRIPTION_ID | azure.subscription_id |
ARM_CLIENT_ID | The app registration client ID |
AZL_AUTH_METHOD | devops.authentication.method |
- Only with
devops.authentication.method: client_secret: on the Secrets tab, addARM_CLIENT_SECRETwith the value of the Key Vault secretdevops.authentication.client_secretnames.
Environment-Scoped Values
The script also sets the sign-in values on each environment:
- Go to Settings → Environments → select environment (e.g.
azr-prod-us) - Under Environment variables (and Environment secrets for
ARM_CLIENT_SECRET), add the values that differ per environment, such asARM_SUBSCRIPTION_ID
Tip: Repository-level values apply to all environments. Environment values override them per environment.
Configure CI/CD Variables
- Navigate to Settings → CI/CD
- Expand Variables
- The script adds each variable of the table Every variable the pipelines read with scope
*, and the sign-in values also per environment. To add one by hand, click Add variable:
| Variable | Configuration |
|---|---|
| ARM_TENANT_ID, ARM_SUBSCRIPTION_ID, ARM_CLIENT_ID | |
| Type | Variable |
| Environments | *, and the target environment for a value that differs |
| Flags | none (identifiers) |
| Value | azure.tenant_id, azure.subscription_id, the app registration client ID |
| Variable | Configuration |
|---|---|
ARM_CLIENT_SECRET (only with devops.authentication.method: client_secret) | |
| Type | Variable |
| Environments | Select target environment |
| Flags | Masked |
| Value | The Key Vault secret devops.authentication.client_secret names |
With oidc the jobs sign in with the GitLab ID token ARM_OIDC_TOKEN and the federated credential Task 01 made; there is no secret.
Tip: Scope variables to specific environments to support multi-subscription deployments.
Create Variable Group
The script creates the group. To create it by hand:
- Navigate to Pipelines → Library
- Click + Variable group
- Name it
<variable_group>-<environment>, fromdevops.pipelines.variable_group(e.g.iic-azure-credentials-azr-prod-us). Without entries indevops.environments[]the name isdevops.pipelines.variable_groupalone. - Add variables:
| Variable | Value | Lock |
|---|---|---|
ARM_TENANT_ID | Entra ID tenant ID | 🔒 |
ARM_SUBSCRIPTION_ID | Azure subscription ID | 🔒 |
ARM_CLIENT_ID | App Registration client ID | 🔒 |
ARM_CLIENT_SECRET | App Registration client secret (only with devops.authentication.method: client_secret) | 🔒 |
TF_BACKEND_RG, TF_BACKEND_SA, TF_BACKEND_CONTAINER, TF_BACKEND_KEY | The Terraform state settings (table above) | |
AZL_AUTH_METHOD | devops.authentication.method | |
AZL_DEFAULT_BRANCH | devops.repository.default_branch | |
AZL_TERRAFORM_VERSION, AZL_PYTHON_VERSION, AZL_ANSIBLE_CORE_VERSION, AZL_ANSIBLE_LINT_VERSION, AZL_AZ_POWERSHELL_VERSION, AZL_POWERSHELL_YAML_VERSION, AZL_AZ_KEYVAULT_VERSION | devops.pipelines.tool_versions.* | |
AZL_RUNNER_SSH_PUBLIC_KEY | devops.runners[].admin_ssh_public_key of the Linux runner |
- Click Save
With OIDC (workload identity federation) the script also creates the service connection named by devops.pipelines.service_connection. There is no client secret.
Link to Pipeline
The script writes the repository group devops.pipelines.variable_group (besides one group per environment) and names it, with the pool, the service connection, the infrastructure file and the handoff path, in pipelines/azure-devops/variables/pipeline-settings.yml, with a - group: entry. Every Azure DevOps pipeline of the toolkit includes that file, so no run form asks for these values (D126). Commit the file in a pull request. The written file looks like this (sample names of the improbability.cloud lab):
variables:
- name: AZL_AGENT_POOL
value: 'pool-iic-azl'
- name: AZL_SERVICE_CONNECTION
value: 'iic-azure-local'
- name: AZL_VARIABLE_GROUP
value: 'iic-azure-credentials'
- name: AZL_INFRASTRUCTURE_FILE
value: 'config/infrastructure.yml'
- name: AZL_HANDOFF_PATH
value: 'ztp-state'
- group: 'iic-azure-credentials'
and each pipeline links it like this:
variables:
- template: variables/pipeline-settings.yml
Write the approval environments
The approval environments are not in the variable group and are not run parameters. The script writes six values, one for each variable of pipelines/azure-devops/variables/approval-environments.yml:
| Variable | Value |
|---|---|
AZL_ENVIRONMENT_OS_CONFIGURATION | devops.pipelines.environments.os_configuration |
AZL_ENVIRONMENT_OS_CONFIGURATION_CLEAR_STORAGE | devops.pipelines.environments.os_configuration_clear_storage |
AZL_ENVIRONMENT_ARM_DEPLOYMENT | devops.pipelines.environments.arm_deployment |
AZL_ENVIRONMENT_CICD_INFRA | devops.pipelines.environments.cicd_infra |
AZL_ENVIRONMENT_TERRAFORM_DEPLOYMENT | devops.pipelines.environments.terraform_deployment |
AZL_ENVIRONMENT_OPERATIONS | devops.pipelines.environments.operations |
Commit the written file in a pull request. The pipelines read the file when they are compiled, so whoever queues a run cannot choose the environment. The file links into each pipeline like this:
variables:
- template: variables/approval-environments.yml
Verification
- All required variables configured per environment
- Sensitive values are masked/secret
- Variables scoped to correct environments
- Test pipeline can authenticate to Azure
Next Steps
References
- GitHub
- GitLab
- Azure DevOps
The toolkit script for this task is PowerShell 7. It reads infrastructure.yml through the mandatory -InfrastructureFile parameter and never prompts. It ends with exit code 0, 1 or 2. Run it with -WhatIf first: the script reads what exists and lists what it would do.
Script
| Script | What it does |
|---|---|
scripts/deploy/01-cicd-infra/phase-01-cicd-setup/task-05-configure-variables/powershell/Set-CicdVariables.ps1 | Task 05. Sets every value the toolkit's pipelines read, each from its key of infrastructure.yml: the sign-in, the state, the runner, the approval environments, the paths, the tool versions and the job timeouts. Supports -WhatIf. |
Requires: PowerShell 7.
Run
./Set-CicdVariables.ps1 -InfrastructureFile ./infrastructure.yml -WhatIf
Alternatives
The procedures in this task use the methods shown in the tabs above. The toolkit is PowerShell 7 only and has no Bash scripts. A few tasks that act on Azure also have an Azure CLI script written in PowerShell. The script status page of the toolkit lists which task has which script.
Navigation
| Previous | Up | Next |
|---|---|---|
| ← Task 04: Create Environments | Phase 01: CI/CD Setup | Task 06: Deploy Runners -> |
Troubleshooting
| Issue | Cause | Resolution |
|---|---|---|
| Variable group not accessible | Pipeline authorization missing | Authorize the pipeline to use the variable group |
| Secret variables not resolving | Key vault integration misconfigured | Verify key vault access policy and service connection |
Version Control
| Version | Date | Author | Changes |
|---|---|---|---|
| 1.0.0 | 2025-03-25 | Azure Local Cloud | Initial release |