使用Visual Studio部署Azure策略

时间:2018-10-08 23:11:15

标签: azure cloud policies

我正在尝试在允许的内置位置使用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发布管道。

1 个答案:

答案 0 :(得分:0)

我知道了。默认情况下,Visual Studio使用资源组部署,因此这是行不通的。我们需要使用New-AzureRmDeployment而不是New-AzureRmResourceGroupDeployment。