0
我有多個共享相同連接字符串(和應用程序設置)的Azure WebApps。我想重構下面的內容,以便配置連接字符串資源只定義一次並從每個WebApp引用。這可能嗎?如果是這樣,怎麼樣?在Azure資源管理器模板中共享資源
// some sections clipped for brevity
{
"apiVersion": "2015-08-01",
"name": "[variables('apiPortalName')]",
"type": "Microsoft.Web/sites",
"dependsOn": [
"[concat('Microsoft.Web/serverFarms/', variables('hostingPlanName'))]"
],
"resources": [
{
"apiVersion": "2015-08-01",
"type": "config",
"name": "connectionstrings",
"dependsOn": [
"[concat('Microsoft.Web/Sites/', variables('apiPortalName'))]"
],
"properties": {
"Default": {
"value": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('settingsDatabaseName'), ';User Id=', parameters('databaseAdminLogin'), '@', variables('sqlServerName'), ';Password=', parameters('databaseAdminPassword'), ';')]",
"type": "SQLAzure"
}
}
}
]
},
{
"apiVersion": "2015-08-01",
"name": "[variables('userPortalName')]",
"type": "Microsoft.Web/sites",
"dependsOn": [
"[concat('Microsoft.Web/serverFarms/', variables('hostingPlanName'))]"
],
"resources": [
{
"apiVersion": "2015-08-01",
"type": "config",
"name": "connectionstrings",
"dependsOn": [
"[concat('Microsoft.Web/Sites/', variables('userPortalName'))]"
],
"properties": {
"Default": {
"value": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('settingsDatabaseName'), ';User Id=', parameters('databaseAdminLogin'), '@', variables('sqlServerName'), ';Password=', parameters('databaseAdminPassword'), ';')]",
"type": "SQLAzure"
}
}
}
]
}
您應該能夠使用[變量](https://azure.microsoft.com/en-us/documentation/articles/resource-group-authoring-templates/#variables)了點。 – BenV
甜。我不知道變量可能是對象。請添加爲答案,我會接受。 –
對不起,看起來我錯了。你可以在變量定義中使用一些函數,但不能使用'reference()'。 – BenV