Conditional deployment of Virtual Network Links does not work #9041
-
Bicep version Describe the bug To Reproduce
In the event that I DO NOT pass a name in for blobPrivateDnsZoneName, blobDnsNameIsNotEmpty correctly returns False, but creation of the
However, the validation pass should not take a look at the virtual network link, as I have it marked conditional AND I have ternary conditional safety on the virtual network ID parameter. Additional Context |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The issue that you are bumping into here is that ARM is validating the name of the resource even though you're doing a conditional deployment. When Here's an example that would work for you: // Virtual network of the network to be linked to the Private DNS Zone.
param virtualNetworkName string = ''
param virtualNetworkId string = ''
param blobPrivateDnsZoneName string = ''
var stgAcctPrivateDnsZoneVnetLinkName = 'link-${virtualNetworkName}-to-dns-st'
var blobDnsNameIsNotEmpty = !empty(blobPrivateDnsZoneName)
resource privateDnsZone 'Microsoft.Network/privateDnsZones@2020-06-01' existing = {
name: blobDnsNameIsNotEmpty ? blobPrivateDnsZoneName : 'dummy.com'
}
resource blobPrivateDnsZoneVnetLink 'Microsoft.Network/privateDnsZones/virtualNetworkLinks@2020-06-01' = if (blobDnsNameIsNotEmpty) {
name: blobDnsNameIsNotEmpty ? stgAcctPrivateDnsZoneVnetLinkName : 'dummy'
parent: privateDnsZone
location: 'global'
properties: {
registrationEnabled: false
virtualNetwork: {
id: blobDnsNameIsNotEmpty ? virtualNetworkId : ''
}
}
} |
Beta Was this translation helpful? Give feedback.
The issue that you are bumping into here is that ARM is validating the name of the resource even though you're doing a conditional deployment.
When
blobDnsNameIsNotEmpty
returns false thename
property for the virtualNetworkLinks resource is''
and this is what ARM is rejecting. You can provide a dummy name in your condition instead of''
as a workaround. But since you are deploying a child resource with segmented names and your condition is to check if a parameter with the DNS Zone name is empty you need to use a dummy name for the first segment as well or we would get an error that the number of segments are incorrect.Here's an example that would work for you:
// Virtual network of the…