Lesson 5 of 6 Infrastructure as Code

Implementing Desired State Configuration

This lesson covers desired state at the resource level and inside the guest operating system.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how deployment stacks extend Bicep.
  • Compare Machine Configuration assignment types.
  • Describe Azure Automation State Configuration.
  • Explain why new designs avoid State Configuration.

Desired state at the Azure resource level

ARM templates and Bicep describe the desired state of Azure resources. Deploying the same template corrects any property that differs, for resources named in the template. Incremental mode leaves unmentioned resources alone, so it does not remove additions made by hand.

Deployment stacks

A deployment stack is an Azure resource that manages a group of resources as a unit, at resource group, subscription or management group scope. It records what it manages, which gives two capabilities that a plain deployment lacks.

The first is lifecycle control through action on unmanage. When a resource is removed from the template, the stack can detachAll, which is the default and leaves the resource in place, deleteResources, or deleteAll, which also deletes resource groups. The second is protection through deny settings: denyDelete stops deletion, and denyWriteAndDelete stops changes as well, even by someone with Owner rights, unless they are excluded.

az stack group create \
  --name web-stack \
  --resource-group rg-web \
  --template-file infra/main.bicep \
  --parameters infra/environments/production.bicepparam \
  --action-on-unmanage deleteResources \
  --deny-settings-mode denyWriteAndDelete

Up to five principals may be excluded from deny settings, which allows a break-glass account or pipeline identity to continue. Deployment stacks replaced Azure Blueprints, which are deprecated.

Scenario questions

Deployment stacks

Exam skills 3.5.4

Choose the deployment stack setting for each requirement.

Log in to try this activity Interactive activities are free with an account.

Azure Machine Configuration

Azure Machine Configuration, formerly Azure Policy Guest Configuration, applies desired state inside a machine. A configuration is compiled into a package, usually from PowerShell Desired State Configuration, and it is stored where machines can reach it, such as in a storage account. A guest assignment links that configuration to a machine, and it is usually created by an Azure Policy definition at scale.

The machine needs the Machine Configuration extension and a managed identity, or the Azure Arc agent on a hybrid machine. The agent evaluates the configuration on a regular schedule, and it reports to Azure. The assignment type decides what happens.

Assignment typeBehaviour
AuditReports on state only and changes nothing
Apply and MonitorApplies the configuration once, then reports drift without correcting it
Apply and AutocorrectApplies the configuration, and corrects drift when it occurs

Up to 50 guest assignments can apply to one machine. Virtual Machine Scale Sets in Uniform mode are not supported, whereas Flexible orchestration is. Compliance is reported through Azure Policy, and Azure Resource Graph can query it at scale.

The following diagram compares the three assignment types of Azure Machine Configuration.

The three Machine Configuration assignment types. Audit only reports, which suits checking 2,000 servers without changing them; Apply and Monitor applies the configuration but does not correct later drift; Apply and Autocorrect applies it and corrects drift, which suits the later enforcement phase.
The scenario is illustrative.
Sort into groups

Which assignment type?

Exam skills 3.5.4

Match each requirement with the Machine Configuration assignment type.

Log in to try this activity Interactive activities are free with an account.

Azure Automation State Configuration

Azure Automation State Configuration is an older service, and it is still in the skills measured. It provides a pull server in an Azure Automation account. An administrator imports a PowerShell DSC configuration, compiles it into node configurations, and registers machines, whose Local Configuration Manager then pulls the configuration and applies it.

Azure Automation State Configuration will be retired on 30 September 2027, and Microsoft directs users to Azure Machine Configuration. The DSC extension for virtual machines is also retiring, on 31 March 2028, and Automation DSC for Linux has already been retired. If a scenario describes an existing deployment, know how the service works. If a scenario asks for a new design, recommend Machine Configuration. Migration consists of exporting configurations, unregistering machines and assigning the new packages. Compared with State Configuration, Machine Configuration lets you apply several configurations to a machine, and control when correction occurs, and it reports through Azure Resource Graph.

Machine Configuration
StatusCurrent
InfrastructureAzure Policy; no pull server to create
ReportingAzure Policy and Resource Graph
Configurations per machineUp to 50 assignments
LinuxSupported
Choose when New designs, on Azure or Arc machines.
Automation State Configuration
StatusRetires 30 September 2027
InfrastructureAzure Automation account
ReportingAutomation account
Configurations per machineOne node configuration
LinuxRetired
Choose when Only existing deployments, pending migration.
True or false

State Configuration and its successor

Exam skills 3.5.4

Check the facts about Azure Automation State Configuration and Machine Configuration.

Log in to try this activity Interactive activities are free with an account.
Worked example

Audit first

A company wants to check whether 2,000 servers meet a new baseline, without changing them. Later, it plans to enforce the baseline and correct drift. Which Machine Configuration approach should you use?

Start with the Audit assignment type, which only reports state. When ready to enforce, change to Apply and Autocorrect, which applies the configuration and corrects drift. Apply and Monitor would make changes but would not correct later drift. Azure Automation State Configuration is retiring, so it is unsuitable for a new design.

Check yourself

What does a deployment stack do by default when a resource leaves the template?

Show answer

It detaches the resource, which stays in Azure. Deletion needs deleteResources or deleteAll.

Exam Tips

Remember for the exam

  • Deployment stacks add lifecycle control and deny settings.
  • Action on unmanage defaults to detach, not delete.
  • Audit reports; Apply and Monitor applies once; Apply and Autocorrect corrects drift.
  • Azure Automation State Configuration retires on 30 September 2027.
  • Machine Configuration needs an extension and managed identity, or Azure Arc.