IaC in Practice: Desired State & Deployment Environments
Implement desired state configuration with Azure Automation State Configuration and Azure Machine Configuration. Design on-demand self-deployment with Azure Deployment Environments.
From Templates to Continuous Compliance
Think of a thermostat.
You set the temperature to 22 degrees. If the room gets cold, the heater kicks in. If it gets hot, the heater turns off. You declared the DESIRED STATE (“22 degrees”) and the thermostat continuously enforces it.
Desired state configuration works the same way for servers. You declare “IIS must be installed, TLS 1.2 must be enabled, port 443 must be open.” The system checks every 15 minutes — if anything drifts from the desired state, it either reports the drift or automatically fixes it.
Configuration Drift
Configuration drift occurs when the actual state of a server diverges from its intended configuration. Common causes:
- Manual changes via RDP/SSH (“just a quick fix” that is never documented)
- Failed or partial updates
- Software installations outside the pipeline
- Security patches that change settings
Drift is dangerous because environments that were once identical become unpredictably different. A bug that cannot be reproduced in staging might only exist because production has drifted.
Two approaches to prevent drift:
- Detect and report — monitor for drift, alert the team, require manual remediation
- Detect and auto-correct — automatically revert any drift to the desired state
Azure Automation State Configuration
Azure Automation State Configuration uses PowerShell Desired State Configuration (DSC) to define and enforce server configurations.
How It Works
- Write a DSC configuration (PowerShell script defining desired state)
- Compile it into a MOF (Managed Object Format) file
- Assign the MOF to target nodes (VMs)
- The Local Configuration Manager (LCM) on each node pulls and applies the configuration
Example DSC Configuration
configuration WebServerConfig {
Node 'webserver01' {
WindowsFeature IIS {
Ensure = 'Present'
Name = 'Web-Server'
}
File WebContent {
Ensure = 'Present'
Type = 'Directory'
DestinationPath = 'C:\inetpub\wwwroot\app'
}
Registry TLS12 {
Ensure = 'Present'
Key = 'HKLM:\SYSTEM\CurrentControlSet\...'
ValueName = 'Enabled'
ValueData = '1'
}
}
}
Configuration Modes
| Mode | Behaviour | Use When |
|---|---|---|
| ApplyAndMonitor | Apply once, then only report drift (no auto-fix) | Audit-first environments, initial rollout |
| ApplyAndAutoCorrect | Apply and continuously fix any drift automatically | Production servers requiring strict compliance |
| ApplyOnly | Apply once, never check again | One-time setup, immutable infrastructure |
Azure Machine Configuration (formerly Guest Configuration)
Azure Machine Configuration is the modern replacement for Automation DSC when managing Azure VMs and Arc-enabled servers. It integrates with Azure Policy for compliance reporting.
Key Differences from Automation DSC
| Capability | Azure Automation DSC | Azure Machine Configuration |
|---|---|---|
| Platform | Azure Automation account required | Built into Azure Policy — no additional infrastructure |
| Supported OS | Windows (PowerShell DSC) | Windows and Linux |
| Configuration format | PowerShell DSC / MOF files | PowerShell DSC v3 or custom (machine configuration packages) |
| Compliance reporting | Automation DSC dashboard | Azure Policy compliance dashboard (unified view) |
| Assignment model | Pull from Automation account | Azure Policy assignment (inherited, scoped) |
| Remediation | LCM auto-correct modes | Policy remediation tasks (audit-only or deploy-if-not-exists) |
| Arc support | Limited | Full support for Arc-enabled servers (on-premises and other clouds) |
| Direction | Retiring September 2027 (Linux retired Sept 2023) — migrate to Machine Configuration | Actively developed — the future of Azure config management |
| Best for | Existing DSC investments, Windows-only | New projects, cross-platform, Azure Policy integration |
Machine Configuration Workflow
- Author a machine configuration package (PowerShell DSC v3 or custom)
- Publish the package to Azure Blob Storage or a built-in package
- Assign via Azure Policy (audit mode or enforce mode)
- The Guest Configuration agent on each VM checks compliance every 15 minutes
- Results appear in the Azure Policy compliance dashboard
Two policy effects control behaviour:
- AuditIfNotExists — report non-compliance but do not fix (audit mode)
- DeployIfNotExists — automatically remediate drift (enforce mode)
Exam tip: Provisioning vs configuration management
The exam draws a clear line between two layers:
Resource provisioning (WHAT to create):
- ARM templates, Bicep, Terraform
- Create VMs, databases, App Services, networking
- Runs once per deployment
Configuration management (HOW to configure what is inside):
- Automation DSC, Machine Configuration
- Install software, set registry keys, configure OS settings
- Runs continuously to prevent drift
When a question asks about “ensuring IIS is installed and TLS 1.2 is enabled on all VMs” — this is configuration management (DSC/Machine Config), NOT Bicep/Terraform.
When a question asks about “provisioning a VM with a specific SKU in East US” — this is resource provisioning (Bicep/Terraform), NOT DSC.
Azure Deployment Environments
Azure Deployment Environments (ADE) provide self-service, template-based infrastructure for developers. Instead of submitting a ticket and waiting days for an environment, developers spin up pre-approved infrastructure in minutes.
How It Works
- Platform engineers create a Dev Center with project definitions
- They define environment types (Dev, Test, Staging, Production)
- They build a catalogue of approved IaC templates (Bicep or Terraform) stored in a Git repository
- Developers self-serve: pick a template, provide parameters, click deploy
- Guardrails enforce policies — developers cannot exceed resource limits or create non-compliant resources
- Auto-delete policies destroy idle environments after a configurable period (cost control)
Key Components
| Component | Purpose |
|---|---|
| Dev Center | Central management hub for projects and catalogues |
| Project | Logical grouping — maps to a team or application |
| Environment Type | Classification (Dev, Test, Staging) with different policies |
| Catalogue | Git repository containing approved IaC templates |
| Environment Definition | A specific template in the catalogue (e.g., “3-tier web app”) |
| Environment | A running instance created by a developer from a definition |
Scenario: Jordan builds a self-service platform
☁️ Jordan at Cloudstream Media creates a Dev Center for the engineering team:
Catalogue templates:
- “Microservice sandbox” — App Service + SQL Database + Redis Cache
- “Full-stack dev” — AKS cluster + ACR + PostgreSQL + Storage Account
- “Data pipeline” — Event Hub + Stream Analytics + Cosmos DB
Guardrails:
- Dev environments limited to B-series VMs (cost control)
- Auto-delete after 7 days of inactivity
- All resources tagged with owner and project automatically
Developer experience:
Avery (dev lead) needs a new environment for a feature branch. She opens the Azure Developer CLI, picks “Microservice sandbox,” names it feature-payments, and has a running environment in 8 minutes. When the feature merges, the environment auto-deletes after 7 idle days.
This eliminates the “wait 3 days for infra team to provision an environment” bottleneck while maintaining cost and compliance guardrails.
Comprehensive IaC Comparison
| Tool | Layer | Scope | State | Best For |
|---|---|---|---|---|
| ARM Templates | Resource provisioning | Azure only | Azure manages state | Legacy templates, maximum compatibility |
| Bicep | Resource provisioning | Azure only | Azure manages state | New Azure-only projects, clean syntax |
| Terraform | Resource provisioning | Multi-cloud | External state file | Multi-cloud environments, existing Terraform teams |
| Automation DSC | OS configuration | Windows VMs | Automation account | Existing DSC investments, Windows-only shops |
| Machine Configuration | OS configuration | Windows + Linux (Azure and Arc) | Azure Policy | Modern config management, cross-platform, compliance |
| Deployment Environments | Self-service provisioning | Azure | Dev Center | Developer self-service with governance guardrails |
Dr. Amira's government client requires that all Windows VMs have TLS 1.2 enabled and that any drift is automatically corrected. The solution must report compliance through Azure Policy. Which tool should Amira recommend?
Jordan wants to enable developers to create their own test environments from approved templates without involving the platform team. Environments should auto-delete after 7 days of inactivity. What should Jordan implement?
Which configuration mode should you use for an initial rollout where you want to apply the desired state and monitor for drift WITHOUT automatically fixing it?
🎬 Video coming soon
Desired State Configuration and Deployment Environments
Next up: Pipeline Maintenance: Health, Migration and Retention