使用Azure Devops部署Azure策略ARM模板失败

里亚C

我们为“允许的位置”建立了一个Azure策略。创建了所需的template.json和parameter.json,如下所示:Template.json

将json文件上传到Azure存储库后尝试使用Azure管道运行时,以下是错误

[错误]请求内容无效,无法反序列化:在JSON中找不到“必填属性”资源。路径“ properties.template”,第1行,位置222。”。

尽管在template.json中提到了资源,但它因此错误而失败。任何人都可以提供任何见解。

   {
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion": "1.0.0.0",
  "parameters": {
      "listOfAllowedLocations": {
  "type": "array"
    }
  },
  "variables": {},
  "resources": [
   {
  "type": "Microsoft.Authorization/policyDefinitions",
  "name": "policylocation",
  "apiVersion": "2018-03-01",
  "properties": {
    "policyType": "Custom",
    "displayName": "policylocation",
    "description": "",
    "mode": "all",
    "parameters": {
      "listOfAllowedLocations": {
        "type": "array",
        "metadata": {
          "description": "The list of locations that can be specified when deploying resources.",
          "displayName": "Allowed locations"
        }
      }
    },
"policyRule": {
  "if": {
    "allOf": [
      {
        "field": "location",
        "notIn": "EastUS"
      },
      {
        "field": "location",
        "notEquals": "global"
      },
      {
        "field": "type",
        "notEquals": "Microsoft.Compute/virtualMachines"
      }
    ]
  },
  "then": {
    "effect": "deny"
  }
}
  }
}
  ]
}

Parameter.json

   {
 "$schema": "https://schema.management.azure.com/schemas/2015-01- 
  01/deploymentParameters.json#",
 "contentVersion": "1.0.0.0",
 "parameters": {
"listOfAllowedLocations": {
  "type":"array",
  "value": "EastUS"
   }
   }
 }
罗伯·S。

当我尝试使用给定的模板和参数文件部署策略时,收到以下错误。

{
    "error": {
        "code": "InvalidDeploymentParameterType",
        "message": "The type of deployment parameter 'listOfAllowedLocations' should not be specified. Please see https://aka.ms/resource-manager-parameter-files for details."
    }
}

这意味着您有一个未使用的参数(listOfAllowedLocations)。尽管对于大多数语言模式而言,使用未使用的参数可能是可以的,但对于策略而言则不是。首先删除此参数或将此参数添加到您的策略中,以便使用它。

接下来,基于您收到的误导性错误消息,我对您的部署方法感到好奇。可以采用许多不同的方式部署策略。门户,Powershell,REST API,仅举几例。我更喜欢REST API方法,因为它在定义和使用方面提供了相当多的灵活性和简便性。如果选择REST API,则实际上可以选择两种不同的方法(作为Azure部署或作为策略定义),分别是以下端点。

PUT https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Resources/deployments/{deploymentName}?api-version=2019-10-01

DOCS- https: //docs.microsoft.com/zh-cn/rest/api/resources/deployments/createorupdate

PUT https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}?api-version=2019-09-01

DOCS- https: //docs.microsoft.com/zh-cn/rest/api/resources/policydefinitions/createorupdate

我更喜欢部署路线,这是因为它使用azure部署机制来部署策略,该策略提供了一致且用户友好的故障排除,重试和检查方法。它还允许您将策略部署为模板文件和参数文件,将部署嵌套在部署中(这在更复杂的用例中很有用),并在部署范围和策略范围中指定参数。但是,部署还存在一些限制,例如,每个订阅和资源组配额(当前为800)。一些定期的房屋清洁将对此有所帮助。

我鼓励使用Azure部署REST API方法,根据您的意图尝试以下操作之一。

选项1a:您希望保留“ listOfAllowedLocations”作为参数,并在策略中使用它。您还希望在DEPLOYMENT范围内应用参数,以使生成的部署策略具有静态定义的允许位置列表。

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Resources/deployments/{deploymentName}?api-version=2019-10-01

身体:

{
    "location": "eastus",
    "properties": {
        "mode": "Incremental",
        "parameters": {
            "listOfAllowedLocations": {
                "value": ["eastus"]
            }
        },
        "template": {
            "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
            "contentVersion": "1.0.0.0",
            "parameters": {
                "listOfAllowedLocations": {
                    "type": "array"
                }
            },
            "variables": {},
            "resources": [
                {
                    "type": "Microsoft.Authorization/policyDefinitions",
                    "name": "policylocation",
                    "apiVersion": "2018-03-01",
                    "properties": {
                        "policyType": "Custom",
                        "displayName": "policylocation",
                        "description": "",
                        "mode": "all",
                        "parameters": {},
                        "policyRule": {
                            "if": {
                                "allOf": [
                                    {
                                        "field": "location",
                                        "notIn": "[parameters('listOfAllowedLocations')]"
                                    },
                                    {
                                        "field": "location",
                                        "notEquals": "global"
                                    },
                                    {
                                        "field": "type",
                                        "notEquals": "Microsoft.Compute/virtualMachines"
                                    }
                                ]
                            },
                            "then": {
                                "effect": "deny"
                            }
                        }
                    }
                }
            ]
        }
    }
}

选项1b:您要保留“ listOfAllowedLocations”作为参数,并在策略中使用它。您还希望在POLICY DEFINITION范围内应用参数,以便在分配时可以操纵允许位置的已部署结果列表。请注意,在策略资源定义('[[')中,参数的作用域和参数的转义之间存在细微的差异。

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Resources/deployments/{deploymentName}?api-version=2019-10-01

身体:

{
    "location": "eastus",
    "properties": {
        "mode": "Incremental",
        "parameters": {},
        "template": {
            "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
            "contentVersion": "1.0.0.0",
            "parameters": {},
            "variables": {},
            "resources": [
                {
                    "type": "Microsoft.Authorization/policyDefinitions",
                    "name": "policylocation",
                    "apiVersion": "2018-03-01",
                    "properties": {
                        "policyType": "Custom",
                        "displayName": "policylocation",
                        "description": "",
                        "mode": "all",
                        "parameters": {
                            "listOfAllowedLocations": {
                                "type": "array",
                                "defaultValue": ["eastus"]
                            }
                        },
                        "policyRule": {
                            "if": {
                                "allOf": [
                                    {
                                        "field": "location",
                                        "notIn": "[[parameters('listOfAllowedLocations')]"
                                    },
                                    {
                                        "field": "location",
                                        "notEquals": "global"
                                    },
                                    {
                                        "field": "type",
                                        "notEquals": "Microsoft.Compute/virtualMachines"
                                    }
                                ]
                            },
                            "then": {
                                "effect": "deny"
                            }
                        }
                    }
                }
            ]
        }
    }
}

选项2:允许位置的静态定义。这将基本上避免通过部署或策略分配传递参数的过程。

{
    "location": "eastus",
    "properties": {
        "mode": "Incremental",
        "parameters": {},
        "template": {
            "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
            "contentVersion": "1.0.0.0",
            "parameters": {},
            "variables": {},
            "resources": [
                {
                    "type": "Microsoft.Authorization/policyDefinitions",
                    "name": "policylocation",
                    "apiVersion": "2018-03-01",
                    "properties": {
                        "policyType": "Custom",
                        "displayName": "policylocation",
                        "description": "",
                        "mode": "all",
                        "parameters": {},
                        "policyRule": {
                            "if": {
                                "allOf": [
                                    {
                                        "field": "location",
                                        "notIn": ["eastus"]
                                    },
                                    {
                                        "field": "location",
                                        "notEquals": "global"
                                    },
                                    {
                                        "field": "type",
                                        "notEquals": "Microsoft.Compute/virtualMachines"
                                    }
                                ]
                            },
                            "then": {
                                "effect": "deny"
                            }
                        }
                    }
                }
            ]
        }
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

由于对链接服务的授权,Azure ADF ARM模板部署失败

来自分类Dev

由于对链接服务的授权,Azure ADF ARM模板部署失败

来自分类Dev

Azure ARM模板将部署者对象ID添加到关键保管库访问策略

来自分类Dev

如何使用Azure DevOps Pipeline部署多个ARM

来自分类Dev

如何使用arm模板部署python azure函数?

来自分类Dev

使用 arm 模板部署 azure Key Vault Secret 出现错误

来自分类Dev

Azure中的部署脚本ARM模板

来自分类Dev

Azure存储:通过ARM模板部署队列

来自分类Dev

Azure ARM JSON 模板部署逻辑说明

来自分类Dev

WordPress部署使用Azure失败

来自分类Dev

Azure ARM模板部署。未提供模板参数的值

来自分类Dev

使用Azure DevOps将发行版部署到测试环境时失败Azure文件复制

来自分类Dev

Azure Devops生成策略

来自分类Dev

使用DevOps部署ARM模板时出现奇怪的错误

来自分类Dev

运行DevOps Server部署模板时,Active Directory帐户/密钥库身份验证上的Azure LinkedAuthorization失败

来自分类Dev

如何获取Azure(ARM)部署模板的clientId和clientsecret

来自分类Dev

在 Azure 中通过 ARM 模板部署 Windows 和 Linux VM

来自分类Dev

使用 azure devops 分支各自的部署

来自分类Dev

如何使用zip文件和ARM模板将bot框架应用程序部署为Azure。

来自分类Dev

未使用Azure ARM模板将标签部署到服务器场

来自分类Dev

如何在输出中使用 ARM 模板在部署后列出 Azure VM 或 HDI 集群的 IP

来自分类Dev

Azure DevOps:Blazor部署在管道生成中失败

来自分类Dev

使用Azure Devops Pipeline将标签(带有空格)传递到ARM模板

来自分类Dev

在Azure ARM模板中使用条件

来自分类Dev

使用 ARM 模板创建 Azure IoThub 端点?

来自分类Dev

使用资源管理器(ARM)模板通过Git部署来部署Azure Web App

来自分类Dev

Azure ARM 模板问题

来自分类Dev

gitlab使Azure部署失败

来自分类Dev

使用ARM将Azure策略应用于管理组

Related 相关文章

  1. 1

    由于对链接服务的授权,Azure ADF ARM模板部署失败

  2. 2

    由于对链接服务的授权,Azure ADF ARM模板部署失败

  3. 3

    Azure ARM模板将部署者对象ID添加到关键保管库访问策略

  4. 4

    如何使用Azure DevOps Pipeline部署多个ARM

  5. 5

    如何使用arm模板部署python azure函数?

  6. 6

    使用 arm 模板部署 azure Key Vault Secret 出现错误

  7. 7

    Azure中的部署脚本ARM模板

  8. 8

    Azure存储:通过ARM模板部署队列

  9. 9

    Azure ARM JSON 模板部署逻辑说明

  10. 10

    WordPress部署使用Azure失败

  11. 11

    Azure ARM模板部署。未提供模板参数的值

  12. 12

    使用Azure DevOps将发行版部署到测试环境时失败Azure文件复制

  13. 13

    Azure Devops生成策略

  14. 14

    使用DevOps部署ARM模板时出现奇怪的错误

  15. 15

    运行DevOps Server部署模板时,Active Directory帐户/密钥库身份验证上的Azure LinkedAuthorization失败

  16. 16

    如何获取Azure(ARM)部署模板的clientId和clientsecret

  17. 17

    在 Azure 中通过 ARM 模板部署 Windows 和 Linux VM

  18. 18

    使用 azure devops 分支各自的部署

  19. 19

    如何使用zip文件和ARM模板将bot框架应用程序部署为Azure。

  20. 20

    未使用Azure ARM模板将标签部署到服务器场

  21. 21

    如何在输出中使用 ARM 模板在部署后列出 Azure VM 或 HDI 集群的 IP

  22. 22

    Azure DevOps:Blazor部署在管道生成中失败

  23. 23

    使用Azure Devops Pipeline将标签(带有空格)传递到ARM模板

  24. 24

    在Azure ARM模板中使用条件

  25. 25

    使用 ARM 模板创建 Azure IoThub 端点?

  26. 26

    使用资源管理器(ARM)模板通过Git部署来部署Azure Web App

  27. 27

    Azure ARM 模板问题

  28. 28

    gitlab使Azure部署失败

  29. 29

    使用ARM将Azure策略应用于管理组

热门标签

归档