简体   繁体   中英

how do we include connectionstrings in ARM template for function app?

How do we add connection strings in the ARM template to this section: 在此处输入图像描述

Here's what I have tried, though it did not add anything to the Connection Strings section in the portal:

"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"
    }
  ]

I'm using this definition.

How do we add connection strings in the ARM template?

Setting the connection string as Microsoft.Web/sites is the solution I use:

{
    "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"
                }
            ]
        }
    }
}

Edit:

Here is a working bicep example that sets the connection string: https://gist.github.com/mjisaak/e7ddb416f86027658a3fa3d24feb3e0b

And here the corresponding ARM template: https://gist.github.com/mjisaak/76fa5a534807f85bf2fa2b023d25fcc5

It works when I use the subresource "Microsoft.Web/sites/config" for that.

In the example I added 2 connection strings - there can be as many as you want, and they can easily be passed as a parameter or variable as well.

{
    "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')]"
            ]
        }
    ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM