0

我尝试最小化我的 ARM 模板,但我被困在这里......

我的原始模板是:

    "parameters": {
        "subscriptionId": {
            "type": "String"
        },
        "resourcegroupName": {
            "type": "String"
        },
.....
        "databases": {
            "type": "Array"
        },
        "failoverPolicy": {
            "type": "String"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Sql/servers/failoverGroups",
            "name": "[concat(parameters('primaryServer'), '/', parameters('failovergroupName'))]",
            "apiVersion": "2015-05-01-preview",
            "location": "eastus",
            "properties": {
                "readWriteEndpoint": {
                    "failoverPolicy": "[parameters('failoverPolicy')]"
                },
                "partnerServers": [
                    {
                        "id": "[concat('/subscriptions/',parameters('subscriptionId'),'/resourceGroups/',parameters('resourcegroupName'),'/providers/Microsoft.Sql/servers/',parameters('partnerServer'))]"
                    }
                ],
                "databases": "[parameters('databases')]"
            },
            "dependsOn": [
                "[concat('Microsoft.Sql/servers/',parameters('partnerServer'))]",
                "[concat('Microsoft.Sql/servers/',parameters('partnerServer'),'/elasticPools/',parameters('primaryElasticPoolName'))]"
            ]
        },
....

我的参数文件包含:

    "parameters": {
        "subscriptionId": {
            "value": "11111-4444-5555-666-777777777"
        },
        "resourcegroupName": {
            "type": "RG-ElasticPool"
        },

        "primaryElasticPoolName": {
            "value": "crelasticpool01"
        },

....
            "databases": {
            "value": [
                "/subscriptions/11111-4444-5555-666-777777777/resourceGroups/RG-ElasticPool/providers/Microsoft.Sql/servers/crelasticsrv01/databases/crelasticdb03",
                "/subscriptions/11111-4444-5555-666-777777777/resourceGroups/RG-ElasticPool/providers/Microsoft.Sql/servers/crelasticsrv01/databases/crelasticdb02",
                "/subscriptions/11111-4444-5555-666-777777777/resourceGroups/RG-ElasticPool/providers/Microsoft.Sql/servers/crelasticsrv01/databases/crelasticdb01"
            ]
        },
        "failoverPolicy": {
            "value": "Manual"
        }
    }

我只能:

"databases": {
            "value": [
                "crelasticdb03",
                "crelasticdb02",
                "crelasticdb01"
            ]

在我的参数文件中,而不是长 id,并在我的模板文件中连接长 id

我尝试了几个配置,例如:

"databases": "[concat('/subscriptions/',parameters('subscriptionId'),'/resourceGroups/',parameters('resourcegroupName'),'/providers/Microsoft.Sql/servers/',parameters('primaryServer'),'/databases/',parameters('databases')[copyIndex()])]"

但我总是收到与 copyindex 相关的部署错误...

4

1 回答 1

1

不幸的是,您不能使用复制功能来创建数组。你只能用它创建对象数组。您似乎需要一个字符串数组,这是不可能的。

你可以使用嵌套模板和循环,但它更容易\更干净,只需使用你所拥有的,tbh。

于 2019-02-23T07:34:05.107 回答