Home > Mobile >  Azure Bicep: Invalid JSON error while using dictionary object param
Azure Bicep: Invalid JSON error while using dictionary object param

Time:03-22

I try to deploy automation account variables with the bicep code below:

param DictionaryAutomationAccountVariables object  = {
  var1: {
    varValue: 'value1'
  }
  var2: {
    varValue: 'value2'
  }
}


resource automationAccount 'Microsoft.Automation/automationAccounts@2019-06-01' = {
  name: 'aatest'
  location: resourceGroup().location
  properties: {
    sku: {
      name: 'Free'
    }
  }
}

resource automationVariable 'Microsoft.Automation/automationAccounts/variables@2019-06-01' = [for automationVariable in items(DictionaryAutomationAccountVariables): {
  parent: automationAccount
  name: automationVariable.key
  properties: {
    value: automationVariable.value.varValue
    isEncrypted: false
  }
}]

I enter the command New-AzResourceGroupDeployment -Name 'mydeployment' -ResourceGroupName 'MyRG' -TemplateFile .\aaVariables.bicep and I get the error below:

New-AzResourceGroupDeployment: 8:43:01 AM - The deployment 'mydeployment' failed with error(s). Showing 1 out of 1 error(s).
Status Message: {"Message":"Invalid JSON - Kindly check the value of the variable."} (Code:BadRequest)

I have checked the dictionary object example in Bicep documentation, I use exactly the same format.

Any idea why I get this error?

UPDATE: I have tried just deploying a simple automation account variable with bicep without loop. I got the same error.

CodePudding user response:

I suspect that error message could be improved... a bit...

Try this:

    value: '"${automationVariable.value.varValue}"'

If you want a string var put the value in double quotes.

When type property is not supplied (and I don't think it's even possible to supply in that apiVersion, but it used to be) the default type is object...

  • Related