gpt4 book ai didi

azure - 当资源在主位置不可用时,如何在 Azure 资源管理器模板的辅助位置部署资源?

转载 作者:行者123 更新时间:2023-12-03 01:29:27 25 4
gpt4 key购买 nike

我有一个 ARM 模板,用于在给定资源组的位置创建资源。以下是部署 SignalR 服务的方法:

    {
"apiVersion": "2018-10-01",
"name": "[variables('signalRName')]",
"type": "Microsoft.SignalRService/signalR",
"location": "[resourceGroup().location]",
"tags": {},
"sku": {
"name": "Free_F1",
"tier": "Free"
},
"properties": { }
}

在加拿大,我可以访问两个地点:加拿大东部加拿大中部。不过,SignalR 在加拿大中部尚不可用,但在加拿大东部可用:

ew-AzResourceGroupDeployment: 11:40:32 AM - Error:Code=LocationNotAvailableForResourceType; Message=The providedlocation 'canadacentral' is not available for resource type'Microsoft.SignalRService/SignalR'. List of available regions for theresource type is'eastus,westus,southeastasia,westeurope,westus2,eastus2,northeurope,australiaeast,canadaeast,centralus,japaneast,uksouth,southcentralus,brazilsouth,francecentral,koreacentral'.

问题

如何将主要位置不可用的资源部署到某个辅助/后备位置?

最佳答案

我找到了一种方法来实现它,但需要进行一些调整。首先,我必须在参数文件中为自己指定一个辅助位置参数。

例如,在以下参数文件中,我将加拿大中部指定为主要位置,将加拿大东部指定为次要位置:

    {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"primaryLocation": {
"value": "Canada Central"
},
"secondaryLocation": {
"value": "Canada East"
}
...
}
}

此参数在我的部署模板文件中定义:

    {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"primaryLocation": {
"type": "string",
"minLength": 3,
"maxLength": 32
}
"secondaryLocation": {
"type": "string",
"minLength": 3,
"maxLength": 32
}
}
... }

然后我发现了providers陈述。该语句返回 the list of locations给定资源类型可用。

因此,我更新了 location 属性,以在 SignalR 可用的位置列表中查找资源组的位置。 If它是contained在列表中,然后我使用资源组的位置。否则,我使用提供的辅助位置。

    {
"apiVersion": "2018-10-01",
"name": "[variables('signalRName')]",
"type": "Microsoft.SignalRService/signalR",
"location": "[if(contains(providers('Microsoft.SignalRService', 'signalR').locations, parameters('primaryLocation')), parameters('primaryLocation'), parameters('secondaryLocation'))]",
"tags": {},
"sku": {
"name": "Free_F1",
"tier": "Free"
},
"properties": { }
}

注意

我无法使用 resourceGroup().location,因为它返回的位置格式与 providers('Microsoft.SignalRService', 'signalR').locations。第一个将返回类似 canadaeast 的内容,而第二个将返回 Canada East

关于azure - 当资源在主位置不可用时,如何在 Azure 资源管理器模板的辅助位置部署资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63649012/

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