Kenny_I
Kenny_I

Reputation: 2503

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

I would like to deploy Azure Logic App with Terraform. I would need to add 2-3 custom action. I'm currently testing to add 2 variables.

I would like to all action to be in run one after another, but currently actions get deployed parallel. I don't know which parameter decided if actions should deployed parallel or one after another.

I have copied and pasted Code from followings:

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

How to make actions deployed one after another?

enter image description here Terraform Code:

# 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

}

Upvotes: 2

Views: 2103

Answers (1)

SwethaKandikonda
SwethaKandikonda

Reputation: 8234

In order to make it as a flow and not as a parallel action. You need to add the variable name in "runAfter":{} of your previous variable.

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

or

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

After doing the changes I tested in my environment with the below code:

# 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

}

outputs: enter image description here enter image description here

Upvotes: 5

Related Questions