'ARM - Create Key Vault via private endpoint using existing VNet / Subnet

I am trying to Create a Key Vault via private endpoint - "using existing VNet/Subnet" using ARM custom template. The QuickStart template available in Azure creates a new VNet/Subnet it does not have option of using already created Vnet/subnet.

https://azure.microsoft.com/en-us/resources/templates/key-vault-private-endpoint/

Is their a way to create it in already existing Vnet ?



Solution 1:[1]

Is their a way to create it in already existing Vnet ?

As per above discussion with Bokambo, adding gist as a community wiki answer to help community members who might face a similar issue.

You can add subnetRef via subnetResourceId.

For examples, as suggested by Charles Xu and tom-blake:

"subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]",
 "properties":
    {
        "subnetResourceId": "[variables('subnetRef')]",
        "swiftSupported": true
    }
}
"resources": [
    {
        "type": "config",
        "apiVersion": "2018-11-01",
        "name": "virtualNetwork",
        "dependsOn": [
            "[resourceId('Microsoft.Web/sites', variables('site_name'))]"
        ],
        "properties": {
            "subnetResourceId": "[resourceId(resource_group_name, 'Microsoft.Network/virtualNetworks/subnets', vnet_name, subnet_name)]",
            "isSwift": true
        }
    }
]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1