Gallery › Resilience › Azure built-in policies
[Preview]: Azure Kubernetes Service Managed Clusters should be Zone Redundant
Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0-preview Preview
Azure Kubernetes Service Managed Clusters can be configured to be Zone Redundant or not. The policy checks the node pools in the cluster and ensures that avaialbilty zones are set for all the node pools.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONContainerService_managedclusters_ZoneRedundant_Audit.json · 98 lines
{
"properties": {
"displayName": "[Preview]: Azure Kubernetes Service Managed Clusters should be Zone Redundant",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "Azure Kubernetes Service Managed Clusters can be configured to be Zone Redundant or not. The policy checks the node pools in the cluster and ensures that avaialbilty zones are set for all the node pools.",
"metadata": {
"category": "Resilience",
"version": "1.1.0-preview",
"preview": true
},
"version": "1.1.0-preview",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "This parameter lets you choose the effect of the policy. If you choose Audit (default), the policy will only audit resources for compliance. If you choose Deny, the policy will deny the creation of non-compliant resources. If you choose Disabled, the policy will not enforce compliance (useful, for example, as a second assignment to ignore a subset of non-compliant resources in a single resource group)."
},
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"defaultValue": "Audit"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.ContainerService/managedclusters"
},
{
"anyOf": [
{
"count": {
"field": "Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]",
"where": {
"allOf": [
{
"value": "[coalesce(tryGet(current('Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]'), 'mode'), '')]",
"notEquals": "Machines"
},
{
"value": "[coalesce(tryGet(current('Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]'), 'type'), '')]",
"notEquals": "FlexNodes"
},
{
"count": {
"field": "Microsoft.ContainerService/managedClusters/agentPoolProfiles[*].availabilityZones[*]"
},
"less": 3
}
]
}
},
"greater": 0
},
{
"count": {
"field": "Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]",
"where": {
"allOf": [
{
"value": "[coalesce(tryGet(current('Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]'), 'mode'), '')]",
"notEquals": "Machines"
},
{
"value": "[coalesce(tryGet(current('Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]'), 'type'), '')]",
"notEquals": "FlexNodes"
},
{
"field": "Microsoft.ContainerService/managedClusters/agentPoolProfiles[*].count",
"less": 3
}
]
}
},
"greater": 0
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"versions": [
"1.1.0-PREVIEW",
"1.0.0-PREVIEW"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/2dec5f47-bc40-40d1-8c7d-a39d9d6808d1",
"name": "2dec5f47-bc40-40d1-8c7d-a39d9d6808d1"
}Bylaw2dec5f47-bc40-40d1-8c7d-a39d9d6808d1.bylaw.ps1 · 41 lines
# Converted from ContainerService_managedclusters_ZoneRedundant_Audit.json by ConvertTo-Bylaw.
Policy '2dec5f47-bc40-40d1-8c7d-a39d9d6808d1' {
Properties @{
DisplayName = '[Preview]: Azure Kubernetes Service Managed Clusters should be Zone Redundant'
Description = 'Azure Kubernetes Service Managed Clusters can be configured to be Zone Redundant or not. The policy checks the node pools in the cluster and ensures that avaialbilty zones are set for all the node pools.'
Category = 'Resilience'
Version = '1.1.0-preview'
Preview = $true
PolicyVersion = '1.1.0-preview'
Mode = 'Indexed'
}
Parameter Effect @{
AllowedValues = @('Audit', 'Deny', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'This parameter lets you choose the effect of the policy. If you choose Audit (default), the policy will only audit resources for compliance. If you choose Deny, the policy will deny the creation of non-compliant resources. If you choose Disabled, the policy will not enforce compliance (useful, for example, as a second assignment to ignore a subset of non-compliant resources in a single resource group).'
}
Resource 'Microsoft.ContainerService/managedclusters' {
Require 'agentPoolProfiles and availabilityZones are as required' {
Count 'agentPoolProfiles[*]' -Where {
Arm '[coalesce(tryGet(current(''Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]''), ''mode''), '''')]' | Must -Not -Be 'Machines'
Arm '[coalesce(tryGet(current(''Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]''), ''type''), '''')]' | Must -Not -Be 'FlexNodes'
Count 'availabilityZones[*]' | Must -BeLessThan 3
} | Must -Be 0
}
Require 'agentPoolProfiles and count are as required' {
Count 'agentPoolProfiles[*]' -Where {
Arm '[coalesce(tryGet(current(''Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]''), ''mode''), '''')]' | Must -Not -Be 'Machines'
Arm '[coalesce(tryGet(current(''Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]''), ''type''), '''')]' | Must -Not -Be 'FlexNodes'
Field count | Must -BeLessThan 3
} | Must -Be 0
}
}
Effect (Param Effect)
}Source: built-in-policies/policyDefinitions/Resilience/ContainerService_managedclusters_ZoneRedundant_Audit.json in Azure/azure-policy, under the MIT licence.
Bylaw