0
votes

I am defining some parameters to configure my SQL Database elastic pool in my ARM template. I would like to specify defaults for each parameter, with the second and third parameters' default values being based on the first parameter's value. However, I'm getting errors whenever I attempt to specify expressions as the default values of parameters that have an allowed set of values: "This value is not one of the allowed values for parameter '…'." The same happens for parameters that have a type other than string: "Parameter '…' must be of type '…'.".

I can work around the issue by eliminating the allowed values, and by changing all parameter types to string. However, this would lose the validation for user-input values. Am I doing something wrong when defining the default values, or is this an ARM limitation?

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "sqlSkuName": {
      "type": "string",
      "allowedValues": [
        "BasicPool",
        "StandardPool",
        "PremiumPool"
      ],
      "defaultValue": "StandardPool"
    },
    "sqlSkuTier": {
      "type": "string",
      "allowedValues": [
        "Basic",
        "Standard",
        "Premium"
      ],
      "defaultValue": "[if(equals(parameters('sqlSkuName'), 'BasicPool'), 'Basic',
                        if(equals(parameters('sqlSkuName'), 'StandardPool'), 'Standard',
                        if(equals(parameters('sqlSkuName'), 'PremiumPool'), 'Premium',
                        '')))]"
    },
    "sqlDatabaseMaxCapacity": {
      "type": "int",
      "defaultValue": "[if(equals(parameters('sqlSkuName'), 'BasicPool'), 5, 50)]"
    },
  }
}

enter image description here

enter image description here

1

1 Answers

0
votes

You have to use the object variables to use the parameters conditionally, so you have to do something like this:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "sqlSkuName": {
        "type": "string",
        "allowedValues": [
            "BasicPool",
            "StandardPool",
            "PremiumPool"
        ],
        "defaultValue": "StandardPool"
    },
    "sqlSkuTier": {
        "type": "string",
        "allowedValues": [
            "Basic",
            "Standard",
            "Premium"
        ]
    },
    "sqlDatabaseMaxCapacity": {
        "type": "int",
        "defaultValue": 0
    }
},
"variables": {
    "sqlSkuTier-Var": "[if(equals(parameters('sqlSkuName'), 'BasicPool'), 'Basic',
                    if(equals(parameters('sqlSkuName'), 'StandardPool'), 'Standard',
                    if(equals(parameters('sqlSkuName'), 'PremiumPool'), 'Premium',
                    '')))]",
    "sqlDatabaseMaxCapacity-var": "[if(equals(parameters('sqlDatabaseMaxCapacity'),0 ),
                                        if(equals(parameters('sqlSkuName'), 'BasicPool'), 5,50),
                                        parameters('sqlDatabaseMaxCapacity'))]"
},
"resources": []

}

And then to use the value:

variables('sqlSkuTier-Var')

I recommend that you use the visual studio code plugin( https://marketplace.visualstudio.com/items?itemName=msazurermtools.azurerm-vscode-tools) to have IntelliSense, it helps a lot to work and see what you have wrong.