Skip to main content

Task 04: Create Environments

Runbook GitHub GitLab Azure DevOps

DOCUMENT CATEGORY: Runbook Step
SCOPE: Deployment environment creation
PURPOSE: Create deployment environments for infrastructure automation MASTER REFERENCE: Azure Pipelines Environments

Status: Active


Objective​

Create deployment environments to manage infrastructure using IaC and automation. Environments provide deployment targets with optional protection rules and approval gates.


Prerequisites​

  • Project settings configured (Task 03)
  • Admin / Maintainer role on the project

Environment Naming Convention​

Use consistent naming across all platforms:

Cloud/ServiceExample Names
Azure Productionazr-prod-us, azr-prod-eu
Azure Developmentazr-dev-us
Azure Stagingazr-staging

Procedure​

Create Environments​

  1. Navigate to Settings → Environments
  2. Click New environment
  3. Enter the environment name (e.g., azr-prod-us)
  4. Click Configure environment

Configure Protection Rules​

For production environments, add protection rules:

SettingValue
Required reviewers✅ Add 1–2 required reviewers
Wait timerOptional — add delay before deployment (minutes)
Deployment branchesmain only (select Selected branches → add main)

Repeat for each environment in the naming convention table above.

tip

GitHub Environments integrate with GitHub Actions via the environment: key in workflow YAML. Protection rules automatically gate deployments.

References: GitHub — Using environments for deployment


Verification​

  • Environment created for each deployment target
  • Environment names follow naming convention
  • Production environments have protection rules / approval gates configured

Next Steps​

Configure Environment Variables


References​


Values from infrastructure.yml​

The script reads devops.environments[] (name, approval required, approvers, wait minutes, deployment branch) of infrastructure.yml (schema 5). Each key, with its type, default and example, is in the variables reference.

The pipeline files of the toolkit name no environment. devops.pipelines.environments (schema 5.6.25) says which entry of devops.environments[] gates which pipeline: os_configuration, os_configuration_clear_storage, arm_deployment, cicd_infra, terraform_deployment and operations. Each value must name an entry with approval_required: true. Task 05 turns them into pipeline variables on GitHub and GitLab. On Azure DevOps it lists the value of each one to write in pipelines/azure-devops/variables/approval-environments.yml, once, in a pull request.

devops.pipelines.environments.operations (schema 5.6.28, the variable AZL_ENVIRONMENT_OPERATIONS) is the one environment of 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. It is one environment on purpose. On Azure DevOps its Exclusive lock check then keeps an update and a node reboot from running on the cluster at the same time. Give it the approvers of your change process, and on Azure DevOps add the Approvals, Exclusive lock and Branch control checks. See Validation and day 2 pipelines.

While an AZL_ENVIRONMENT_* value is empty, no pipeline runs a change without an approval. A refusal fails with a message that names the variable: the job approval-environment-not-set on GitHub, the job <pipeline>-approval-environment-not-set on GitLab, the stage ApprovalEnvironmentNotSet on Azure DevOps. Nothing is sent to any machine.


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-04-create-environments/powershell/New-CicdEnvironments.ps1Task 04. Creates the deployment environments with their approval gates. Supports -WhatIf.

Requires: PowerShell 7.

Run​

./New-CicdEnvironments.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 03: Configure Project SettingsPhase 01: CI/CD SetupTask 05: Configure Environment Variables ->

Troubleshooting​

IssueCauseResolution
Environment creation failsInsufficient permissionsVerify user has environment creation rights
Approval gates not configuringEnvironment policy restrictionsCheck organization-level environment policies

Version Control​

VersionDateAuthorChanges
1.0.02025-03-25Azure Local CloudInitial release