API连接-ARM模板中的用户名和密码

时间:2019-04-30 15:19:59

标签: azure api azure-resource-manager arm-template

我想在ARM模板中提供用户名和密码,以便在Azure模板中进行部署和填充,并可以在Azure门户的“编辑API连接”下看到。

enter image description here

这是ARM模板的一部分:

"resources": [
    {
      "type": "Microsoft.Web/connections",
      "apiVersion": "2016-06-01",
      "name": "[parameters('connections_sql_name')]",
      "location": "westeurope",
      "properties": {
        "displayName": "Test Connection Name",
        "parameterValues": {
          "server": "[parameters('sql_server')]",
          "database": "[parameters('sql_database')]",
          "authType": "[parameters('sql_authType')]",
          "userName": "[parameters('username')",
          "password": "[parameters('password')]"
        },
        "customParameterValues": {},
        "api": {
          "id": "[concat('/subscriptions/', subscription().subscriptionID, '/providers/Microsoft.Web/locations/westeurope/managedApis/sql')]"
        }
      }
    }

已填充服务器,数据库和AuthType,但无法在部署中填充userName和password参数。

1 个答案:

答案 0 :(得分:1)

“编辑API连接”页面将不会显示UsernamePassword,因为它们的类型为securestring

参考:https://docs.microsoft.com/en-us/connectors/sql/#creating-a-connection enter image description here

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "connections_sql_name": {
      "type": "string",
      "defaultValue": "connections_sql_name"
    },
    "sql_server": {
      "type": "string",
      "defaultValue": "server201-dev-sql.database.windows.net"
    },
    "sql_database": {
      "type": "string",
      "defaultValue": "Incidents"
    },
    "sql_authType": {
      "type": "string",
      "defaultValue": "Windows"
    },
    "username": {
      "type": "securestring",
    },
    "password": {
      "type": "securestring"
    }
  },
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.Web/connections",
      "apiVersion": "2016-06-01",
      "name": "[parameters('connections_sql_name')]",
      "location": "westeurope",
      "properties": {
        "displayName": "Test Connection Name",
        "parameterValues": {
          "server": "[parameters('sql_server')]",
          "database": "[parameters('sql_database')]",
          "authType": "[parameters('sql_authType')]",
          "userName": "[parameters('username')]",
          "password": "[parameters('password')]"
        },
        "customParameterValues": {},
        "api": {
          "id": "[concat('/subscriptions/', subscription().subscriptionID, '/providers/Microsoft.Web/locations/westeurope/managedApis/sql')]"
        }
      }
    }
  ]
}