Task 02: Apply Azure Policy Initiatives
DOCUMENT CATEGORY: Runbook
SCOPE: Azure Policy configuration
PURPOSE: Apply governance and compliance policies
MASTER REFERENCE: Microsoft Learn - Azure Policy
Status: Active
Azure Policy enforces organizational standards and assesses compliance at scale. This step applies policy initiatives specifically designed for Azure Local deployments, including security baselines and governance policies.
Policy Initiatives (also called policy sets) group related policies together. For Azure Local, Microsoft provides built-in initiatives that bundle recommended security configurations.
Overview
| Initiative | Scope | Purpose |
|---|---|---|
| Azure Security Benchmark | Management Group | Comprehensive security controls aligned to industry standards |
| Azure Local Security Baseline | Subscription | Microsoft-recommended configurations for Azure Local |
| Guest Configuration | Resource Group | In-guest policy enforcement for Windows/Linux |
| Tagging Governance | Subscription | Enforce required tags for cost management |
Prerequisites
- Azure subscription with Owner or Policy Contributor role
- Management groups configured (if applying at MG scope)
- Log Analytics workspace for compliance data
Values from infrastructure.yml
The script reads these keys from infrastructure.yml (schema 5). Each key, with its type, default and example, is in the variables reference.
azure.tenant_id the tenant; also the id of the tenant root management group
landing_zone.policy.required_tags the tag names to require (no default: the names follow your tagging standard)
landing_zone.policy.management_group optional; the management group to assign at
The Terraform route (src/terraform/modules/security) assigns the policies these keys list (registry 5.0.62, schema 5.6.28, optional). They replace the earlier extra.tfvars copy of terraform.tfvars.example:
| Key | What it is |
|---|---|
landing_zone.policy.assignments[] | Azure Policy assignments at the scope of the Azure Local subscription (azure.subscription_id) |
landing_zone.policy.resource_group_assignments[] | Azure Policy assignments at the scope of a resource group of the landing zone; resource_group names an entry of landing_zone.resource_groups |
.name | Name of the assignment (its resource name, unique in its scope) |
.policy_definition_id | Resource ID of the policy definition or initiative |
.display_name, .description | Display name and description of the assignment |
.enforce | Enforcement mode: true (default) applies the policy's effect, false only reports (DoNotEnforce) |
.non_compliance_message | Message shown when a resource is not compliant |
Procedure
- Azure Portal
- Orchestrated Script
- Azure CLI
Assign Azure Security Benchmark
- Navigate to Azure Policy
- In Azure Portal, search for Policy
- Click Definitions in the left menu
- Find Security Benchmark Initiative
- Set Definition type to Initiative
- Search for Azure Security Benchmark
- Click on the initiative to view details
- Assign the Initiative
- Click Assign
- Scope: Select your subscription or management group
- Exclusions: Add any resources to exclude (optional)
- Assignment name:
Azure Security Benchmark - Azure Local
- Configure Parameters
- Review default parameters
- Adjust as needed for your environment
- Click Review + create
- Click Create
Assign Azure Local-Specific Policies
- Search for Azure Local Policies
- In Policy Definitions, search for Azure Stack HCI or Azure Local
- Review available built-in policies
- Assign Key Policies
- Audit Azure Stack HCI clusters for compliance
- Configure Azure Stack HCI to use Azure Monitor Agent
- Configure periodic checking for missing security updates
- Create Policy Initiative (Optional)
- Click Definitions → + Initiative definition
- Name:
Azure Local Security Baseline - Add relevant policies
- Save and assign to subscription
Enable Guest Configuration
- Assign Guest Configuration Initiative
- Search for Guest Configuration
- Find: Audit Windows machines that do not have the specified Windows PowerShell execution policy
- Assign to your resource group containing Arc-enabled servers
- Deploy Prerequisites
- Assign: Deploy prerequisites to enable Guest Configuration policies on virtual machines
- This installs the Guest Configuration extension on VMs
PowerShell
When to use: Run the task from a management workstation or a pipeline. The script reads
infrastructure.ymland carries no values of its own.
Script
| Script | What it does |
|---|---|
scripts/deploy/05-operational-foundations/phase-04-security-governance/task-02-apply-azure-policy-initiatives/powershell/Invoke-AzurePolicyTier1-Orchestrated.ps1 | Assigns the Tier 1 tag policy at one management group, in audit mode, from infrastructure.yml. Supports -WhatIf. |
Requires: PowerShell 7; modules Az.Accounts, Az.Resources.
Run
./Invoke-AzurePolicyTier1-Orchestrated.ps1 -InfrastructureFile ./infrastructure.yml -WhatIf
The earlier Set-AzurePolicyConfiguration.ps1 is removed: Microsoft Learn documents no supported way to do what it did. The security baseline of Azure Local is changed with Set-AzsSecurity (see Task 03: Configure security baselines).
Azure CLI
When to use: Run the task from a host that has the Azure CLI and not the Az PowerShell modules. The script is PowerShell 7 that calls
az; it readsinfrastructure.ymland carries no values of its own.
Script
| Script | What it does |
|---|---|
scripts/deploy/05-operational-foundations/phase-04-security-governance/task-02-apply-azure-policy-initiatives/azurecli/Invoke-AzurePolicyTier1-Orchestrated.azcli.ps1 | Assigns the Tier 1 tag policy at one management group, in audit mode, from infrastructure.yml, with the Azure CLI. Supports -WhatIf. |
Requires: PowerShell 7 and the Azure CLI, signed in with az login --tenant <azure.tenant_id>.
One assignment for each tag of landing_zone.policy.required_tags, named req-tag-<tag>, at landing_zone.policy.management_group (empty: the tenant root group). The enforcement mode is DoNotEnforce: Azure reports resources without the tag as non-compliant and denies nothing. An assignment that exists is left alone; a name used by another definition or tag is reported as Conflict and the script exits 1. Assigning at the tenant root group needs a role that can write policy assignments there.
Run
./Invoke-AzurePolicyTier1-Orchestrated.azcli.ps1 -InfrastructureFile ./infrastructure.yml -WhatIf
./Invoke-AzurePolicyTier1-Orchestrated.azcli.ps1 -InfrastructureFile ./infrastructure.yml
Validation
# Check policy assignments
$assignments = Get-AzPolicyAssignment -Scope "/subscriptions/$subscriptionId"
Write-Host "Policy Assignments:" -ForegroundColor Cyan
$assignments | Format-Table DisplayName, EnforcementMode -AutoSize
# Check compliance state (may take up to 24 hours for initial scan)
$complianceStates = Get-AzPolicyState -SubscriptionId $subscriptionId -Top 10
Write-Host "`nRecent Compliance States:" -ForegroundColor Cyan
$complianceStates | Group-Object ComplianceState | Format-Table Name, Count
Expected Output
Policy Assignments:
DisplayName EnforcementMode
----------- ---------------
Azure Security Benchmark - Azure Local Default
Require Environment Tag Default
Deploy Guest Configuration Prerequisites Default
Recent Compliance States:
Name Count
---- -----
Compliant 45
NonCompliant 3
Unknown 2
Common Policies for Azure Local
| Policy Name | ID | Purpose |
|---|---|---|
| Audit VMs without disaster recovery | 0015ea4d-51ff-4ce3-8d8c-f3f8f0179a56 | Ensure DR is configured |
| Configure periodic checking for updates | 59efceea-0c96-497e-a4a1-4eb2290dac15 | Security update compliance |
| Deploy Log Analytics agent | 053d3325-282c-4e5c-b944-24faffd30d77 | Monitoring agent deployment |
| Require tag on resources | 871b6d14-10aa-478d-b590-94f262ecfa99 | Cost management tags |
Troubleshooting
| Issue | Cause | Resolution |
|---|---|---|
| Policy assignment fails with permission error | Account lacks Policy Contributor role at target scope | Assign Resource Policy Contributor role at the subscription or management group level |
| Resources remain non-compliant after remediation | Remediation task not triggered or still in progress | Check remediation task status in Policy > Remediation; create a new remediation task if needed |
| Policy effects not enforced on new resources | Assignment uses Audit instead of Deny effect | Update the assignment parameters to use Deny for enforcement; existing resources need remediation separately |
Next Steps
Proceed to Task 4: Configure Security Baselines to review and remediate Defender recommendations.
Scripts for this task are located in the azurelocal-toolkit repository under scripts/deploy/ in the appropriate task folder.
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.
Navigation
| Previous | Up | Next |
|---|---|---|
| ← Task 01: Enable Defender for Cloud | Phase 04: Security & Governance | Task 03: Security Baselines → |
| Version | Date | Author | Changes |
|---|---|---|---|
| 1.0.0 | 2026-03-24 | Azure Local Cloud | Initial release |
Version Control
| Version | Date | Author | Changes |
|---|---|---|---|
| 1.0.0 | 2025-03-25 | Azure Local Cloud | Initial release |