我可以通过Azure策略添加多个语句或多个效果吗?

发布于 2025-02-08 18:47:24 字数 187 浏览 5 评论 0原文

我需要创建一个Azure策略,以在没有标签的情况下创建的资源添加标签(例如名称,支持,CostCenter),

问题是,如果例如我创建VM并添加了名称标签,但我忘记了支持和CostCenter I希望我的策略添加这两个并保留我的姓名价值标签。

我可以添加一些条件来修改效果吗?还是倍数,如果/然后在定义中对象?

谢谢,

I need to create an Azure policy for adding tags to resources which are being created without tags (eg name, support, costcenter)

The issue is that if for example I create a VM and I add Name tag, but I forget support and costcenter I want that my policy adds this two and keep my Name value tag.

Can I add some condition to modify effect? Or multiples if/then objects in the definition?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

行雁书 2025-02-15 18:47:24

我认为,如果/then 块可以根据Azure Policy模式[此处] [1]提供多个。另外,这是DOC页面演示[策略定义结构] [1]。

但是,就您而言,您不需要这个,您可能只需要[]操作中的额外操作。

"then": {
  "effect": "modify",
  "details": {
    "roleDefinitionIds": [
      "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
    ],
  "operations": [
    {
      "operation": "Add",
      "field": "tags['costcenter']",
      "value": "US123"
    },
    {
      "operation": "Add",
      "field": "tags['Support']",
      "value": "Operations"
    }
  ]
  }
}

I don't think multiple if/then blocks are available as per Azure Policy schema [here][1]. Also here's the doc page demonstrates the [policy definition structure][1].

However, in your case, you don't need this, you might only need extra operations inside the []operations.

"then": {
  "effect": "modify",
  "details": {
    "roleDefinitionIds": [
      "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
    ],
  "operations": [
    {
      "operation": "Add",
      "field": "tags['costcenter']",
      "value": "US123"
    },
    {
      "operation": "Add",
      "field": "tags['Support']",
      "value": "Operations"
    }
  ]
  }
}
淡墨 2025-02-15 18:47:24

是的,您可以添加倍数条件语句。

有关结合逻辑运算符

{
    "properties": {
        "displayName": "Audit Azure Spring Cloud instances where distributed tracing is not enabled",
        "description": "Distributed tracing tools in Azure Spring Cloud allow debugging and monitoring the complex interconnections between microservices in an application. Distributed tracing tools should be enabled and in a healthy state.",
        "mode": "Indexed",
        "policyRule": {
            "if": {
                "allOf": [{
                        "field": "type",
                        "equals": "Microsoft.AppPlatform/Spring"
                    },
                    {
                        "anyOf": [{
                                "field": "Microsoft.AppPlatform/Spring/trace.enabled",
                                "notEquals": "true"
                            },
                            {
                                "field": "Microsoft.AppPlatform/Spring/trace.state",
                                "notEquals": "Succeeded"
                            }
                        ]
                    }
                ]
            },
            "then": {
                "effect": "audit"
            }
        }
    }
}

Yes, you can add multiples conditional statements.

More information about Combining Logical operators

{
    "properties": {
        "displayName": "Audit Azure Spring Cloud instances where distributed tracing is not enabled",
        "description": "Distributed tracing tools in Azure Spring Cloud allow debugging and monitoring the complex interconnections between microservices in an application. Distributed tracing tools should be enabled and in a healthy state.",
        "mode": "Indexed",
        "policyRule": {
            "if": {
                "allOf": [{
                        "field": "type",
                        "equals": "Microsoft.AppPlatform/Spring"
                    },
                    {
                        "anyOf": [{
                                "field": "Microsoft.AppPlatform/Spring/trace.enabled",
                                "notEquals": "true"
                            },
                            {
                                "field": "Microsoft.AppPlatform/Spring/trace.state",
                                "notEquals": "Succeeded"
                            }
                        ]
                    }
                ]
            },
            "then": {
                "effect": "audit"
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文