Gallery › Cache › Azure built-in policies
Configure Azure Cache for Redis with private endpoints
Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.0.0
Private endpoints let you connect your virtual network to Azure services without a public IP address at the source or destination. By mapping private endpoints to your Azure Cache for Redis resources, you can reduce data leakage risks. Learn more at: https://aka.ms/redis/privateendpoint.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONRedisCache_PrivateEndpoint_DINE.json · 163 lines
{
"properties": {
"displayName": "Configure Azure Cache for Redis with private endpoints",
"description": "Private endpoints let you connect your virtual network to Azure services without a public IP address at the source or destination. By mapping private endpoints to your Azure Cache for Redis resources, you can reduce data leakage risks. Learn more at: https://aka.ms/redis/privateendpoint.",
"metadata": {
"category": "Cache",
"version": "1.0.0"
},
"version": "1.0.0",
"policyType": "BuiltIn",
"mode": "Indexed",
"parameters": {
"privateEndpointSubnetId": {
"type": "String",
"metadata": {
"displayName": "privateEndpointSubnetId",
"description": "A subnet in the selected subscription/virtual network in which the private endpoint is configured",
"strongType": "Microsoft.Network/virtualNetworks/subnets"
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"DeployIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Cache/redis"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Cache/redis/privateEndpointConnections",
"evaluationDelay": "AfterProvisioning",
"existenceCondition": {
"field": "Microsoft.Cache/redis/privateEndpointConnections/privateLinkServiceConnectionState.status",
"equals": "Approved"
},
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/e0f68234-74aa-48ed-b826-c38b57376e17"
],
"deployment": {
"properties": {
"mode": "incremental",
"parameters": {
"name": {
"value": "[field('name')]"
},
"serviceId": {
"value": "[field('id')]"
},
"privateEndpointSubnetId": {
"value": "[parameters('privateEndpointSubnetId')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string"
},
"serviceId": {
"type": "string"
},
"privateEndpointSubnetId": {
"type": "string"
}
},
"variables": {
"privateEndpointName": "[concat('pe-m-',substring(parameters('name'),0,min(length(parameters('name')),47)),'-',uniquestring(deployment().name))]"
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"name": "[variables('privateEndpointName')]",
"apiVersion": "2020-06-01",
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "inner"
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"serviceId": {
"type": "string"
},
"privateEndpointSubnetId": {
"type": "string"
},
"subnetLocation": {
"type": "string"
}
},
"variables": {
"privateEndpointName": "[deployment().name]"
},
"resources": [
{
"name": "[variables('privateEndpointName')]",
"type": "Microsoft.Network/privateEndpoints",
"apiVersion": "2020-07-01",
"location": "[parameters('subnetLocation')]",
"tags": {},
"properties": {
"subnet": {
"id": "[parameters('privateEndpointSubnetId')]"
},
"privateLinkServiceConnections": [
{
"name": "[variables('privateEndpointName')]",
"properties": {
"privateLinkServiceId": "[parameters('serviceId')]",
"groupIds": [
"redisCache"
],
"requestMessage": "autoapprove"
}
}
],
"manualPrivateLinkServiceConnections": []
}
}
]
},
"parameters": {
"serviceId": {
"value": "[parameters('serviceId')]"
},
"privateEndpointSubnetId": {
"value": "[parameters('privateEndpointSubnetId')]"
},
"subnetLocation": {
"value": "[reference(first(take(split(parameters('privateEndpointSubnetId'),'/subnets'),1)),'2020-07-01','Full').location]"
}
}
}
}
]
}
}
}
}
}
},
"versions": [
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/5d8094d7-7340-465a-b6fd-e60ab7e48920",
"name": "5d8094d7-7340-465a-b6fd-e60ab7e48920"
}Bylaw5d8094d7-7340-465a-b6fd-e60ab7e48920.bylaw.ps1 · 38 lines
# Converted from RedisCache_PrivateEndpoint_DINE.json by ConvertTo-Bylaw.
Policy '5d8094d7-7340-465a-b6fd-e60ab7e48920' {
Properties @{
DisplayName = 'Configure Azure Cache for Redis with private endpoints'
Description = 'Private endpoints let you connect your virtual network to Azure services without a public IP address at the source or destination. By mapping private endpoints to your Azure Cache for Redis resources, you can reduce data leakage risks. Learn more at: https://aka.ms/redis/privateendpoint.'
Category = 'Cache'
Version = '1.0.0'
PolicyVersion = '1.0.0'
Mode = 'Indexed'
}
Parameter PrivateEndpointSubnetId @{
Type = 'String'
DisplayName = 'privateEndpointSubnetId'
Description = 'A subnet in the selected subscription/virtual network in which the private endpoint is configured'
Metadata = [ordered]@{ strongType = 'Microsoft.Network/virtualNetworks/subnets' }
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Resource 'Microsoft.Cache/redis'
DeployIfNotExists 'Microsoft.Cache/redis/privateEndpointConnections' -Role 'Redis Cache Contributor' -EvaluationDelay AfterProvisioning -Effect (Param Effect) {
Require 'privateLinkServiceConnectionState.status is Approved' {
Field privateLinkServiceConnectionState.status | Must -Be 'Approved'
}
Deployment -TemplateFile './templates/5d8094d7-7340-465a-b6fd-e60ab7e48920.json' -Parameters ([ordered]@{
name = (Arm '[field(''name'')]')
serviceId = (Arm '[field(''id'')]')
privateEndpointSubnetId = (Param PrivateEndpointSubnetId)
})
}
}Its deployment templates are written beside it:
templates/5d8094d7-7340-465a-b6fd-e60ab7e48920.json
Source: built-in-policies/policyDefinitions/Cache/RedisCache_PrivateEndpoint_DINE.json in Azure/azure-policy, under the MIT licence.
Bylaw