首页 > 解决方案 > ARM 模板无法设置 $connections

问题描述

我在 Visual Studio 项目中创建了一个与 slack 连接的 ARM 模板。当我连接到 Azure 门户中的 slack 时 - 一切都很好。我的 slack API 连接已获得授权并且可以正常工作。我的问题是部署和设置$connections

这是我的模板

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    <template-params>
  },
  "variables": {
    "slack": "[concat(parameters('appPrefix'), '-slack-', parameters('environment'))]"
  },
  "resources": [
    {
      "type": "Microsoft.Web/connections",
      "apiVersion": "2016-06-01",
      "location": "[resourceGroup().location]",
      "name": "[variables('slack')]",
      "properties": {
        "api": {
          "id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/slack')]"
        },
        "displayName": "Slack",
        "parameterValues": {}
      }
    },
    {
      "name": "[parameters('logicAppName')]",
      "type": "Microsoft.Logic/workflows",
      "location": "[parameters('logicAppLocation')]",
      "tags": {
        "displayName": "LogicApp"
      },
      "apiVersion": "2016-06-01",
      "properties": {
        "definition": {
          "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
          "actions": {
            "Collecting_went_wrong": {
              "inputs": {
                "host": {
                  "connection": {
                    "name": "@parameters('$connections')['slack']['connectionId']"
                  }
                },
                "method": "post",
                "path": "/chat.postMessage",
                "queries": {
                  "channel": "<channel>",
                  "text": "<message>",
                  "username": "<user>"
                }
              },
              "runAfter": {},
              "type": "ApiConnection"
            }
          },
          "parameters": {
            "$connections": {
              "type": "object",
              "defaultValue": {
              }
            }
          },
          "triggers": {
           <trigger>
          }
        },
        "parameters": {
          "$connections": {
            "value": {
              "slack": {
                "id": "[resourceId('Microsoft.Web/connections', variables('slack'))]",
                "connectionId": "[resourceId('Microsoft.Web/connections', variables('slack'))]",
                "connectionName": "slack"
              }
            }
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/connections', variables('slack'))]"
      ]
    }
  ],
  "outputs": {}
}

“有趣”的部分是在部署期间验证模板:

New-AzureRmResourceGroupDeployment : 17:08:51 - Resource Microsoft.Logic/workflows 'reporting-reminder-logic-app-dev' 
failed with message '{
  "error": {
    "code": "ConnectionsParameterInvalid",
    "message": "The provided API connection parameter 'slack' is missing the required property 'id'."
  }
}'

我在这里真的很困惑。

我尝试将其部署为connection并添加$connection参数定义,部署通过了。然而,当我更改connection$connectionsin 模板参数时,Azure 门户向我抛出了同样的验证错误。

知道我在这里做错了什么吗?

谢谢

标签: validationconnectionazure-logic-appsarm-template

解决方案


问题在于资源中的不同 ID -> Microsoft/Web.connections -> 属性 -> id 和 slack -> 连接。一旦此连接 ID 相同,验证通过。

所以它只是令人困惑的验证消息。


推荐阅读