Skip to main content

Task 05: Configure Environment Variables

Runbook GitHub GitLab Azure DevOps

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); with devops.authentication.method: client_secret, its secret in Key Vault, named by the reference in devops.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).

VariableKey in infrastructure.ymlGitHubGitLabAzure DevOps
ARM_CLIENT_IDazure.automation_identity.client_id (else the app registration Task 01 made)variablevariablevariable group
ARM_TENANT_IDazure.tenant_idvariablevariablevariable group
ARM_SUBSCRIPTION_IDazure.subscription_idvariablevariablevariable group
ARM_USE_OIDC (method oidc) or ARM_CLIENT_SECRET (method client_secret, read from devops.authentication.client_secret)devops.authentication.methodvariable / secretvariable / maskedvariable group (secret)
AZL_AUTH_METHODdevops.authentication.method (oidc or client_secret)variablevariablevariable group
TF_BACKEND_RG, TF_BACKEND_SA, TF_BACKEND_CONTAINER, TF_BACKEND_KEYdevops.state.resource_group, .storage_account, .container, .azure_local_keyvariablevariablevariable group
AZL_RUNNER_LABELdevops.pipelines.runner_labelvariablevariable(the pool: AZL_AGENT_POOL of pipeline-settings.yml, from devops.runners[].pool)
AZL_RUNNER_OSdevops.runners[].os_type of the general runnervariable
AZL_ENVIRONMENT_OS_CONFIGURATION, _OS_CONFIGURATION_CLEAR_STORAGE, _ARM_DEPLOYMENT, _CICD_INFRA, _TERRAFORM_DEPLOYMENT, _OPERATIONSdevops.pipelines.environments.*variablevariablethe variable of the same name in pipelines/azure-devops/variables/approval-environments.yml (written once, in a pull request; see below)
AZL_INFRASTRUCTURE_FILEdevops.pipelines.infrastructure_filevariablevariablepipeline-settings.yml
AZL_HANDOFF_PATHdevops.pipelines.handoff_pathvariablevariablepipeline-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_VERSIONdevops.pipelines.tool_versions.terraform, .python, .ansible_core, .ansible_lint, .az_powershell, .powershell_yaml, .az_keyvaultvariablevariablevariable group
AZL_VALIDATE_JOB_TIMEOUT_MINUTES, AZL_DEPLOY_JOB_TIMEOUT_MINUTESdeployment.validate_timeout_minutes, deployment.deploy_timeout_minutes, each plus 60 minutesvariable
AZL_DEFAULT_BRANCHdevops.repository.default_branchvariable group
AZL_RUNNER_SSH_PUBLIC_KEYdevops.runners[].admin_ssh_public_key of the Linux runner (the key, or a reference the script reads through the secret resolver)variablevariablevariable 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:

KeyWhat it is
devops.pipelines.runner_labelThe 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_configurationThe environment that gates the Apply job of the OS configuration pipelines.
devops.pipelines.environments.os_configuration_clear_storageThe 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_deploymentThe environment that gates the Deploy job of the ARM deployment pipelines.
devops.pipelines.environments.cicd_infraThe environment that gates the Apply job of the CI/CD infrastructure pipelines (the runners).
devops.pipelines.environments.terraform_deploymentThe environment that gates the Terraform apply and the on-premises Ansible jobs of the Terraform and Ansible sample pipelines.
devops.pipelines.environments.operationsSchema 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.ymlValue the script listsUsed by
AZL_ENVIRONMENT_OS_CONFIGURATIONdevops.pipelines.environments.os_configurationos-configuration.yml, stage Apply
AZL_ENVIRONMENT_OS_CONFIGURATION_CLEAR_STORAGEdevops.pipelines.environments.os_configuration_clear_storageos-configuration.yml, stage ConfirmStorageWipe
AZL_ENVIRONMENT_ARM_DEPLOYMENTdevops.pipelines.environments.arm_deploymentarm-deployment.yml, stage Deploy; pre-cluster-verification.yml, stage VerifyWithChanges
AZL_ENVIRONMENT_CICD_INFRAdevops.pipelines.environments.cicd_infracicd-infra.yml, stage Apply
AZL_ENVIRONMENT_TERRAFORM_DEPLOYMENTdevops.pipelines.environments.terraform_deploymentazure-local-deploy.yml, stages DeployFoundation, ConfigureOnPrem and ConfigureOperations
AZL_ENVIRONMENT_OPERATIONSdevops.pipelines.environments.operationsday2-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.

KeyWhat it is
devops.pipelines.service_connectionThe 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_groupThe 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:

KeyWhat it isDefault
devops.pipelines.infrastructure_fileThe path, in the deployment repository, of the infrastructure file the pipelines pass to the scripts (-InfrastructureFile)config/infrastructure.yml
devops.pipelines.handoff_pathThe repository path of the ZTP handoff files (a handoff file or a directory of *.ztp-handoff.json) the OS configuration pipelines pass to the scriptztp-state
devops.pipelines.tool_versions.terraformThe Terraform release the pipelines install1.16.3
devops.pipelines.tool_versions.pythonThe Python minor version of the Ansible jobs3.12
devops.pipelines.tool_versions.ansible_coreThe ansible-core release the Ansible jobs install with pip2.21.5
devops.pipelines.tool_versions.ansible_lintThe ansible-lint release the lint jobs install with pip26.10.1
devops.pipelines.tool_versions.az_powershellThe Az PowerShell module version16.3.0
devops.pipelines.tool_versions.powershell_yamlThe powershell-yaml module version the pipelines install to read infrastructure.yml0.4.12
devops.pipelines.tool_versions.az_keyvaultThe Az.KeyVault module version the pipelines install to read keyvault:// secrets6.6.1
devops.state.azure_local_keyBlob name of the state of the azure-local Terraform environment (TF_BACKEND_KEY)azure-local.tfstate
devops.runners[].admin_ssh_public_keyThe 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:

KeyWhat it isDefault
devops.pipelines.schedules.check_for_updatesWhen the day 2 check for updates runs (day2-check-updates.yml). A five-field cron expression in UTC. Empty means no schedule17 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):

PlatformWhat the script does
GitHubWrites 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
GitLabCreates 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 DevOpsWrites 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:

VariableDescriptionSensitivity
ARM_TENANT_IDEntra ID tenant ID (azure.tenant_id)Plain (an identifier)
ARM_SUBSCRIPTION_IDAzure subscription ID (azure.subscription_id)Plain (an identifier)
ARM_CLIENT_IDApp registration client ID (azure.automation_identity, from Task 01)Plain (an identifier)
ARM_USE_OIDCtrue, only with devops.authentication.method: oidc (no secret)Plain
ARM_CLIENT_SECRETOnly with devops.authentication.method: client_secret: the script reads it from Key Vault (devops.authentication.client_secret); never typed inSecret / 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:

VariableSourceSensitivity
TF_BACKEND_RGdevops.state.resource_groupPlain
TF_BACKEND_SAdevops.state.storage_accountPlain
TF_BACKEND_CONTAINERdevops.state.containerPlain
TF_BACKEND_KEYdevops.state.azure_local_key, the state file of the azure-local environment (the same key New-IacVariableFiles.ps1 writes to backend.hcl)Plain

Procedure​

Configure Repository Variables​

The script sets them. To check or set them by hand:

  1. Navigate to your repository → Settings → Secrets and variables → Actions
  2. On the Variables tab, click New repository variable for each variable of the table Every variable the pipelines read (the workflows read vars.NAME):
VariableValue
ARM_TENANT_IDazure.tenant_id
ARM_SUBSCRIPTION_IDazure.subscription_id
ARM_CLIENT_IDThe app registration client ID
AZL_AUTH_METHODdevops.authentication.method
  1. Only with devops.authentication.method: client_secret: on the Secrets tab, add ARM_CLIENT_SECRET with the value of the Key Vault secret devops.authentication.client_secret names.

Environment-Scoped Values​

The script also sets the sign-in values on each environment:

  1. Go to Settings → Environments → select environment (e.g. azr-prod-us)
  2. Under Environment variables (and Environment secrets for ARM_CLIENT_SECRET), add the values that differ per environment, such as ARM_SUBSCRIPTION_ID

Tip: Repository-level values apply to all environments. Environment values override them per environment.


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​

Deploy Runners


References​


Toolkit script

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​

ScriptWhat it does
scripts/deploy/01-cicd-infra/phase-01-cicd-setup/task-05-configure-variables/powershell/Set-CicdVariables.ps1Task 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.

PreviousUpNext
← Task 04: Create EnvironmentsPhase 01: CI/CD SetupTask 06: Deploy Runners ->

Troubleshooting​

IssueCauseResolution
Variable group not accessiblePipeline authorization missingAuthorize the pipeline to use the variable group
Secret variables not resolvingKey vault integration misconfiguredVerify key vault access policy and service connection

Version Control​

VersionDateAuthorChanges
1.0.02025-03-25Azure Local CloudInitial release