Private Endpoint for a Storage Queue in ARM

1.5k views Asked by At

I can create a Private Endpoint for a Storage Queue through the portal just fine and it works as intended when checking with nameresolver.exe from KUDU. However, I am struggling to find an ARM template that does this in one go.

I have made this template work but I can see that the A record entry does not get generated in the Private DNS Zone that is generated. I don't know how to create that A record entry and cannot seem to find a ARM template online that describes this:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "privateEndpointName": {
            "type": "string",
            "defaultValue": "privendpoint-sapriv01-queue"
        },
        "vnetName": {
            "type": "string",
            "defaultValue": "vn-myvnet01"
        },
        "subnetName": {
            "type": "string",
            "defaultValue": "sn-private-endpoints"
        },
        "groupId": {
            "type": "string",
            "defaultValue": "queue"
        }
    },
    "variables": {
        "privateDNSZone_name": "[concat('privatelink', '.queue.', environment().suffixes.storage)]"
    },
    "resources": [
        {
            "apiVersion": "2019-04-01",
            "name": "[parameters('privateEndpointName')]",
            "type": "Microsoft.Network/privateEndpoints",
            "location": "[resourceGroup().Location]",
            "properties": {
                "privateLinkServiceConnections": [
                    {
                        "name": "[parameters('privateEndpointName')]",
                        "properties": {
                            "privateLinkServiceId": "[resourceId('Microsoft.Storage/storageAccounts', 'saprivendpointdemo')]",
                            "groupIds": [
                                "[parameters('groupId')]"
                            ]
                        }
                    }
                ],
                "manualPrivateLinkServiceConnections": [],
                "subnet": {
                    "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), parameters('subnetName') )]"
                }
            }
        },
        {
            "type": "Microsoft.Network/privateDnsZones",
            "apiVersion": "2018-09-01",
            "name": "[variables('privateDNSZone_name')]",
            "location": "global",
            "tags": {},
            "properties": {}
        },
        {
            "type": "Microsoft.Network/privateDnsZones/virtualNetworkLinks",
            "apiVersion": "2018-09-01",
            "name": "[concat(variables('privateDNSZone_name'), '/', parameters('vnetName'), 'link' )]",
            "location": "global",
            "dependsOn": [
                "[resourceId('Microsoft.Network/privateDnsZones', variables('privateDNSZone_name'))]"
            ],
            "properties": {
                "virtualNetwork": {
                    "id": "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]"
                },
                "registrationEnabled": false
            }
        }
    ],
    "outputs": {
    }
}

I think Microsoft overcomplicated this. The Private IP is auto generated and I don't know how one would reference this IP in the ARM template.

1

There are 1 answers

1
Jim Xu On

If you want to add A record in your Azure Private DNS Zone, you can define Microsoft.Network/privateEndpoints/privateDnsZoneGroups in your template.

For example

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "privateEndpointName": {
            "type": "string",
            "defaultValue": "testqueue"
        },
        "vnetName": {
            "type": "string",
            "defaultValue": "teststorage"
        },
        "subnetName": {
            "type": "string",
            "defaultValue": "default"
        },
        "groupId": {
            "type": "string",
            "defaultValue": "queue"
        }
    },
    "variables": {
        "privateDNSZone_name": "[concat('privatelink', '.queue.', environment().suffixes.storage)]"
    },
    "resources": [
        {
            "apiVersion": "2019-04-01",
            "name": "[parameters('privateEndpointName')]",
            "type": "Microsoft.Network/privateEndpoints",
            "location": "[resourceGroup().Location]",
            "properties": {
                "privateLinkServiceConnections": [
                    {
                        "name": "[parameters('privateEndpointName')]",
                        "properties": {
                            "privateLinkServiceId": "[resourceId('Microsoft.Storage/storageAccounts', 'teststorage05')]",
                            "groupIds": [
                                "[parameters('groupId')]"
                            ]
                        }
                    }
                ],
                "manualPrivateLinkServiceConnections": [],
                "subnet": {
                    "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), parameters('subnetName') )]"
                }
            }
        },
        {
            "type": "Microsoft.Network/privateDnsZones",
            "apiVersion": "2018-09-01",
            "name": "[variables('privateDNSZone_name')]",
            "dependsOn": [
                "[parameters('privateEndpointName')]"
            ],
            "location": "global",
            "tags": {},
            "properties": {}
        },
        {
            "type": "Microsoft.Network/privateDnsZones/virtualNetworkLinks",
            "apiVersion": "2018-09-01",
            "name": "[concat(variables('privateDNSZone_name'), '/', parameters('vnetName'), 'link' )]",
            "location": "global",
            "dependsOn": [
                "[resourceId('Microsoft.Network/privateDnsZones', variables('privateDNSZone_name'))]"
            ],
            "properties": {
                "virtualNetwork": {
                    "id": "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]"
                },
                "registrationEnabled": false
            }
        },
        {
            "type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
            "apiVersion": "2020-03-01",
            "name": "[concat(parameters('privateEndpointName'), '/', 'default')]",
            "dependsOn": [
                "[parameters('privateEndpointName')]",
                "[variables('privateDNSZone_name')]"
            ],
            "location": "[resourceGroup().Location]",
            "properties": {
                "privateDnsZoneConfigs": [
                    {
                        "name": "privatelink-queue-core-windows-net",
                        "properties": {
                            "privateDnsZoneId": "[resourceId('Microsoft.Network/privateDnsZones',variables('privateDNSZone_name'))]"
                        }
                    }
                ]
            }
        }
    ],
    "outputs": {
    }
}

enter image description here enter image description here

For more details, please refer to here and here