I'm having issues setting up an ARM Template for Azure Web Apps in that I can't add ConnectionString parameters where it sets the values if the parameters are set, but leave blank (default) if the parameters aren't set.
Here is how it looks in the template.json file:
"connectionStrings": [
{
"name": "[parameters('connString').connName)]",
"connectionString": "[parameters('connString').string]",
"type": "[parameters('connString').connType]"
}
],
And in the parameters.json file:
"connString": {
"value": {
"connName": "",
"string": "",
"connType": ""
}
},
When running the deployment with the above it fails on "Parameter name cannot be empty" I attempted to use an equals function to set the value as empty if the parameter is empty, but set the parameter if the parameter is filled out, however it doesn't like the empty value.
"name": "[if(equals(parameters('connString').connName,''),'',parameters('connString').connName)]"
Also attempted an empty function:
"name": "[not(empty(parameters('connString').connName))]"
However this returns "False" if empty and "True" if the parameter is set (as designed)
The deployment works fine if I set dummy values as the parameters, is it possible to set a function or something similar so if the parameter is empty it uses whatever value is sent as if the connectionStrings section wasn't present in the template? These parameters are optional but it looks like because they're in the actual template.json file its expecting a value.
Cheers
EDIT Going to post what my end templates looked like in case someone else needs assistance.
Template File
Variables
"variables": {
"empty": []
},
Resources
"connectionStrings": "[if(empty(parameters('connString')), variables('empty'), array(parameters('connString')))]",
Parameter File
If setting a connection string
"connString": {
"value": [{
"name": "test",
"connectionString": "ufgndjkngsdgjkn",
"type": "Custom"
}]
},
If not wanting to set a connection string
"connString": {
"value": [
]
},
you should just do this:
parameters:
"connString": {
"value": {}
},
variables:
"empty": [],
template:
"connectionStrings": "[if(empty(parameters('connString')), variables('empty'), array(parameters('connString')))]"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With