I’m creating bicep module and by specific condition I need to check if I should create connection string:
param connectionStringName string = 'TestConnectionString'
param connectionStringValue string = ''
resource connectionstring 'Microsoft.Web/sites/config@2023-01-01' = if (addConnectionString) {
name: 'connectionstrings'
parent: appServiceFunction
properties: {
connectionStringName: {
value: connectionStringValue
type: 'SQLServer'
}
}
}
Is it possible to dynamically create connection string name, so when I build bicep file to get TestConnectionString instead of connectionStringName, connectionStringName property is ConnStringValueTypePair type, and I didn’t find any way to explicitly define name for such property.
2
Answers
I guess you can do this by using a condition block. You can use the if expression inside the condition block to set different values based on your condition.
like this above we have made dynamicConnectionStringName is dynamically set based on the condition. If addConnectionString is true, it uses the connectionStringName parameter; else, it uses a default value (in this case, ‘DefaultConnectionString’).
You can use string interpolation, that will use the
connectionStringName
parameter value as the property name: