Azure LogicApp ARM Template

Generate ARM Templates for Azure Logic Apps with Connections Using PowerShell

Overview

Azure Logic Apps are a vital part of many cloud-based automations and workflows. However, exporting these Logic Apps—including their connections—for reuse or deployment in another environment can be a tedious manual process. This blog post introduces a PowerShell script designed to simplify that task by generating an ARM (Azure Resource Manager) template that includes both the Logic App and its required connections.

The script is particularly useful for DevOps engineers, cloud architects, and administrators who frequently manage Infrastructure as Code (IaC) or need to migrate Logic Apps across environments.

Script Synopsis

This PowerShell script allows users to:

  • Connect to an Azure tenant
  • Select subscriptions and Logic Apps interactively
  • Automatically generate ARM templates including:
    • The Logic App definition
    • All associated API connections
  • Output a clean and formatted ARM template JSON file
  • Optionally prepare the template for publishing to the Azure Sentinel Playbook Gallery

The script is authored by Sreedhar Ande and Itai Yankelevsky and is distributed under an open disclaimer (“AS IS” without warranty or liability).

Script

Key Features

  • 🔐 Secure Authentication using Connect-AzAccount
  • 🔎 Interactive GUI Selection for subscriptions and Logic Apps via Out-GridView
  • 🔁 Handles Both Managed and Custom API Connections
  • 🧩 Automatic Parameter Extraction for dynamic fields
  • 📦 Modular Design with helper functions like Get-RequiredModules, HandlePlaybookApiConnectionReference, and BuildArmTemplate
  • 🛠️ Built-in Logging with color-coded messages
  • 🧪 Environment Clean-Up with context disconnection before each new session
  • 📁 Export Templates in a structured folder format

Requirements

Before running the script, make sure:

  • You are using PowerShell version 5.0 or higher
  • You have Az PowerShell modules installed (specifically Az.Accounts, Az.Resources, and Az.OperationalInsights)
  • You have sufficient permissions in the Azure subscription and resource group

How to Use

  1. Open PowerShell as an Administrator.
  2. Save the script locally as GenerateARMTemplate_V2.ps1.
  3. Run the script using the command:
  1. Answer the prompts to:
    • Choose whether to generate a gallery-ready template
    • Decide on updating Az modules
    • Log in to Azure and select the appropriate subscription
    • Select Logic Apps to export
  2. Choose a folder to save the exported templates.
  3. The script will:
    • Fetch the Logic App and connections
    • Clean up the JSON definition
    • Export a formatted azuredeploy.json file per Logic App

Example Output Path

The script will create a sub-folder for each Logic App, such as:

This file is ready to be deployed using tools like Azure CLI, Azure Portal, or as part of a DevOps pipeline.


Notes and Best Practices

  • Version Control: Store generated templates in Git or Azure Repos for better CI/CD integration.
  • Security: Always review and sanitize connection strings and secrets before sharing or publishing templates.

Summary

If you’re working extensively with Azure Logic Apps, this script is a powerful tool to include in your automation toolkit. It not only saves time but also ensures your Logic Apps and their connections are properly preserved across environments or published in a compliant, structured way.

Whether you’re deploying internal workflows or creating public templates for the community, this script does the heavy lifting for you—efficiently and cleanly.

Leave a Comment

Your email address will not be published. Required fields are marked *