Azure策略中匹配等通配符之间的区别

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

我使用此处记录的JSON结构编写Azure策略:https://docs.microsoft.com/en-us/azure/governance/policy/concepts/definition-structure

有人能够确认是否可以使用星号通配符和“?”,“#”或“。”。在相同的声明。正如它所说,我认为你只能在比较上使用星号,而在匹配比较中使用其他星号。

非常感谢

我的标记字段必须以4个数字开头,然后是分号,但之后我不关心编码的内容。理想情况下,这将是

####;*

但我发现我必须编码####;。或####; ..或####; ...等

{
  "if": {
    "allOf": [
      {
        "field": "type",
        "in": "[parameters('type')]"
      },
      {
        "not": {
          "anyOf": [
            {

              "field": "[concat('tags[','tag_name', ']')]",
              "match": "####;"
            },
            {
              "field": "[concat('tags[','tag_name', ']')]",
              "match": "####;."
            },
            {
              "field": "[concat('tags[','tag_name', ']')]",
              "match": "####;.."
            },
            {
              "field": "[concat('tags[','tag_name', ']')]",
              "match": "####;..."
            },
            {
              "field": "[concat('tags[','tag_name', ']')]",
              "match": "####;...."
            },
            {
              "field": "[concat('tags[','tag_name', ']')]",
              "match": "####;....."
            },
            {
              "field": "[concat('tags[','tag_name', ']')]",
              "match": "####;......"
            },

有没有更好的方法来实现这一目标?

azure policy
1个回答
0
投票

你是正确的,你不能在match子句中使用星号通配符(*)。

但是,你可以使用value clausetake and field functions来达到你想要的效果:

{
  "if": {
    "allOf": [
      {
        "field": "type",
        "in": "[parameters('type')]"
      },
      {
        "not": {
          "value": "[take(field('tags[tag_name]'), 5)]",
          "match": "####;"
        }
      }
    ]
  },
  "then": {
    "effect": "audit"
  }
}
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.