簡體   English   中英

我們如何在 function 應用程序的 ARM 模板中包含連接字符串?

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

我們如何將 ARM 模板中的連接字符串添加到此部分: 在此處輸入圖像描述

這是我嘗試過的方法,盡管它沒有向門戶中的“連接字符串”部分添加任何內容:

"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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM