如何使用 Terraform 向 Azure 逻辑应用程序添加多个自定义操作?

How to add several Custom Action to Azure Logic Apps with Terraform?

我想使用 Terraform 部署 Azure 逻辑应用程序。我需要添加 2-3 个自定义操作。我目前正在测试添加 2 个变量。

我希望所有操作都在 运行 中一个接一个地进行,但目前操作是并行部署的。我不知道哪个参数决定操作应该并行部署还是一个接一个地部署。

我复制并粘贴了以下代码:

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/logic_app_trigger_http_request
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/logic_app_action_custom

如何让动作一个接一个地部署?

地形代码:

# Define Terraform provider
terraform {
  required_version = ">= 0.12"
}
# Configure the Azure provider
provider "azurerm" { 
  environment = "public"
  version = ">= 2.0.0"
  features {}  
}

resource "azurerm_resource_group" "example" {
  name     = "my-logicapp-rg"
  location = "West Europe"
}

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


resource "azurerm_logic_app_trigger_http_request" "example" {
  name         = "some-http-trigger"
  logic_app_id = azurerm_logic_app_workflow.example.id

  schema = <<SCHEMA
{
    "type": "object",
    "properties": {
        "hello": {
            "type": "string"
        }
    }
}
SCHEMA

}

resource "azurerm_logic_app_action_custom" "example" {
  name         = "example-action"
  logic_app_id = azurerm_logic_app_workflow.example.id

  body = <<BODY
{
    "description": "A variable to configure the auto expiration age in days. Configured in negative number. Default is -30 (30 days old).",
    "inputs": {
        "variables": [
            {
                "name": "ExpirationAgeInDays",
                "type": "Integer",
                "value": -30
            }
        ]
    },
    "runAfter": {},
    "type": "InitializeVariable"
}
BODY

}

resource "azurerm_logic_app_action_custom" "example2" {
  name         = "example-action2"
  logic_app_id = azurerm_logic_app_workflow.example.id

  body = <<BODY
{
    "description": "A variable to configure the auto expiration age in days. Configured in negative number. Default is -30 (30 days old).",
    "inputs": {
        "variables": [
            {
                "name": "ExpirationAgeInDays2",
                "type": "Integer",
                "value": -30
            }
        ]
    },
    "runAfter": {},
    "type": "InitializeVariable"
}
BODY

}

为了让它成为一个流程而不是一个并行的动作。您需要在之前变量的“runAfter”:{} 中添加变量名称。

"runAfter": {
        "${azurerm_logic_app_action_custom.example.name}": [
                        "Succeeded"
                    ]
        }

"runAfter": {
        "example-action": [
                        "Succeeded"
                    ]
        }

完成更改后,我使用以下代码在我的环境中进行了测试:

# Define Terraform provider
terraform {
  required_version = ">= 0.12"
}
# Configure the Azure provider
provider "azurerm" { 
  environment = "public"
  version = ">= 2.0.0"
  features {}  
}

resource "azurerm_resource_group" "example" {
  name     = "my-logicapp-rg"
  location = "West Europe"
}

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


resource "azurerm_logic_app_trigger_http_request" "example" {
  name         = "some-http-trigger"
  logic_app_id = azurerm_logic_app_workflow.example.id

  schema = <
<SCHEMA
{
    "type": "object",
    "properties": {
        "hello": {
            "type": "string"
        }
    }
}
SCHEMA

}

resource "azurerm_logic_app_action_custom" "example" {
  name         = "example-action"
  logic_app_id = azurerm_logic_app_workflow.example.id

  body = <
    <BODY
{
    "description": "A variable to configure the auto expiration age in days. Configured in negative number. Default is -30 (30 days old).",
    "inputs": {
        "variables": [
            {
                "name": "ExpirationAgeInDays",
                "type": "Integer",
                "value": -30
            }
        ]
    },
    "runAfter": {},
    "type": "InitializeVariable"
}
BODY

}

resource "azurerm_logic_app_action_custom" "example2" {
  name         = "example-action2"
  logic_app_id = azurerm_logic_app_workflow.example.id

  body = <
        <BODY
{
    "description": "A variable to configure the auto expiration age in days. Configured in negative number. Default is -30 (30 days old).",
    "inputs": {
        "variables": [
            {
                "name": "ExpirationAgeInDays2",
                "type": "Integer",
                "value": -30
            }
        ]
    },
    "runAfter": {
        "${azurerm_logic_app_action_custom.example.name}": [
                        "Succeeded"
                    ]
        },
    "type": "InitializeVariable"
}
BODY

}

输出: