
Often you don’t need all the configurations of an app per stage; sometimes they are optional. This is often the case for the development stage in particular.
Bicep supports conditions by default, but in many examples they are not really well described or even readable. Here is a snippet of how I usually do it:
1// sample param, empty string as fallback
2param corsOption string = ''
3
4// required web app settings
5var requiredWebAppSettings = [
6 {
7 name: 'CosmosDB__Endpoint'
8 value: cosmosAccount.outputs.endpoint
9 }
10 {
11 name: 'CosmosDB__Database'
12 value: db.outputs.name
13 }
14]
15
16// optional entry for cors
17
18var optionalWebAppCorsConfig = corsOption != '' ? [
19 {
20 name: 'CorsOptions__Origins'
21 value: corsOption
22 }
23] : []
24
25
26// create web app config
27module backendApp './modules/app-service-webapp-linux.bicep' = {
28 name: 'deploy-${backendAppName}'
29 params: {
30 name: backendAppName
31 location: location
32 environmentVariables: concat(appApiEnvVarsCollection, appApiCorsOptionsOriginsSection)
33 }
34}
Thanks to concat we have an array with mandatory variables that must always be set and an array with optional cors settings that are only set if the corsOption parameter is not empty. This is now very easy to control, for example with variables in Azure DevOps.
Related articles

Mar 15, 2023 - 1 min read
Efficient deserialization of Json files on Azure Blob Storage with .NET
System.Text.Json is currently the most modern way to handle Json files efficiently. Efficiency here also means that memory sparing files are …

Mar 12, 2023 - 2 min read
Use constants in Azure Bicep to simplify your IaC life.
Azure is an ecosystem full of constants, identifiers, IDs or role definitions. Unfortunately, ARM and Bicep do not provide as much support …

Nov 02, 2022 - 1 min read
Avoid hardcoded Microsoft URLs with Bicep environments
Bicep has a great feature, which meanwhile also leads to warnings during execution if you don’t pay attention to it: the avoidance of …
Let's Work Together
Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.
