You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Pulumi Python中为Azure逻辑应用传递GitHub连接参数

解决Pulumi Python中Logic App GitHub连接参数不识别问题

核心问题原因

$connections是逻辑应用工作流层级的全局参数,不能定义在单个Action的body.parameters块中,你当前的写法把连接参数放到了单个Action的配置里,所以逻辑应用运行时无法读取到对应配置。

正确实现步骤

1. 先在逻辑应用工作流的定义中声明全局连接参数

创建azure.logicapps.Workflow资源时,通过parameters属性传入$connections配置,示例代码:

import pulumi
import pulumi_azure as azure

# 如果你还没有预先创建GitHub连接器,建议先通过代码创建,避免硬编码ID
github_connection = azure.web.Connection("github-connection",
    resource_group_name="bluecode_test_task",
    name="github",
    custom_api_id="/subscriptions/b417b96c-ff1e-4d07-bc32-74bd70a2a033/providers/Microsoft.Web/locations/eastus/managedApis/github",
    parameter_values={
        "token": "你的GitHub访问令牌" # 也可以用Pulumi secret存储敏感信息
    }
)

# 创建逻辑应用工作流时传入全局连接参数
example_workflow = azure.logicapps.Workflow("exampleWorkflow",
    resource_group_name="bluecode_test_task",
    location="eastus",
    # 全局参数声明
    parameters={
        "$connections": {
            "value": {
                "github": {
                    "connectionId": github_connection.id, # 直接引用上面创建的连接器ID,不用硬编码
                    "connectionName": "github",
                    "id": "/subscriptions/b417b96c-ff1e-4d07-bc32-74bd70a2a033/providers/Microsoft.Web/locations/eastus/managedApis/github"
                }
            }
        }
    },
    # 你的工作流定义、触发器配置等
    definition={
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {},
        "triggers": {}, # 这里补充你的触发器配置
        "actions": {},
        "outputs": {}
    }
)

2. 修改ActionCustom的body配置,删除重复的连接参数

单个Action中不需要重复定义$connections,直接引用工作流层面的全局参数即可,修改后的Action代码:

example_action_custom = azure.logicapps.ActionCustom("exampleActionCustom",
    logic_app_id=example_workflow.id,
    name= "Create_a_repository_using_a_template",
    body="""{
    "inputs": {
        "body": {
            "name": "cog-chalnge-pmi-shah-@{triggerBody()?['ghusername']}",
            "owner": "@triggerBody()?['ghusername']",
            "private": true    
        },
        "headers": {
            "Accept": "application/vnd.github.baptiste-preview+json"
        },
        "host": {
            "connection": {
                "name": "@parameters('$connections')['github']['connectionId']"
            }
        },
        "method": "post",
        "path": "/repos/@{encodeURIComponent('')}/@{encodeURIComponent('')}/generate"
    },
    "runAfter": {},
    "type": "ApiConnection"
}
""")

注意事项

  • 如果你是预先在Azure门户中创建的GitHub连接器,要确保连接器和逻辑应用在同一个租户下,且逻辑应用的托管身份有访问连接器的权限
  • 敏感信息比如GitHub令牌建议用pulumi.Secret存储,避免明文泄露

内容的提问来源于stack exchange,提问作者UDIT JOSHI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.10 20:27:02