【问题标题】:MAP type parameter / variable in BICEP?BICEP 中的 MAP 类型参数/变量?
【发布时间】:2021-05-20 17:37:12
【问题描述】:

有没有办法在 TF、BICEP 中复制 MAP 变量?在 ARM 模板参考中,我看到“对象”在声明中与 MAP 类似,但在用法上有所不同。

tf - 地图示例 (https://gist.github.com/devops-school/1f3efed15d390748b208a109f9765e0c)

手臂模板对象/二头肌示例 (https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/data-types?tabs=bicep#objects)

谢谢!

【问题讨论】:

  • 你是对的 - 对象几乎是一张地图。您究竟在寻找什么用途?

标签: azure azure-resource-manager azure-bicep


【解决方案1】:

是的,Bicep 中也有 Object 类型。它与 ARM 对应物相似,但也有一些细微差别。在二头肌中,必须在多行中声明一个对象。对象中的每个属性都由键和值组成。键和值用冒号 (:) 分隔。对象允许任何类型的任何属性。

在二头肌中,键不包含在引号中。不要在属性之间使用逗号。

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

属性访问器用于访问对象的属性。它们是使用. 运算符构造的。

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

您还可以使用[] 语法来访问属性。 a.d.e也可以表示为a['d'].e

参考:Objects in Bicep

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-26
    • 2016-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    • 2021-10-02
    • 1970-01-01
    相关资源
    最近更新 更多