L12. Infrastructure as Code: Bicep, ARM & Desired State Configuration
Course outlineLesson 12 of 18
Bicep compiles to ARM JSON, what-if predicts deployment changes, and DSC modes determine whether in-guest configuration drift is reported or corrected.
ARM Templates vs Bicep
ARM (Azure Resource Manager) templates are JSON-based infrastructure definitions for Azure Resource Manager resources.
Bicep is a domain-specific language that transpiles to ARM JSON before deployment. It offers cleaner, more readable syntax with support for modules and reusable components, while deploying through the same ARM engine. Bicep has full day-one support for new Azure resource types because it transpiles to the same underlying ARM JSON that new resources use.
What-If Deployments: Preview Before You Deploy
The what-if operation evaluates a deployment against your current Azure resources and predicts what would be created, changed, or deleted without actually applying anything. This is the standard way to review an infrastructure change before it hits production.
What-if works for both ARM templates and Bicep files:
az deployment group what-if --resource-group myRg --template-file main.bicepReview the predicted changes and validation diagnostics. What-if can report noise from unresolved expressions and can short-circuit resource analysis when expressions or dependencies cannot be evaluated. It is a preview, not proof of a successful deployment.
Desired State Configuration: Enforce In-Guest Settings
Azure Automation State Configuration (DSC-as-a-service) is a declarative model for in-guest machine configuration. You assign a DSC configuration to a VM, and the Local Configuration Manager checks the machine. ApplyAndAutoCorrect remediates drift; ApplyAndMonitor reports drift without correcting it. Azure Automation State Configuration retires on September 30, 2027; plan migration to Azure Machine Configuration.
Use cases include enforcing specific Windows features, registry settings, or required software to be present on every VM in a fleet.
Azure Machine Configuration: Policy-Driven Compliance
Azure Machine Configuration (formerly Guest Configuration) audits and can remediate in-guest settings through the Azure Policy framework. It serves the same goal as DSC (enforcing in-guest configuration) but is delivered through the policy system, making it easier to audit at scale across subscriptions.
Azure Deployment Environments: Self-Service Infrastructure
Azure Deployment Environments lets developers self-deploy pre-approved, governed infrastructure templates on demand for their own dev/test sandboxes. Templates are curated by platform teams, so developers get infrastructure guardrails without needing to understand ARM/Bicep syntax.
Benefits: cost (ephemeral environments torn down when done) and security (reviewed templates reduce configuration risk; permissions, parameters, policy and deployed state still need validation).
IaC Strategy Fundamentals
Effective IaC follows these principles:
| Principle | Why It Matters |
|---|---|
| Source control | IaC definitions must be versioned alongside application code |
| Testing & validation | Use what-if to preview changes before applying them |
| Pipeline automation | IaC deployment and testing must be automated, just like application deployment |
| Idempotence | Running the same IaC should be safe multiple times |
Real-World IaC Workflow
A typical workflow: developer branches, updates a Bicep file, opens a PR. CI runs what-if to show predicted changes, reviewers approve, the PR merges, CD applies the deployment in staging first, then production after manual approval.
This keeps infrastructure changes transparent, auditable, and versioned in Git. Reverting a template does not automatically restore deleted resources or data; plan state recovery separately. Review tip: Use what-if before applying IaC, review its analysis limitations, and distinguish Bicep authoring from the ARM deployment engine.
References
- Bicep overview
- Bicep what-if and limitations
- Azure Automation State Configuration lifecycle
- DSC Local Configuration Manager modes
- AZ-400 official study guide
Continue Learning
- ✓Bicep is a DSL that transpiles to ARM JSON and deploys through the same ARM engine, giving it cleaner syntax and reusable modules while retaining full day-one support for new Azure resource types
- ✓Desired State Configuration (DSC), delivered as Azure Automation State Configuration, can remediate in-guest drift with ApplyAndAutoCorrect; ApplyAndMonitor only reports drift, and the managed State Configuration service retires September 30, 2027
- ✓Azure Machine Configuration (formerly Guest Configuration) audits and can remediate in-guest settings through the Azure Policy framework, addressing a similar problem to DSC through a different delivery mechanism
- ✓What-if deployment (available for both ARM templates and Bicep) predicts what an IaC deployment would change, subject to documented analysis limitations before it is actually applied, which is the standard way to validate an IaC change before it hits production
- ✓Azure Deployment Environments let developers self-deploy governed, pre-approved infrastructure templates on demand for their own sandboxes, reducing both cost (ephemeral, torn down when done) and risk (reviewed templates and guardrails reduce, rather than eliminate, configuration risk)
1. Why might a team choose Bicep over writing ARM templates directly, given that both ultimately deploy through the same engine?
2. A team wants to preview predicted changes an infrastructure-as-code deployment would make to their Azure resources before actually applying it, to catch an unintended change ahead of time. What should they use?
3. A team needs to ensure that every domain-joined VM in a fleet keeps a specific Windows feature enabled and a specific registry setting in place, and automatically corrects any machine that drifts from that configuration. Which existing managed DSC service can do this with ApplyAndAutoCorrect, but must be migrated before September 30, 2027?