Search code examples
terraformazure-logic-appsazure-logic-app-standard

Is there a terraform block that create multiple workflows in a single logic App in Azure


below configuration creates 2 logic Apps, but I am trying to create 2 workflows in the same logic App:

resource "azurerm_resource_group" "example" {
 name     = "workflow-resources"
 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_workflow" "example" {
 name                = "workflow2"
 location            = azurerm_resource_group.example.location
 resource_group_name = azurerm_resource_group.example.name
}

I tried creating a standard logic App but couldn't find an option to create workflows within that logic App.


Solution

  • I found one workaround for your requirement. That is create an ARM template and pass it in the terraform code using template_deployment resource and deploy the ARM template to configure the workflow for logic app with terraform as detailed in this SO.

    data "azurerm_resource_group" "example" {
     name     = "Jahnavi"
    }
    data "azurerm_logic_app_standard" "example" {
      name                = "stlog"
      resource_group_name = "Jahnavi"
    }
    resource "azurerm_logic_app_workflow" "example" {
     name     = "logicappflow"
     location            = data.azurerm_resource_group.example.location
     resource_group_name = data.azurerm_resource_group.example.name
    }
    
    data "template_file" "workflow" {
      template = file(local.<workflow_schema_filepath>)
    }
    resource "azurerm_template_deployment" "example" {
      name                = "acctesttemplate-01"
      resource_group_name = data.azurerm_resource_group.main.name
      parameters = merge({
        "workflowName" = var.workflow,
        "location"     = "westeurope"
      }, var.parameters)
      dependsOn = [
      data.azurerm_logic_app_standard.main.name
      ]
    
      template_body =  data.template_file.workflow.template
    }
    

    Refer document for more information related to the above issue.

    And if you want to create multiple workflows using consumption plan then you can follow the below steps and it worked for me as expected.

    variable "workflows" {
      type = map(string)
      default = [ "workflow1", "workflow2"]
    }
    
    resource "azurerm_resource_group" "example" {
         name     = "workflow-resources"
         location = "West Europe"
    }
    
    resource "azurerm_logic_app_workflow" "example" {
         for_each = toset(var.workflows)
         name     = logic_${each.value}
         location            = azurerm_resource_group.example.location
         resource_group_name = azurerm_resource_group.example.name
    }
    

    Output:

    enter image description here

    enter image description here

    enter image description here

    enter image description here