如何参数化 azure logic app 标准项目的 workflow.json 和 connections.json 文件中的值

How to parameterize the values in workflow.json and connections.json files of azure logic app standard project

我按照 this 文档使用 visual studio 代码创建了 azure logic app 单租户项目。然后根据我的要求创建工作流,其中包含数据工厂管道和发送网格操作。

工作流包含创建管道 运行 数据工厂操作中的硬编码值。

"Create_a_pipeline_run": {
            "inputs": {
                "host": {
                    "connection": {
                        "referenceName": "azuredatafactory_5"
                    }
                },
                "method": "post",
                "path": "/subscriptions/@{encodeURIComponent('xxxxxxx-xxxx-xxxx-xxxx-xxxxxx')}/resourcegroups/@{encodeURIComponent('xxxxx')}/providers/Microsoft.DataFactory/factories/@{encodeURIComponent('xxxxxx')}/pipelines/@{encodeURIComponent('xxxxxxx')}/CreateRun",
                "queries": {
                    "x-ms-api-version": "2017-09-01-preview"
                }
            },
            "runAfter": {},
            "type": "ApiConnection"
        },

connections.json 文件如下所示:

"managedApiConnections": {
"sendgrid": {
  "api": {
    "id": "/subscriptions/@appsetting('WORKFLOWS_SUBSCRIPTION_ID')/providers/Microsoft.Web/locations/centralus/managedApis/sendgrid"
  },
  "authentication": {
    "type": "ManagedServiceIdentity"
  }
},
"azuredatafactory_5": {
  "api": {
    "id": "/subscriptions/@appsetting('WORKFLOWS_SUBSCRIPTION_ID')/providers/Microsoft.Web/locations/centralus/managedApis/azuredatafactory"
  },
  "authentication": {
    "type": "ManagedServiceIdentity"
  }
}

}

上述管理的 API 连接是指来自 azure 的现有 API 连接。但是我想为每个环境创建新的托管 API 连接(意味着根据环境参数化 connections.json 文件中的值)。

任何人都可以建议我如何为每个环境参数化 workflow.json 文件中的值以及如何为每个环境参数化 connections.json 文件中的值。

逻辑应用程序标准只是一种应用程序服务workflowApp。 您可以在此处大量使用应用程序设置。

  1. 逻辑应用参数。

    在您的 workflow.json 中,您可以使用这样的参数:

    "Create_a_pipeline_run": {
      "inputs": {
        "host": {
          "connection": {
            "referenceName": "azuredatafactory_5"
          }
       },
       "method": "post",
       "path": "/subscriptions/@{encodeURIComponent(parameters('subscription_id'))}/resourcegroups/...",
       "queries": {
         "x-ms-api-version": "2017-09-01-preview"
       }
     },
     "runAfter": {},
     "type": "ApiConnection"
    }
    

    然后在您的 parameters.json 文件中,参考这样的应用设置:

    {
      "subscription_id": {
        "type": "String",
        "value": "@appsetting('WORKFLOWS_SUBSCRIPTION_ID')"
      }
    }
    

    subscription_id 必须定义为应用服务中的应用设置。

  2. 逻辑应用连接。 同样,您可以在 connections.json 文件中使用应用设置和连接信息参数:

    {
      "managedApiConnections": {
        "sendgrid": {
          "api": {
            "id": "/subscriptions/@appsetting('WORKFLOWS_SUBSCRIPTION_ID')/providers/Microsoft.Web/locations/centralus/managedApis/sendgrid"
          },
          ...
          "authentication": "@parameters('azure_authentication')"
        }
      }
    }
    

    然后在您的 parameters.json 文件中:

    {
      "azure_authentication": {
        "type": "object",
        "value": {
          "type": "ManagedServiceIdentity"
        }
      }
      ...
    }
    

通过这种方式,您可以轻松地将所有环境特定参数卸载到应用设置