首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >通过Terraform和Azure的逻辑应用程序工作流

通过Terraform和Azure的逻辑应用程序工作流
EN

Stack Overflow用户
提问于 2022-01-18 14:55:24
回答 3查看 4.9K关注 0票数 0

我们有Terraform来创建和部署Logic。

我们还在Logic中创建了工作流。

我们希望实现逻辑应用程序的创建和内部工作流的自动化。

例如,请参见下面的工作流:

https://learn.microsoft.com/en-us/azure/logic-apps/tutorial-build-schedule-recurring-logic-app-workflow

EN

回答 3

Stack Overflow用户

发布于 2022-01-24 11:27:28

在部署逻辑应用程序工作流( bingsmap work )时,terraform有一个限制,不能创建工作流中所需的api连接,只能通过arm模板或从门户手动部署,然后需要在工作流中手动配置,如: connection和E 212 outlook E 116connectionE 217

如果您是,开始从terraform部署逻辑应用程序,那么快速修复将在手动创建工作流之后引用工作流的ARM模板,然后转到逻辑应用程序代码视图,以获得如何用terraform编写自定义操作的想法。

您可以从terraform部署逻辑应用程序,然后使用逻辑应用程序代码视图中的代码使用https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group_template_deployment从terraform部署。

参考资料:

https://stackoverflow.com/questions/68892355/unable-to-connect-the-api-connection-to-the-logic-app-via-arm-template-in-terraf

***Example provide by AZApril on how to use terraform to deploy logic app and then workflow using template deployment***

用于部署逻辑应用程序和工作流,您可以使用terraform中的以下内容:

代码语言:javascript
运行
复制
provider "azurerm" {
  features{}
}

data "azurerm_resource_group" "example" {
  name="ansumantest"
}

resource "azurerm_logic_app_workflow" "example" {
  name                = "workflow1"
  location           = data.azurerm_resource_group.example.location
  resource_group_name = data.azurerm_resource_group.example.name
}

resource "azurerm_resource_group_template_deployment" "apiconnections" {
  name                = "group-deploy"
  resource_group_name = data.azurerm_resource_group.example.name
  deployment_mode     = "Incremental"
  template_content = <<TEMPLATE
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "connections_bingmaps_name": {
            "defaultValue": "bingmaps",
            "type": "string"
        },
        "connections_office365_name": {
            "defaultValue": "office365",
            "type": "string"
        }
    },
    "variables": {},
    "resources": [
        {
    "type": "Microsoft.Web/connections",
    "apiVersion": "2016-06-01",
    "name": "[parameters('connections_bingmaps_name')]",
    "location": "eastus",
    "kind": "V1",
    "properties": {
        "displayName": "BingMapsConnection",
        "statuses": [
            {
                "status": "Connected"
            }
        ],
        "customParameterValues": {},
        "nonSecretParameterValues": {},
        "createdTime": "2022-01-24T08:26:56.8147674Z",
        "changedTime": "2022-01-24T08:28:05.4634315Z",
        "api": {
            "name": "[parameters('connections_bingmaps_name')]",
            "displayName": "Bing Maps",
            "description": "Bing Maps",
            "iconUri": "[concat('https://connectoricons-prod.azureedge.net/releases/v1.0.1538/1.0.1538.2619/', parameters('connections_bingmaps_name'), '/icon.png')]",
            "brandColor": "#008372",
            "id": "[concat('/subscriptions/<subscriptionId>/providers/Microsoft.Web/locations/eastus/managedApis/', parameters('connections_bingmaps_name'))]",
            "type": "Microsoft.Web/locations/managedApis"
        },
        "testLinks": []
    }
},
{
    "type": "Microsoft.Web/connections",
    "apiVersion": "2016-06-01",
    "name": "[parameters('connections_office365_name')]",
    "location": "eastus",
    "kind": "V1",
    "properties": {
        "displayName": "<emailid>",
        "statuses": [
            {
                "status": "Connected"
            }
        ],
        "customParameterValues": {},
        "nonSecretParameterValues": {},
        "createdTime": "2022-01-24T08:33:55.8159813Z",
        "changedTime": "2022-01-24T08:35:04.9083183Z",
        "api": {
            "name": "[parameters('connections_office365_name')]",
            "displayName": "Office 365 Outlook",
            "description": "Microsoft Office 365 is a cloud-based service that is designed to help meet your organization's needs for robust security, reliability, and user productivity.",
            "iconUri": "[concat('https://connectoricons-prod.azureedge.net/releases/v1.0.1538/1.0.1538.2621/', parameters('connections_office365_name'), '/icon.png')]",
            "brandColor": "#0078D4",
            "id": "[concat('/subscriptions/<subscriptionId>/providers/Microsoft.Web/locations/eastus/managedApis/', parameters('connections_office365_name'))]",
            "type": "Microsoft.Web/locations/managedApis"
        },
        "testLinks": [
            {
                "requestUri": "[concat('https://management.azure.com:443/subscriptions/<subscriptionId>/resourceGroups/ansumantest/providers/Microsoft.Web/connections/', parameters('connections_office365_name'), '/extensions/proxy/testconnection?api-version=2016-06-01')]",
                "method": "get"
            }
        ]
    }
}
    ],
    "outputs": {
        "bingmapid":{
            "type": "string",
            "value" : "[resourceId('Microsoft.Web/connections', parameters('connections_bingmaps_name'))]"
        } ,
        "officeid": {
            "type": "string",
            "value": "[resourceId('Microsoft.Web/connections', parameters('connections_office365_name'))]"
        }
    }
}
TEMPLATE
depends_on = [
  azurerm_logic_app_workflow.example
]
}
locals {
  bingmapconnectionid = jsondecode(azurerm_resource_group_template_deployment.apiconnections.output_content).bingmapid.value
  office365connectionid = jsondecode(azurerm_resource_group_template_deployment.apiconnections.output_content).officeid.value
}
resource "azurerm_logic_app_trigger_recurrence" "trigger" {
  name         = "Recurrence"
  logic_app_id = azurerm_logic_app_workflow.example.id
  frequency    = "Week"
  interval     = 1
  schedule {
    at_these_minutes=[0,15,30,45]
    at_these_hours =["8","9","7"]
    on_these_days=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
  }
  depends_on = [
    azurerm_resource_group_template_deployment.apiconnections
  ]
}

resource "azurerm_logic_app_action_custom" "action1" {
  name         = "Get_route_and_travel_time_with_traffic"
  logic_app_id = azurerm_logic_app_workflow.example.id

  body = <<BODY
{
                            "runAfter": {},
                            "type": "ApiConnection",
                            "inputs": {
                                "host": {
                                    "connection": {
                                        "name": "${local.bingmapconnectionid}"
                                    }
                                },
                                "method": "get",
                                "path": "/V3/REST/V1/Routes/@{encodeURIComponent('Driving')}",
                                "queries": {
                                    "distanceUnit": "Mile",
                                    "optimize": "timeWithTraffic",
                                    "wp.0": "21930 SE 51st ,Issaugh,WA,98029",
                                    "wp.1": "3003 160th Ave,Bellevue,WA,98029"
                                }
                            }
                        }
BODY
depends_on = [
  azurerm_logic_app_trigger_recurrence.trigger
]
}
resource "azurerm_logic_app_action_custom" "action2" {
  name         = "Create_variable_to_store_travel_time"
  logic_app_id = azurerm_logic_app_workflow.example.id

  body = <<BODY
                       {
                "inputs": {
                    "variables": [
                        {
                            "name": "travelTime",
                            "type": "integer",
                            "value": "@div(body('Get_route_and_travel_time_with_traffic')?['travelDurationTraffic'],60)"
                        }
                    ]
                },
                "runAfter": {
                    "Get_route_and_travel_time_with_traffic": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            }
BODY
depends_on = [
  azurerm_logic_app_action_custom.action1
]
}
resource "azurerm_logic_app_action_custom" "condition" {
  name         = "If_travel_time_exceeds_limit"
  logic_app_id = azurerm_logic_app_workflow.example.id

  body = <<BODY
{
                            "actions": {
                                "Send_email_with_travel_time": {
                                    "runAfter": {},
                                    "type": "ApiConnection",
                                    "inputs": {
                                        "body": {
                                            "Body": "<p>Add extra travel time (minutes): @{sub(variables('travelTime'),15)}</p>",
                                            "Subject": "Current travel time (minutes): @{variables('travelTime')}",
                                            "To": "admin@xxxxxxxxxx.onmicrosoft.com"
                                        },
                                        "host": {
                                            "connection": {
                                                "name": "${local.office365connectionid}"
                                            }
                                        },
                                        "method": "post",
                                        "path": "/v2/Mail"
                                    }
                                }
                            },
                            "runAfter": {
                                "Create_variable_to_store_travel_time": [
                                    "Succeeded"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "greater": [
                                            "@variables('travelTime')",
                                            15
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
BODY
depends_on = [
  azurerm_logic_app_action_custom.action2
]
}

输出:

每件事情都会被部署,但是api连接会在逻辑应用程序中出现错误,而不是,所以您必须手动地或者通过我在另一个so线程中提到的解决方案来配置它。

票数 3
EN

Stack Overflow用户

发布于 2022-02-16 12:25:52

你应该看看逻辑应用程序(标准)。它们提供了更好的开发/部署经验。您可以创建使用terraform的逻辑应用程序标准运行库并使用Azure CI/CD管道部署工作流。

然而,在逻辑应用程序(标准)中,只有三层定价:WS1、WS2和WS3。即使您的实例处于空闲状态,也始终需要支付费用。逻辑应用程序(标准)将托管在应用程序服务中。好处是:您的工作流代码可以在git中进行源代码控制,并且您可以使用在VSCode中本地开发/调试

所以可以归结为这样的比较:

逻辑应用程序消费

优点

  • 你只为你使用的东西付费(消费定价模型)
  • 在本地VSCode中开发,但没有调试(imho) - VSCode只连接到Azure

缺点

  • 工作流的自动化部署目前非常困难(请参阅上面复杂的terraform脚本)
  • 不提供源代码管理。
  • 您的工作流定义只存在于Azure中。
  • 无CI/CD

逻辑应用程序(标准)

优点

  • 通过CI/CD管道进行部署是可能的
  • 通过git对工作流和连接进行源代码管理
  • VSCode集成(使用可移植的工作流运行时在本地开发和调试)
  • 可以参数化(也可以使用应用程序设置)

缺点

  • 您必须运行一个完整的AppService来托管
  • 最便宜的定价模式是WS1,每月价格约130美元。

目前,我们决定运行标准模型,因为任何东西都可以用CI/CD自动控制。然而,我们只运行少量的工作流,而且成本很高。我们最好选择消费方式。

票数 2
EN

Stack Overflow用户

发布于 2022-06-21 07:54:21

在以上答案的基础上,您现在可以使用

然后,可以在工作流参数或自定义操作主体下的连接中使用连接

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70757669

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档