更新对象作为参数传递给二头肌文件

问题描述 投票:0回答:1

我有多个需要在部署期间标记的天蓝色资源,并且我有将标记作为参数的二头肌文件。对于所有资源,所有标签都将相同且具有相同的值,除了一个标签

Type
将根据正在部署的资源类型具有不同的值。

param tags object = {}

resource myResourceWithTags 'resourceType' = {
  tags: tags
}

有没有办法将管道中的标签作为

{ "Type" : "{{type}}" }
传递,然后用正确的值替换资源中的
{{type}}

不在管道中执行此操作的原因是因为我一次部署了许多资源,这将要求我为每个基本相同的资源设置单独的标签变量。当前的方法将允许我定义一次变量并让模板处理更新。

我在想类似的事情

tags: contains(tags, 'Type') ? json(replace(tags), '{{type}}', 'appInsights') : tags

但是我还没有想出一种方法来将标签对象转换为字符串并返回(或完全更好的方法)。

azure azure-pipelines azure-resource-manager azure-bicep
1个回答
1
投票

您可以使用

union
函数覆盖类型值:

param tags object = {}

resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
  ...
  tags: contains(tags, 'Type') ? union(tags, {
      Type: 'appInsights'
    }) : tags
  ...
}

您只需要定义一个空值的 Type 属性:

{ "Type" : "" }
© www.soinside.com 2019 - 2024. All rights reserved.