[英]how do we include connectionstrings in ARM template for function app?
这是我尝试过的方法,尽管它没有向门户中的“连接字符串”部分添加任何内容:
"appSettings": [
{
"name": "WEBSITE_WEBDEPLOY_USE_SCM",
"value": "false"
},
{
"name": "XDT_MicrosoftApplicationInsights_BaseExtensions",
"value": "disabled"
},
{
"name": "XDT_MicrosoftApplicationInsights_Mode",
"value": "default"
}
],
"connectionStrings": [
{
"name": "DefaultConnection",
"connectionString": "[concat('Server=tcp:',reference(parameters('ccc_app_sqlserver_name')).fullyQualifiedDomainName,',1433;Initial Catalog=',parameters('ccc_app_db_name'),';Persist Security Info=False;User ID=',reference(parameters('ccc_app_sqlserver_name')).administratorLogin,';Password=',parameters('sqlserver_admin_password'),';MultipleActiveResultSets=true;Persist Security Info=true')]",
"type": "SQLAzure"
}
]
我正在使用这个定义。
我们如何在 ARM 模板中添加连接字符串?
将连接字符串设置为Microsoft.Web/sites
是我使用的解决方案:
{
"type": "Microsoft.Web/sites",
"apiVersion": "2018-11-01",
"name": "[variables('webSiteName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
],
"kind": "app",
"properties": {
"enabled": true,
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('webSiteName'))]",
"siteConfig": {
"connectionStrings": [
{
"name": "DefaultConnection",
"connectionString": "[concat('Server=tcp:',reference(parameters('ccc_app_sqlserver_name')).fullyQualifiedDomainName,',1433;Initial Catalog=',parameters('ccc_app_db_name'),';Persist Security Info=False;User ID=',reference(parameters('ccc_app_sqlserver_name')).administratorLogin,';Password=',parameters('sqlserver_admin_password'),';MultipleActiveResultSets=true;Persist Security Info=true')]",
"type": "SQLAzure"
}
]
}
}
}
编辑:
这是一个设置连接字符串的工作二头肌示例: https://gist.github.com/mjisaak/e7ddb416f86027658a3fa3d24feb3e0b
这里对应的ARM模板: https://gist.github.com/mjisaak/76fa5a534807f85bf2fa2b023d25fcc5
当我为此使用子资源“Microsoft.Web/sites/config”时,它会起作用。
在示例中,我添加了 2 个连接字符串 - 可以有任意多个,并且它们也可以很容易地作为参数或变量传递。
{
"name": "[variables('webSiteName')]",
"type": "Microsoft.Web/sites",
"apiVersion": "2021-03-01",
"location": "[resourceGroup().location]",
"properties": { /*your normal properties here */},
"resources": [
{
"name": "connectionstrings", //This name is REQUIRED to target the connection strings section
"type": "config",
"apiVersion": "2021-03-01",
"location": "[resourceGroup().location]",
"properties": {
"YourConnectionStringNameHere": {
"value": "your connection string here",
"type": "SQLAzure" //Pick any of the types listed in Azure. 'Custom' if you are unsure
},
"AnotherConnectionStringNameHere": {
"value": "another value here",
"type": "Custom"
}
},
"dependsOn": [
"[variables('webSiteName')]"
]
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.