I’m trying to write a bicep template that conditionally deploys an APIM Version Set if a nullable object parameter was supplied. This seemed like it should be fairly simple but, unfortunately, my attempt seems to be failing to some nullability constraints.
Minimal repro below:
main.bicep
/* ---- Types ---- */
type apimVersionSetParam = {
name: string
displayName: string
description: string
versioningScheme: ('Header'|'Query'|'Segment')?
}
/* ---- Params ---- */
param apimServiceName string
param versionSet apimVersionSetParam? // <-- Nullable object param of type apimVersionSet
/* ---- Resources ---- */
resource apim_service 'Microsoft.ApiManagement/service@2022-08-01' existing = {
name: apimServiceName
}
// This resource should only be created if the versionSet object param was supplied
resource apim_version_set 'Microsoft.ApiManagement/service/apiVersionSets@2021-08-01' = if (versionSet != null) {
name: versionSet!.name
parent: apim_service
properties: {
displayName: versionSet!.displayName
description: versionSet!.description
versioningScheme: versionSet!.?versioningScheme ?? 'Segment'
}
}
main.bicepparam
using './apim.api.min.bicep'
param apimServiceName = 'bst-iaz-apim-dev'
When I supply a valid versionSet parameter in the bicepparam file, the template works fine. However, when I omit the parameter (or explicitly set it to null
) I get the following error:
InvalidTemplate – Deployment template validation failed: ‘The template resource ‘[format(‘{0}/{1}’, parameters(‘apimServiceName’), parameters(‘versionSet’).name)]’ at line ‘1’ and column ‘727’ is not valid: The language expression property ‘name’ can’t be evaluated.. Please see https://aka.ms/arm-functions for usage details.’.
It seems that the properties of the nullable object parameter are being referenced despite the fact that the resource that references them should be excluded from the deployment due to the if statement.
Is there another way to achieve this?