我有多个共享相同连接字符串(和应用程序设置)的Azure WebApp。我想重构下面的内容,以便config connectionstring资源只定义一次并从每个WebApp引用。这可能吗?如果是这样,怎么样?
// 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"
}
}
}
]
}
答案 0 :(得分:0)
如果您的网站足够相似,您可以创建多个使用复制循环的网站。例如
"variables": {
"webSiteNameArray": ["apiPortalName", "userPortalName"]
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "[variables('webSiteNameArray')[copyIndex()]]",
"type": "Microsoft.Web/sites",
"copy": {
"name": "webSiteLoop",
"count": 2
},
"dependsOn": [
"[concat('Microsoft.Web/serverFarms/', variables('hostingPlanName'))]"
],
"resources": [
{
"apiVersion": "2015-08-01",
"type": "config",
"name": "connectionstrings",
"dependsOn": [
"[concat('Microsoft.Web/Sites/', variables('webSiteNameArray')[copyIndex()])]"
],
"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"
}
}
}
]
}