gpt4 book ai didi

使用 Visual Studio 部署 Azure 策略

转载 作者:行者123 更新时间:2023-12-03 02:56:08 25 4
gpt4 key购买 nike

我正在尝试在内置允许的位置使用 Azure 策略。

下面是我的 ARM 模板定义

{
"$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": "Test",
"apiVersion": "2018-03-01",
"properties": {
"displayName": "Test allowed locations",
"policyType": "BuiltIn",
"description": "This policy enables you to restrict the locations your organization can specify when deploying resources. Use to enforce your geo-compliance requirements.",
"parameters": {
"listOfAllowedLocations": {
"type": "Array",
"metadata": {
"description": "The list of locations that can be specified when deploying resources.",
"strongType": "location",
"displayName": "Allowed locations"
}
}
},
"policyRule": {
"if": {
"not": {
"field": "location",
"in": "[parameters('listOfAllowedLocations')]"
}
},
"then": {
"effect": "Deny"
}
}
}
}],
"outputs": {}
}

当我尝试使用 Visual Studio 部署选项进行部署时,出现以下错误

{
"error": {
"code": "InvalidPolicyUri",
"message": "The policy request scope '/subscriptions/xxx/resourcegroups/Test' should be '/', '/subscriptions/id' or '/providers/Microsoft.Management/managementGroups/id'."
}
}

如果有人能够指导我使用 Visual Studio 部署策略的正确方法,我真的很感激。一旦在 VS 部署测试中成功,此模板稍后将进入 DevOps 发布管道。

最佳答案

我明白了。默认情况下,Visual Studio 使用资源组部署,这就是它不起作用的原因。我们需要使用 New-AzureRmDeployment 而不是 New-AzureRmResourceGroupDeployment。

关于使用 Visual Studio 部署 Azure 策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52711218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com