我有一个ARM模板,用于在给定资源组的位置中创建资源。这是我如何部署SignalR服务的方法:
{
"apiVersion": "2018-10-01",
"name": "[variables('signalRName')]",
"type": "Microsoft.SignalRService/signalR",
"location": "[resourceGroup().location]",
"tags": {},
"sku": {
"name": "Free_F1",
"tier": "Free"
},
"properties": { }
}
在加拿大,我可以访问两个位置:Canada East
和Canada Central
。然而,SignalR在Canada Central
中尚不可用,但在Canada East
中却可用:
ew-AzResourceGroupDeployment:11:40:32 AM-错误: Code = LocationNotAvailableForResourceType; Message =提供的 位置“ canadacentral”不适用于资源类型 'Microsoft.SignalRService / SignalR'。可用区域的列表 资源类型为 “东,西,南亚,西,欧洲,西,东2,北,欧洲,澳大利亚,加拿大,中部,中央,日本,英国,南中,巴西,巴西,中央,韩国”。
问题
我该怎么做才能将主要位置中不可用的资源部署到某个次要/后备位置?
答案 0 :(得分:2)
我已经找到了一种方法来实现,但需要进行一些调整。首先,我必须在参数文件中指定一个辅助位置参数。
例如,在以下参数文件中,我将Canada Central
指定为主要位置,并将Canada East
指定为辅助位置:
{
"$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
。
答案 1 :(得分:0)
您无法做到这一点,您必须事先知道这一点,或者只是在手臂模板之外处理故障并重新部署到另一个区域。大多数服务都提供了一个api端点来确定支持哪些位置