简体   繁体   English

我们如何在 function 应用程序的 ARM 模板中包含连接字符串?

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

How do we add connection strings in the ARM template to this section:我们如何将 ARM 模板中的连接字符串添加到此部分: 在此处输入图像描述

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?我们如何在 ARM 模板中添加连接字符串?

Setting the connection string as Microsoft.Web/sites is the solution I use:将连接字符串设置为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"
                }
            ]
        }
    }
}

Edit:编辑:

Here is a working bicep example that sets the connection string: https://gist.github.com/mjisaak/e7ddb416f86027658a3fa3d24feb3e0b这是一个设置连接字符串的工作二头肌示例: https://gist.github.com/mjisaak/e7ddb416f86027658a3fa3d24feb3e0b

And here the corresponding ARM template: https://gist.github.com/mjisaak/76fa5a534807f85bf2fa2b023d25fcc5这里对应的ARM模板: https://gist.github.com/mjisaak/76fa5a534807f85bf2fa2b023d25fcc5

It works when I use the subresource "Microsoft.Web/sites/config" for that.当我为此使用子资源“Microsoft.Web/sites/config”时,它会起作用。

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.在示例中,我添加了 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.

相关问题 如何在 arm 模板中使用条件或? - How to use conditional OR in arm template? 如何在我的 ARM (JSON) 模板中的 Azure 漏洞评估基线定义中指定多行? - How do I specify multiple rows in an Azure Vulnerability Assessment baseline definition in my ARM (JSON) template? 通过 ARM 模板安装时,琐碎的 Azure 逻辑应用程序失败 - Trivial Azure Logic App fails when installed via ARM template 如何在 ARM 二头肌模板中添加条件? - How to add condition in ARM Bicep template? 我们是否需要为我们的 Azure Function 应用程序设置做额外的安全性(存储在 Key Vault 中) - Do we need to do extra security (storing inside Key Vault) for our Azure Function App Settings 如何包含带有 lambda function 的图像 (jpg)? - How do I include an image (jpg) with a lambda function? 使用 ARM 模板创建 Azure Function 密钥失败 - Creating Azure Function Key using ARM template fails 怎么做? 一旦我们使用 google fire base 登录 flutter 应用程序,那么当我们再次打开该应用程序时就不必再次登录 - how to do ? once we sign in in the flutter application using google fire base then we do not have to sign in again whene we again open the app Azure模板 我们如何根据资源组位置更改资源名称? - Azure template how do we change the resource name based on resource group location? ARM 模版认知服务 - ARM Template Coginitive services
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM