Parameterizing a Logic App

Parameterizing a Logic App can be a tedious exercise. This is why Jeff Hollan created the LogicApp Template Creator. First you will have to download the zip file from GitHub. Next you will have to extract it to a folder of your choice. For example: D:\LogicAppTemplateCreator\

The Logic App Template creator assumes you have deployed the Logic App to be parameterized to Azure. In this case I created a Logic App in Visual Studio. So, I had a project with a .json and .parameters.json file. Next I added two Powershell scripts to the project:
GetLogicAppArm.ps1 and GetLogicAppsByRG.ps1.

You can open PowerShell ISE and open file GetLogicAppArm.ps1:

#Set the resource group 
$resourcegroupname = 'test-rg'
#Set the subscription id 
$subscriptionid = 'from Azure Portal, subscription'
#Set the tenant to use when login ing, make sure it has the right tennant
$tenant = '[klant]'

#setting the output filename
$ScriptItem = Get-Item -Path $MyInvocation.MyCommand.Path

cd "$($ScriptItem.DirectoryName)"

.\GetLogicAppsByRG.ps1 -subscriptionId $subscriptionid -tenantname $tenant -resourcegroup $resourcegroupname -destination $($ScriptItem.DirectoryName)

In this case GetLogicAppsByRG.ps1 is in the same folder as GetLogicAppArm.ps1. If script GetLogicAppsByRG.ps1 is in the root folder, you will first have to change the directory to the correct folder, like:

cd "$($ScriptItem.DirectoryName)\..\..\"

After running the script, I received an error in GetLogicAppsByRG.ps1 saying that cmdlet ARMClient could not be found. Via the following link from David Ebbo, I learned you will have to install the ARMClient first. To do this you will have to install Chocolatey. When done, open a command prompt as an administrator and run code: choco install armclient

Now the ARMClient is installed. Next I received another error on FixedFunctionAppName in the following statement:

armclient token $subscriptionID | Get-LogicAppTemplate -LogicApp $_.Name -ResourceGroup $resourcegroup -TenantName $tenantname -DiagnosticSettings $true -SubscriptionId $subscriptionID -Verbose -FixedFunctionAppName $fixedFunctionAppName | Out-File $destinationfile

I simply removed the FixedFunctionAppName and it worked. Below is the full GetLogicAppsByRG script (note this is a reusable script):

param([string] $subscriptionID, [string] $tenantname, [string] $resourcegroup, [string] $destination, [bool] $fixedFunctionAppName)

$module = resolve-path "D:\LogicAppTemplateCreator\LogicAppTemplate\bin\Debug\LogicAppTemplate.dll"
Import-Module $module

# Import the Logic Apps Template Module #
#Install-Module -Name LogicAppTemplate

# Create required folders #
md -Force $destination | Out-Null

Write-Host "Get LogicApps for ResourceGroup: $resourcegroup"

# Gets a list of logic app
(([string] (armclient get "$subscriptionID/resourceGroups/$resourcegroup/providers/Microsoft.Logic/workflows/?api-version=2018-07-01-preview")) | ConvertFrom-Json).value | ForEach-Object{

Write-Host $("Creating {0} Logic App Template" -f $_.Name)

# Define the destination folder #
$logicappfolder = [IO.Path]::GetFullPath((Join-Path $destination $_.Name))
md $logicappfolder -Force | Out-Null

# Define the destination file names #
$destinationfile = $(Join-path $logicappfolder ($_.Name + ".json"))
$destinationparmfile = $(Join-path $logicappfolder ($_.Name + ".parameters.json"))
Write-Host "destinationfile: $destinationfile"

armclient token $subscriptionID | Get-LogicAppTemplate -LogicApp $_.Name -ResourceGroup $resourcegroup -TenantName $tenantname -DiagnosticSettings $true -SubscriptionId $subscriptionID -Verbose | Out-File $destinationfile
# Generate the Parameter File #
Get-ParameterTemplate -TemplateFile $destinationfile | Out-File $destinationparmfile -Force

# Initialize Azure Deploy nested Templates variable #
$azuredeploytemplate = ""

Write-Host "Creating AzureDeploy ARM Template"

# Gets a list of resources to add to the nested template #
Get-ChildItem $destination -Directory -Exclude *obj*, *bin*  | ForEach-object {

# Adds the resource to the nested templates #
$azuredeploytemplate = Get-NestedResourceTemplate -ResourceName $_.Name -Template $azuredeploytemplate}

#Save nested template to destination #
$azuredeploytemplate | Out-File $(Join-path $destination "azuredeploy.json") -Force

Write-Host "Creating AzureDeploy ARM Parameter Template"

#Generate an empty Azure Deploy Parameter

Get-EmptyParameterTemplate | Out-File $(Join-path $destination "azuredeploy.parameters.json") -Force