【问题标题】:How to add dynamic tag in Azure Policy?如何在 Azure Policy 中添加动态标签?
【发布时间】:2021-08-25 05:59:22
【问题描述】:

我需要添加资源类型作为标签值。有人可以帮我创建这个吗?

到目前为止,我已应用此示例策略。我需要在资源类型中添加标签名称resource_class,它应该从类型中获取它,我可以将名称拆分为值中的类型名称。

{
"mode": "Indexed",
"policyRule": {
  "if": {
    "anyOf": [
      {
        "field": "tags[division]",
        "exists": "false"
      },
      {
        "field": "tags[division_code]",
        "exists": "false"
      }
    
    ]
  },
  "then": {
    "effect": "append",
    "details": [
      {
        "field": "tags[division]",
        "value": "[tolower(parameters('division'))]"
      },
      {
        "field": "tags[division_code]",
        "value": "[tolower(parameters('division_code'))]"
      }
    ]
  }
},
"parameters": {
  "division": {
    "type": "String",
    "metadata": {
      "displayName": "division",
      "description": "Value of the tag, such as 'production'"
    }
  },
  "division_code": {
    "type": "String",
    "metadata": {
      "displayName": "division_code",
      "description": "Value of the tag, such as '1234'"
    }
  }
  
}

}

【问题讨论】:

  • 到目前为止你有什么?
  • 我已经用政策代码更新了我的问题。

标签: json azure azure-policy


【解决方案1】:

我的理解是您正在尝试将资源类型添加为标签值。如果是正确的,你可以像下面这样写

{
    "field": "tags[division]",
    "value": "[field('type')]"
  }

【讨论】:

  • 抱歉回复晚了,谢谢。这与 MS 建议的方式相同。
【解决方案2】:

根据文档目前,并非所有资源类型都支持标签。要确定是否可以将标签应用于资源类型,请参阅Tag support for Azure resources

您可以使用Azure Policy 框架并且有built-in 定义来满足您的要求。 基于doc.

更多信息请参考以下链接:

Azure Policy pattern: tags| MS DOC.

.Azure Poilicy Sample| MS DOC.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-04
    • 1970-01-01
    • 1970-01-01
    • 2020-01-13
    • 2014-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多