Skip to content

Commit

Permalink
feat: Support Logic App Standard (#415)
Browse files Browse the repository at this point in the history
Co-authored-by: Stijn Moreels <9039753+stijnmoreels@users.noreply.github.com>
Co-authored-by: Pim Simons <pim.simons@codit.eu>
  • Loading branch information
3 people committed Nov 21, 2023
1 parent 9da6ae5 commit 4624a4e
Show file tree
Hide file tree
Showing 31 changed files with 1,413 additions and 249 deletions.

Large diffs are not rendered by default.

354 changes: 354 additions & 0 deletions docs/preview/03-Features/powershell/azure-logic-apps-standard.md

Large diffs are not rendered by default.

Binary file modified src/Arcus.Scripting.LogicApps/Arcus.Scripting.LogicApps.psd1
Binary file not shown.
44 changes: 34 additions & 10 deletions src/Arcus.Scripting.LogicApps/Arcus.Scripting.LogicApps.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@
.Parameter LogicAppName
The name of the Azure Logic App.
.Parameter WorkflowName
[Optional] The name of the workflow in the Azure Logic App Standard Site.
.Parameter EnvironmentName
[Optional] The Azure Cloud environment in which the Azure Logic App resides.
.Parameter MaximumFollowNextPageLink
The number of times the script should retrieve the next page of Logic App runs, if not specified the entire run history of the Logic App will be retrieved.
[Optional] The number of times the script should retrieve the next page of Logic App runs, if not specified the entire run history of the Logic App will be retrieved.
#>
function Cancel-AzLogicAppRuns {
param(
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of the resource group is required"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required"),
[Parameter(Mandatory = $false)][string] $WorkflowName = "",
[Parameter(Mandatory = $false)][string] $EnvironmentName = "AzureCloud",
[Parameter(Mandatory = $false)][int] $MaximumFollowNextPageLink = 10
)

. $PSScriptRoot\Scripts\Cancel-AzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -MaximumFollowNextPageLink $MaximumFollowNextPageLink
. $PSScriptRoot\Scripts\Cancel-AzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -WorkflowName $WorkflowName -EnvironmentName $EnvironmentName -MaximumFollowNextPageLink $MaximumFollowNextPageLink
}

Export-ModuleMember -Function Cancel-AzLogicAppRuns
Expand All @@ -40,29 +48,37 @@ Export-ModuleMember -Function Cancel-AzLogicAppRuns
.Parameter LogicAppName
The name of the Azure Logic App.
.Parameter WorkflowName
[Optional] The name of the workflow in the Azure Logic App Standard Site.
.Parameter EnvironmentName
[Optional] The Azure Cloud environment in which the Azure Logic App resides.
.Parameter StartTime
The start time of the failed instances of the Azure Logic App.
.Parameter EndTime
The end time of the failed instances of the Azure Logic App.
[Optional] The end time of the failed instances of the Azure Logic App.
.Parameter MaximumFollowNextPageLink
The number of times the script should retrieve the next page of Logic App runs, if not specified the entire run history of the Logic App will be retrieved.
[Optional] The number of times the script should retrieve the next page of Logic App runs, if not specified the entire run history of the Logic App will be retrieved.
#>
function Resubmit-FailedAzLogicAppRuns {
param(
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of the resource group is required"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required"),
[Parameter(Mandatory = $false)][string] $WorkflowName = "",
[Parameter(Mandatory = $true)][datetime] $StartTime = $(throw "Start time is required"),
[Parameter(Mandatory = $false)][datetime] $EndTime,
[Parameter(Mandatory = $false)][string] $EnvironmentName = "AzureCloud",
[Parameter(Mandatory = $false)][int] $MaximumFollowNextPageLink = 10
)

if ($EndTime) {
. $PSScriptRoot\Scripts\Resubmit-FailedAzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -StartTime $StartTime -EndTime $EndTime -MaximumFollowNextPageLink $MaximumFollowNextPageLink
. $PSScriptRoot\Scripts\Resubmit-FailedAzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -WorkflowName $WorkflowName -EnvironmentName $EnvironmentName -StartTime $StartTime -EndTime $EndTime -MaximumFollowNextPageLink $MaximumFollowNextPageLink
} else {
. $PSScriptRoot\Scripts\Resubmit-FailedAzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -StartTime $StartTime -MaximumFollowNextPageLink $MaximumFollowNextPageLink
. $PSScriptRoot\Scripts\Resubmit-FailedAzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -WorkflowName $WorkflowName -EnvironmentName $EnvironmentName -StartTime $StartTime -MaximumFollowNextPageLink $MaximumFollowNextPageLink
}
}

Expand All @@ -86,6 +102,9 @@ Export-ModuleMember -Function Resubmit-FailedAzLogicAppRuns
.Parameter LogicAppName
The name of the Azure Logic App to be enabled.
.Parameter WorkflowName
[Optional] The name of the workflow in the Azure Logic App Standard Site.
.Parameter ApiVersion
[Optional] The version of the api to be used to disable the Azure Logic App.
Expand All @@ -100,11 +119,12 @@ function Disable-AzLogicApp {
[Parameter(Mandatory = $false)][string] $SubscriptionId = "",
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of the resource group is required"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required"),
[Parameter(Mandatory = $false)][string] $WorkflowName = "",
[Parameter(Mandatory = $false)][string] $ApiVersion = "2016-06-01",
[Parameter(Mandatory = $false)][string] $AccessToken = ""
)

. $PSScriptRoot\Scripts\Disable-AzLogicApp.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -ApiVersion $ApiVersion -AccessToken $AccessToken
. $PSScriptRoot\Scripts\Disable-AzLogicApp.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -WorkflowName $WorkflowName -ApiVersion $ApiVersion -AccessToken $AccessToken
}

Export-ModuleMember -Function Disable-AzLogicApp
Expand All @@ -123,7 +143,7 @@ Export-ModuleMember -Function Disable-AzLogicApp
If your solution consists of multiple interfaces, you can specify the flow-specific name of the configuration file, if not, the script will look for a file named 'deploy-orderControl.json' by default.
.Parameter ResourcePrefix
The prefix assigned to all Azure Logic Apps, which can differ per environment.
[Optional] The prefix assigned to all Azure Logic Apps, which can differ per environment.
.Parameter EnvironmentName
[Optional] The Azure Cloud environment in which the Azure Logic App resides.
Expand Down Expand Up @@ -163,6 +183,9 @@ Export-ModuleMember -Function Disable-AzLogicAppsFromConfig
.Parameter LogicAppName
The name of the Azure Logic App to be enabled.
.Parameter WorkflowName
[Optional] The name of the workflow in the Azure Logic App Standard Site.
.Parameter ApiVersion
[Optional] The version of the api to be used to enable the Azure Logic App.
Expand All @@ -178,11 +201,12 @@ function Enable-AzLogicApp {
[Parameter(Mandatory = $false)][string] $SubscriptionId = "",
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of resource group is reqiured"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of logic app is required"),
[Parameter(Mandatory = $false)][string] $WorkflowName = "",
[Parameter(Mandatory = $false)][string] $ApiVersion = "2016-06-01",
[Parameter(Mandatory = $false)][string] $AccessToken = ""
)

. $PSScriptRoot\Scripts\Enable-AzLogicApp.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -ApiVersion $ApiVersion -AccessToken $AccessToken
. $PSScriptRoot\Scripts\Enable-AzLogicApp.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -WorkflowName $WorkflowName -ApiVersion $ApiVersion -AccessToken $AccessToken
}

Export-ModuleMember -Function Enable-AzLogicApp
Expand All @@ -201,7 +225,7 @@ Export-ModuleMember -Function Enable-AzLogicApp
If your solution consists of multiple interfaces, you can specify the flow-specific name of the configuration file, if not, the script will look for a file named 'deploy-orderControl.json' by default.
.Parameter ResourcePrefix
The prefix assigned to all Azure Logic Apps, which can differ per environment.
[Optional] The prefix assigned to all Azure Logic Apps, which can differ per environment.
.Parameter EnvironmentName
[Optional] The Azure Cloud environment in which the Azure Logic App resides.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
<ItemGroup>
<Compile Include="Arcus.Scripting.LogicApps.psd1" />
<Compile Include="Arcus.Scripting.LogicApps.psm1" />
<Compile Include="Scripts\Get-AzLogicAppStandardResourceManagementUrl.ps1" />
<Compile Include="Scripts\Resubmit-FailedAzLogicAppRuns.ps1" />
<Compile Include="Scripts\Cancel-AzLogicAppRuns.ps1" />
<Compile Include="Scripts\Disable-AzLogicApp.ps1" />
<Compile Include="Scripts\Disable-AzLogicAppsFromConfig.ps1" />
<Compile Include="Scripts\Enable-AzLogicApp.ps1" />
<Compile Include="Scripts\Enable-AzLogicAppsFromConfig.ps1" />
<Compile Include="Scripts\Get-AzLogicAppResourceManagementUrl.ps1" />
<Compile Include="Scripts\Get-AzLogicAppConsumptionResourceManagementUrl.ps1" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="Build" />
Expand Down
79 changes: 71 additions & 8 deletions src/Arcus.Scripting.LogicApps/Scripts/Cancel-AzLogicAppRuns.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,82 @@
param(
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of the resource group is required"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required"),
[Parameter(Mandatory = $false)][string] $WorkflowName = "",
[Parameter(Mandatory = $false)][string] $EnvironmentName = "AzureCloud",
[Parameter(Mandatory = $false)][int] $MaximumFollowNextPageLink = 10
)

try {
$runs = Get-AzLogicAppRunHistory -ResourceGroupName $ResourceGroupName -Name $LogicAppName -FollowNextPageLink -MaximumFollowNextPageLink $MaximumFollowNextPageLink |
Where-Object {$_.Status -eq 'Running'}
if ($WorkflowName -eq "") {
$runs = Get-AzLogicAppRunHistory -ResourceGroupName $ResourceGroupName -Name $LogicAppName -FollowNextPageLink -MaximumFollowNextPageLink $MaximumFollowNextPageLink |
Where-Object {$_.Status -eq 'Running'}

foreach ($run in $runs) {
Stop-AzLogicAppRun -ResourceGroupName $ResourceGroupName -Name $LogicAppName -RunName $run.Name -Force
Write-Verbose "Cancelled run $run.Name for the Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'"
}
foreach ($run in $runs) {
$runName = $run.name
Stop-AzLogicAppRun -ResourceGroupName $ResourceGroupName -Name $LogicAppName -RunName $runName -Force
Write-Verbose "Cancelled run '$runName' for the Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'"
}

Write-Host "Successfully cancelled all running instances for the Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'" -ForegroundColor Green
} else {
$token = Get-AzCachedAccessToken
$accessToken = $token.AccessToken
$subscriptionId = $token.SubscriptionId

$listRunningUrl = . $PSScriptRoot\Get-AzLogicAppStandardResourceManagementUrl.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $subscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -WorkflowName $WorkflowName -Action 'listRunning'
$listRunningParams = @{
Method = 'Get'
Headers = @{
'authorization'="Bearer $accessToken"
}
URI = $listRunningUrl
}

$runs = Invoke-WebRequest @listRunningParams -ErrorAction Stop
$runsContent = $runs.Content | ConvertFrom-Json
$allRuns = $runsContent.value

if ($runsContent.nextLink -ne $null) {
$nextPageCounter = 1
$nextPageUrl = $runsContent.nextLink
while ($nextPageUrl -ne $null -and $nextPageCounter -le $MaximumFollowNextPageLink) {
$nextPageCounter = $nextPageCounter + 1
$listRunningParams = @{
Method = 'Get'
Headers = @{
'authorization'="Bearer $accessToken"
}
URI = $nextPageUrl
}

Write-Host "Successfully cancelled all running instances for the Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'" -ForegroundColor Green
$runsNextPage = Invoke-WebRequest @listRunningParams -ErrorAction Stop
$runsNextPageContent = $runsNextPage.Content | ConvertFrom-Json
$nextPageUrl = $runsNextPageContent.nextLink
$allRuns = $allRuns + $runsNextPageContent.value
}
}

foreach ($run in $allRuns) {
$runName = $run.name

$cancelUrl = . $PSScriptRoot\Get-AzLogicAppStandardResourceManagementUrl.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $subscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -WorkflowName $WorkflowName -RunName $runName -Action 'cancel'
$cancelParams = @{
Method = 'Post'
Headers = @{
'authorization'="Bearer $accessToken"
}
URI = $cancelUrl
}
$cancel = Invoke-WebRequest @cancelParams -ErrorAction Stop
Write-Verbose "Cancelled run '$runName' for the workflow '$WorkflowName' in Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'"
}

Write-Host "Successfully cancelled all running instances for the workflow '$WorkflowName' in Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'" -ForegroundColor Green
}
} catch {
throw "Failed to cancel all running instances for the Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'. Details: $($_.Exception.Message)"
if ($WorkflowName -eq "") {
throw "Failed to cancel all running instances for the Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'. Details: $($_.Exception.Message)"
} else {
throw "Failed to cancel all running instances for the workflow '$WorkflowName' in Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'. Details: $($_.Exception.Message)"
}
}
49 changes: 28 additions & 21 deletions src/Arcus.Scripting.LogicApps/Scripts/Disable-AzLogicApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,42 @@ param(
[Parameter(Mandatory = $false)][string] $SubscriptionId = "",
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of the resource group is required"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required"),
[Parameter(Mandatory = $false)][string] $WorkflowName = "",
[Parameter(Mandatory = $false)][string] $ApiVersion = "2016-06-01",
[Parameter(Mandatory = $false)][string] $AccessToken = ""
)

try{
if($SubscriptionId -eq "" -or $AccessToken -eq ""){
# Request accessToken in case the script contains records
$token = Get-AzCachedAccessToken
if ($WorkflowName -eq "") {
if ($SubscriptionId -eq "" -or $AccessToken -eq "") {
# Request accessToken in case the script contains records
$token = Get-AzCachedAccessToken

$AccessToken = $token.AccessToken
$SubscriptionId = $token.SubscriptionId
}
$AccessToken = $token.AccessToken
$SubscriptionId = $token.SubscriptionId
}

$fullUrl = . $PSScriptRoot\Get-AzLogicAppResourceManagementUrl.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -ApiVersion $ApiVersion -Action "disable"
$fullUrl = . $PSScriptRoot\Get-AzLogicAppConsumptionResourceManagementUrl.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -ApiVersion $ApiVersion -Action "disable"

Write-Verbose "Attempting to disable Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'..."
$params = @{
Method = 'Post'
Headers = @{
'authorization'="Bearer $AccessToken"
Write-Verbose "Attempting to disable Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'..."
$params = @{
Method = 'Post'
Headers = @{
'authorization'="Bearer $AccessToken"
}
URI = $fullUrl
}
URI = $fullUrl
}

$web = Invoke-WebRequest @params -ErrorAction Stop
Write-Host "Successfully disabled Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'" -ForegroundColor Green
}
catch {
Write-Warning "Failed to disable Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'"
$ErrorMessage = $_.Exception.Message
Write-Debug "Error: $ErrorMessage"
$web = Invoke-WebRequest @params -ErrorAction Stop
Write-Host "Successfully disabled Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'" -ForegroundColor Green
} else {
Set-AzAppServiceSetting -ResourceGroupName $ResourceGroupName -AppServiceName $LogicAppName -AppServiceSettingName "Workflows.$WorkflowName.FlowState" -AppServiceSettingValue "Disabled"
Write-Host "Successfully disabled workflow '$WorkflowName' in Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'" -ForegroundColor Green
}
} catch {
if ($WorkflowName -eq "") {
throw "Failed to disable Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'. Details: $($_.Exception.Message)"
} else {
throw "Failed to disable workflow '$WorkflowName' in Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'. Details: $($_.Exception.Message)"
}
}

0 comments on commit 4624a4e

Please sign in to comment.