Deploying a private endpoint and need the private ip address as output, but cannot seem to get value query right.
Below results in "The template output ‘hostname’ is not valid: The language expression property | ‘privateIPAddress’ has an invalid array index.. (Code:DeploymentOutputEvaluationFailed)
"value": "[reference(resourceId('Microsoft.Network/privateEndpoints', parameters('privateEndpointName'))).networkInterfaces.privateIPAddress]"
Any idea of how to achieve this?
2
Answers
Yes, I am able to obtain the private IP address associated with the private endpoint and it looks a bit convoluted due to having to work around some difficulties in Azure.
The first difficulty is that you cannot directly get at the properties of the child resource
.networkInterfaces
from the perspective of the providerMicrosoft.Network/privateEndpoints
. The reference will only provide the resource ID for the network interface.The second difficulty is that one cannot nest a call to
reference()
inside another call toreference()
. Azure resource management will report an error like "The template function ‘reference’ is not expected at this location.".This will fail:
The solution I have used is based on a collector pattern from the following page (https://learn.microsoft.com/en-us/azure/architecture/guide/azure-resource-manager/advanced-templates/collector#collector-template).
Bonus
I have a Bicep version the compiles to essentially the same JSON. I work primarily in Bicep these days.
main.bicep
nested.bicep
I have few private endpoints integrated with private DNS zone.
The private IP is available on the
customDnsConfigs
property (Not a networking expert tho but it matches the network interface IP).