Coder Perfect

In BICEP, is there a MAP type parameter or variable?

Problem

Is it possible to recreate the MAP variable in BICEP using TF? In the ARM template reference, I find that “object” is equivalent to a MAP in terms of declaration but not in terms of usage.

(https://gist.github.com/devops-school/1f3efed15d390748b208a109f9765e0c) tf – map example

(https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/data-types?tabs=bicep#objects) arm template object / bicep example

Thanks!

Asked by Chief

Solution #1

In Bicep, there is an Object type as well. It is comparable to the ARM version, however there are some minor variations. In Bicep, an object must be declared in multiple lines. Each property in an object consists of key and value. The key and value are separated by a colon (:). An object allows any property of any type.

The key in Bicep is not enclosed by quotations. When separating properties, avoid using commas.

param exampleObject object = {
  name: 'test name'
  id: '123-abc'
  isCurrent: true
  tier: 1
}

Property accessors are used to gain access to an object’s properties. The. operator is used to create them.

var a = {
  b: 'Dev'
  c: 42
  d: {
    e: true
  }
}

output result1 string = a.b // returns 'Dev' 
output result2 int = a.c // returns 42
output result3 bool = a.d.e // returns true

To access a property, you can alternatively use the [] syntax. a[‘d’].e is another way to write a.d.e.

Objects in Biceps (reference)

Answered by Bhargavi Annadevara

Post is based on https://stackoverflow.com/questions/67625415/map-type-parameter-variable-in-bicep