Home > front end >  How to escape leading square bracket in a parameter array in Bicep?
How to escape leading square bracket in a parameter array in Bicep?

Time:12-19

I'm getting "Deployment template language expression evaluation failed" error from bicep template validation due to leading square bracket. If I add another square bracket it passes but the extra bracket will be appended. Example:

var test='[xxxxxx]'
var arr=[
{
 name: 'varname'
  value: test
}
]

CodePudding user response:

As discussed issue here in github,

Bicep is working appropriately here by producing a single [-> ARM expressions should only be escaped with [[if the string's initial letter is a [. Because the use of multi-line strings in Bicep results in extra spaces at the beginning of the string, the [should not be escaped.

Fix this by giving ' []' instead of '[]'

I tried below sample variable file with a "single variable" declared in bicep and successfully deployed after build got succeeded.

var.bicep:

var test = ' []'
module mod './<stringfile>.bicep' = { //Added parameters in another bicep file.
  name: 'module'
  params: {
    test: test
  }
}

modulefile.bicep:

param test string 

Deployment succeeded:

enter image description here

Deployed in the Portal:

enter image description here

AND

  1. As mentioned in some examples from MsDoc, I've taken a snippet and ran in my environment with multiple "variable arrays", and it was successfully deployed as shown:
var  names = [
'xxx'
'yyy'
'zzz'
]
var digits = [
4
2
7
]
output  index  int = lastIndexOf(names, 'yyy')
output  indexs  int = indexOf(digits, '4')
output  notFoundIndex  int = lastIndexOf(names, 'zzz')

Deployment succeeded:

enter image description here

Deployed in the Portal:

enter image description here

  • Related