Bylaw

Gallery › Internet of Things › Azure built-in policies

Configure Azure Device Update for IoT Hub accounts with private endpoint

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.1.0

A private endpoint is a private IP address allocated inside a customer-owned virtual network via which an Azure resource is reachable. This policy deploys a private endpoint for your Device Update for IoT hub to allow services inside your virtual network to reach this resource without requiring traffic to be sent to Device Update for IoT Hub's public endpoint.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONDeviceUpdate_DeployPrivateEndpoint_DINE.json · 163 lines
{
  "properties": {
    "displayName": "Configure Azure Device Update for IoT Hub accounts with private endpoint",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "A private endpoint is a private IP address allocated inside a customer-owned virtual network via which an Azure resource is reachable. This policy deploys a private endpoint for your Device Update for IoT hub to allow services inside your virtual network to reach this resource without requiring traffic to be sent to Device Update for IoT Hub's public endpoint.",
    "metadata": {
      "version": "1.1.0",
      "category": "Internet of Things"
    },
    "version": "1.1.0",
    "parameters": {
      "privateEndpointSubnetId": {
        "type": "String",
        "metadata": {
          "displayName": "Private endpoint subnet id",
          "description": "A subnet with private endpoint network policies disabled.",
          "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.DeviceUpdate/accounts"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.DeviceUpdate/accounts/privateEndpointConnections",
          "existenceCondition": {
            "field": "Microsoft.DeviceUpdate/accounts/privateEndpointConnections/privateLinkServiceConnectionState.status",
            "equals": "Approved"
          },
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/4d97b98b-1d4f-4787-a291-c67834d212e7",
            "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
          ],
          "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-',substring(parameters('name'),0,min(length(parameters('name')),50)),'-',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": [
                                      "DeviceUpdate"
                                    ],
                                    "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.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/5b9d063f-c5fd-4750-a489-1258d1fefcbf",
  "name": "5b9d063f-c5fd-4750-a489-1258d1fefcbf"
}
Bylaw5b9d063f-c5fd-4750-a489-1258d1fefcbf.bylaw.ps1 · 38 lines
# Converted from DeviceUpdate_DeployPrivateEndpoint_DINE.json by ConvertTo-Bylaw.
Policy '5b9d063f-c5fd-4750-a489-1258d1fefcbf' {

    Properties @{
        DisplayName   = 'Configure Azure Device Update for IoT Hub accounts with private endpoint'
        Description   = 'A private endpoint is a private IP address allocated inside a customer-owned virtual network via which an Azure resource is reachable. This policy deploys a private endpoint for your Device Update for IoT hub to allow services inside your virtual network to reach this resource without requiring traffic to be sent to Device Update for IoT Hub''s public endpoint.'
        Version       = '1.1.0'
        Category      = 'Internet of Things'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

    Parameter PrivateEndpointSubnetId @{
        Type        = 'String'
        DisplayName = 'Private endpoint subnet id'
        Description = 'A subnet with private endpoint network policies disabled.'
        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.DeviceUpdate/accounts'

    DeployIfNotExists 'Microsoft.DeviceUpdate/accounts/privateEndpointConnections' -Role 'Network Contributor', 'Contributor' -Effect (Param Effect) {
        Require 'privateLinkServiceConnectionState.status is Approved' {
            Field privateLinkServiceConnectionState.status | Must -Be 'Approved'
        }
        Deployment -TemplateFile './templates/5b9d063f-c5fd-4750-a489-1258d1fefcbf.json' -Parameters ([ordered]@{
                name                    = (Arm '[field(''name'')]')
                serviceId               = (Arm '[field(''id'')]')
                privateEndpointSubnetId = (Param PrivateEndpointSubnetId)
            })
    }
}

Its deployment templates are written beside it:

Source: built-in-policies/policyDefinitions/Internet of Things/DeviceUpdate_DeployPrivateEndpoint_DINE.json in Azure/azure-policy, under the MIT licence.