【问题标题】:Azure Policy for tag creation when a Resource Group is created is not working创建资源组时用于创建标记的 Azure 策略不起作用
【发布时间】:2021-08-26 16:06:59
【问题描述】:

我在 Azure Policy 下创建了“修改”效果和“添加替换”操作。

我正在通过 terraform 创建资源组、策略定义、策略分配和角色分配。 我希望在创建资源组并应用策略后立即应用 TAG(因此基本上将使用 TAG 创建资源组,因为策略分配是资源组级别的)。

以下是政策定义:

{
  "properties": {
    "displayName": "Subscription Tags",
    "policyType": "Custom",
    "mode": "All",
    "description": "",
    "metadata": {
      "category": "General",
      "createdBy": "a8cf4bcb-fa6d-4ace-ae63-fbeee97299d4",
      "createdOn": "2021-08-26T11:27:02.358131Z",
      "updatedBy": null,
      "updatedOn": null
    },
    "parameters": {
      "SubscriptionOwner": {
        "type": "String",
        "metadata": {
          "description": "Subscription Owner",
          "displayName": "Subscription Owner"
        }
      },
      "SubscriptionOwnerTagName": {
        "type": "String",
        "metadata": {
          "description": "Subscription Owner Tag Name",
          "displayName": "Subscription Owner Tag Name"
        }
      },
      "resourceType": {
        "type": "String",
        "metadata": {
          "description": "resourceType",
          "displayName": "Resource Type"
        }
      }
    },
    "policyRule": {
      "if": {
        "allof": [
          {
            "equals": "Microsoft.Resources/subscriptions/resourceGroups",
            "field": "type"
          },
          {
            "anyOf": [
              {
                "anyOf": [
                  {
                    "exists": "false",
                    "field": "[concat('tags[', parameters('SubscriptionOwnerTagName'), ']')]"
                  },
                  {
                    "allOf": [
                      {
                        "exists": "true",
                        "field": "[concat('tags[', parameters('SubscriptionOwnerTagName'), ']')]"
                      },
                      {
                        "field": "[concat('tags[', parameters('SubscriptionOwnerTagName'), ']')]",
                        "notEquals": "[parameters('SubscriptionOwner')]"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      "then": {
        "details": {
          "operations": [
            {
              "field": "[concat('tags[', parameters('SubscriptionOwnerTagName'), ']')]",
              "operation": "addOrReplace",
              "value": "[parameters('SubscriptionOwner')]"
            },
            {
              "field": "[concat('tags[', parameters('resourceType'), ']')]",
              "operation": "addOrReplace",
              "value": "[resourceGroup().id]"
            }
          ],
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
          ]
        },
        "effect": "modify"
      }
    }
  },
  "id": "/subscriptions/6e268af1-b2a7-44a7-9a1a-9025889dbe5d/providers/Microsoft.Authorization/policyDefinitions/MyCustomPolicy",
  "type": "Microsoft.Authorization/policyDefinitions",
  "name": "MyCustomPolicy"
}

问题是,没有使用资源组创建 TAG,并且合规性说“不合规”。我必须创建一个修复任务,一旦我运行该任务,就会创建标签。

我无法找到原因,因为document 说一旦创建资源就应该创建标签。只有现有资源需要修复任务。

任何帮助。

【问题讨论】:

    标签: azure-policy


    【解决方案1】:
    • 现有任务范围内的新资源或更新资源将在大约 15 分钟内可用。
    • 新政策或倡议 申请作业大约需要 30 分钟。

    https://docs.microsoft.com/en-us/azure/governance/policy/troubleshoot/general#cause-1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      相关资源
      最近更新 更多