Lately, I had to rollout Azure API Management throughout different environments. With Bicep, of course! In the development and test environment, we use API Management without network integration. In the acceptance and production environments, we deploy it internal to the virtual network. In case VNET integration is used, an Application Gateway had to be provisioned. I had to use two types of conditional deployments. Let’s have a look!
One of the parameters indicated whether networking should be used:
@allowed([ 'None' 'Internal' 'External' ]) param apimVirtualNetworkType string
resource applicationGateway 'Microsoft.Network/applicationGateways@2021-02-01' = if(apimVirtualNetworkType == 'Internal') { name: applicationGatewayName ... }
//Create API Management Service resource apiManagement 'Microsoft.ApiManagement/service@2020-12-01' = { name: apimName location: location ... properties: { ... virtualNetworkConfiguration: (apimVirtualNetworkType == 'None') ? null : { subnetResourceId: resourceId(apimVirtualNetworkResourceGroup, 'Microsoft.Network/virtualNetworks/subnets', apimVirtualNetworkName, apimVirtualNetworkSubnetName) } virtualNetworkType: apimVirtualNetworkType } }
Great to use this C#-inspired conditional syntax within Bicep files!
Cheers
Toon