Skip to content

Instantly share code, notes, and snippets.

@skarllot
Created December 19, 2024 15:22
Show Gist options
  • Save skarllot/03424150ac1a8a9f1aca1e87f350f4fd to your computer and use it in GitHub Desktop.
Save skarllot/03424150ac1a8a9f1aca1e87f350f4fd to your computer and use it in GitHub Desktop.
Example condition that does not work on Bicep
resource natGateway 'Microsoft.Network/natGateways@2023-11-01' = if (hasNatGateway) {
name: natGatewayName
location: location
sku: {
name: 'Standard'
}
}
resource subnets 'Microsoft.Network/virtualNetworks/subnets@2022-11-01' = {
name: name
parent: virtualNetwork
properties: {
addressPrefix: addressPrefix
natGateway: hasNatGateway
? {
id: natGateway.id
}
: null
}
}
@skarllot
Copy link
Author

The solution is duplicating subnet resource with condition on each

resource subnets 'Microsoft.Network/virtualNetworks/subnets@2022-11-01' = if (hasNatGateway) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment