【问题标题】:Azure tagging policy for Linux and Windows machines适用于 Linux 和 Windows 计算机的 Azure 标记策略
【发布时间】:2020-04-20 09:28:14
【问题描述】:

有一个 ARM 策略用于检查 Azure 中任何 VM 上是否存在特定标签:

{
  "mode": "Indexed",
  "policyRule": {
    "if": {
      "AllOf": [
        {
          "field": "type",
          "in": [
            "microsoft.compute/virtualmachines",
            "Microsoft.ClassicCompute/virtualMachines"
          ]
        },
        {
          "field": "[concat('tags[', parameters('tagName'), ']')]",
          "exists": "false"
        }
      ]
    },
    "then": {
      "effect": "audit"
    }
  },
  "parameters": {
    "tagName": {
      "type": "String",
      "metadata": {
        "displayName": "tagName",
        "description": "Tag used to unequally identify a VM"
      }
    }
  }
}

问题:

如何创建一个单独的策略,一个用于 Linux,另一个用于 Windows 虚拟机?我找不到如何过滤的方法。 IE。对于 Windows,我使用此策略脚本:

{
  "mode": "Indexed",
  "policyRule": {
    "if": {
      "allOf": [
        {
          "field": "type",
          "equals": "Microsoft.Compute/virtualMachines"
        },
        {
          "field": "Microsoft.Compute/imagePublisher",
          "in": [
            "MicrosoftWindowsServer",
            "MicrosoftSQLServer"
          ]
        },
        {
          "field": "[concat('tags[', parameters('tagName'), ']')]",
          "exists": "false"
        }
      ]
    },
    "then": {
      "effect": "audit"
    }
  },
  "parameters": {
    "tagName": {
      "type": "String",
      "metadata": {
        "displayName": "tagName",
        "description": "Tag used to help unequally identify a VM"
      }
    }
  }
}

但上面显示了Windows和Linux,因为它的逻辑类似于“如果VM是windows并且具有特定标签,则表示合规;否则如果没有特定标签或VM是Linux,则视为不合规”。

需求:

1x 策略以查看只有多少 Windows 虚拟机符合要求(根据标签)。

1x 策略查看只有多少 Linux 虚拟机符合要求(根据标签)。

【问题讨论】:

    标签: azure azure-policy


    【解决方案1】:

    尝试使用 Microsoft.Compute/virtualMachines/imagePublisher 而不是 Microsoft.Compute/imagePublisher

    【讨论】:

      【解决方案2】:
      {
      "mode": "Indexed",
      "policyRule": {
        "if": {
          "allOf": [
            {
              "field": "type",
              "equals": "Microsoft.Compute/virtualMachines"
            },
            {
              "field": "Microsoft.Compute/imagePublisher",
              "in": [
                "MicrosoftWindowsServer",
                "MicrosoftSQLServer"
              ]
            }
          ]
        },
        "then": {
          "effect": "auditIfNotExists",
          "details": {
            "type": "Microsoft.Compute/virtualMachines",
            "name": "[field('name')]",
            "existenceCondition": {
              "field": "[concat('tags[', parameters('tagName'), ']')]",
              "exists": "true"
            }
          }
        }
      },
      "parameters": {
        "tagName": {
          "type": "String",
          "metadata": {
            "displayName": "tagName",
            "description": "Tag used to help unequally identify a VM"
          }
        }
      }
      

      最终为我解决了这个问题

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-01-11
        • 1970-01-01
        • 2012-10-07
        • 1970-01-01
        • 2022-09-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多