Azure模板如何根据资源组位置更改资源名称?



我正在制作一个通用模板,它在每个区域使用不同的vnet。如何根据位置更改模板,设置vnet名称。

我们可以使用if (resourcegroup.location)吗?

我想我知道你发生了什么事,你没有与一个有效的值进行比较,"它不是resourceGroup()。位置,在本例中是"eastus"。您可以进行测试部署,并查看输出以检查这类值。

我已经修改了你在注释中传递的模板来做你想做的。

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_ZRS",
"Premium_LRS"
],
"metadata": {
"description": "Storage Account type"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"storageAccountName": "[if(equals(resourceGroup().location,'eastus'),'eastusstorageaccount','noteastusstorageaccount')]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2018-07-01",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "StorageV2",
"properties": {}
}
],
"outputs": {
"storageAccountName": {
"type": "string",
"value": "[variables('storageAccountName')]"
},
"location": {
"type": "string",
"value": "[resourceGroup().location]"
}
}
}

要以动态的方式做你想做的事情,我会尝试对vbnet的名称进行编码。像这样:

  1. eastusvbnet
  2. westeuropevbnet
  3. uksouthvbnet

我将在变量中输入:

"variables": {
"storageAccountName": "[concat(resourceGroup().location,'vbnet')]"
}

最新更新