【问题标题】:DeployIfnotexists azure policy failing with errorDeployIfnotexists azure 策略失败并出现错误
【发布时间】:2021-06-02 17:47:10
【问题描述】:

我是 azure 策略的新手,我正在尝试为存储帐户编写 deployifnotexists 策略,该策略将为 300 天的容器启用时间点还原。它在部署时出错,错误提示 HttpResourceNotFound 和随机 http 请求 url。我想知道该政策是否正确,这是我创建的我正在使用的代码:

    {
  "properties": {
    "displayName": "storage-pointintime",
    "policyType": "Custom",
    "mode": "All",
    "metadata": {
    },
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy."
        },
        "allowedValues": [
          "DeployIfNotExists",
          "Deny",
          "Audit"
        ],
        "defaultValue": "DeployIfNotExists"
      },
      "retentionInDays": {
        "type": "String",
        "metadata": {
          "displayName": "Retention Days",
          "description": "Set the number of Retention Days."
        },
        "defaultValue": "300"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Storage/storageAccounts"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Storage/storageAccounts/blobServices/restorePolicy",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/<id>"
          ],
          "existenceCondition": {
            "field": "Microsoft.Storage/storageAccounts/blobServices/restorePolicy.days",
            "equals": "[parameters('retentionInDays')]"
          },
          "deployment": {
            "properties": {
              "mode": "incremental",
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "storageAccounts": {
                    "type": "string"
                  },
                  "retentionDays": {
                    "type": "string"
                  }
                },
                "resources": [
                  {
                    "name": "[concat(parameters('storageAccounts'),'/default')]",
                    "type": "Microsoft.Storage/storageAccounts/blobServices/restorePolicy",
                    "apiVersion": "2021-04-01",
                    "properties": {
                      "retentionInDays": "[parameters('retentionDays')]"
                    }
                  }
                ]
              },
              "retentionDays": {
                "value": "[parameters('retentionInDays')]"
              }
            }
          }
        }
      }
    }
  }
}

【问题讨论】:

    标签: azure azure-storage azure-blob-storage azure-policy


    【解决方案1】:

    如果要为容器启用时间点恢复,类型应为Microsoft.Storage/storageAccounts/blobServices。 Azure ARM 模板不提供类型Microsoft.Storage/storageAccounts/blobServices/restorePolicy

    例如

    {
                "name": "[concat(parameters('storageAccountName'), '/default')]",
                "type": "Microsoft.Storage/storageAccounts/blobServices",
                "apiVersion": "2019-06-01",
                "properties": {
                    "restorePolicy": {
                        "enabled": "[parameters('isContainerRestoreEnabled')]",
                        "days": "[parameters('containerRestorePeriodDays')]"
                    },
                    "deleteRetentionPolicy": {
                        "enabled": "[parameters('isBlobSoftDeleteEnabled')]",
                        "days": "[parameters('blobSoftDeleteRetentionDays')]"
                    },
                    "containerDeleteRetentionPolicy": {
                        "enabled": "[parameters('isContainerSoftDeleteEnabled')]"
                    },
                    "changeFeed": {
                        "enabled": "[parameters('changeFeed')]"
                    },
                    "isVersioningEnabled": "[parameters('isVersioningEnabled')]"
                },
                "dependsOn": [
                    "[concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]"
                ]
            }
    

    更多详情请参考herehere

    【讨论】:

    • 如果对你有用,可以accept it as an answer吗?
    • 我按照您的建议进行了更新,但政策似乎没有生效。它成功但没有更新我觉得奇怪的属性
    • @mikeknows 能否请您通过活动日志查看?
    • @mikeknows 你能提供你的模板吗?
    • 我正在使用描述中提供的模板。当我尝试使用错误的值进行更新时,属性不会变回正确
    猜你喜欢
    • 2021-03-26
    • 2019-08-15
    • 1970-01-01
    • 2022-07-01
    • 2017-04-12
    • 2019-10-25
    • 2021-01-07
    • 2017-03-07
    • 2018-02-24
    相关资源
    最近更新 更多