This weekend one of the systems we integrate with had a maintenance window while some server upgrades were performed.

To support this activity we needed to be able to take some of our Logic App integrations off line during the maintenance window.

Our design patterns for integration fall into a couple of patterns with respect to this system:

  1. Logic Apps which listen to a service bus queue then call API’s to upload data to the system
  2. Logic Apps which run on a schedule and poll the system API’s and download data for various other interfaces

These approaches are easy for us to handle a maintenance window. We can simply disable the interfaces then re-enable them. Any messages on service bus will just queue up and be handled later. The polling interfaces will just catchup when ready.

To implement the disable/enable we setup a DevOps pipeline so anyone on the team could run the job when needed.

We used the Azure Powershell task in DevOps configured like below which will call a script in a repo to do the necessary actions. I just pass in the resource group and desired state as parameters.

steps:
- task: AzurePowerShell@4
  displayName: 'Enable Logic Apps'
  inputs:
    azureSubscription: 'Mikes-Subscription'
    ScriptPath: '$(System.DefaultWorkingDirectory)/_Admin/Interfaces.ChangeState.ps1'
    ScriptArguments: '-resourceGroup ''Mikes-ResourceGroup'' -desiredState ''Enabled'''
    azurePowerShellVersion: LatestVersion

We then just had a classic release pipeline which has a stage for our UAT and Prod environments and one to disable and one to enable. This makes it easy for whoever is on support and in the future we just need to add any interfaces to the powershell

The script below contains a list of logic apps to pause and enable depending on the parameters provided.


param (
    # The resource group to update
    [string]$resourceGroup = "", 
    
    # Enabled or Disabled
    [string]$desiredState = ""    
)


$logicApps = New-Object "System.Collections.Generic.List[System.String]" 

# Material Reservation
$logicApps.Add('Mikes-LogicApp-1')
$logicApps.Add('Mikes-LogicApp-2')
$logicApps.Add('Mikes-LogicApp-3')
$logicApps.Add('Mikes-LogicApp-4')


# Helper Function to change the state of the logic app
function ChangeLogicAppState([string] $logicAppName, [string] $resourceGroupName, [string] $desiredState)
{
    Write-Host 'Checking logic app ' $logicAppName

    $logicApp = Get-AzLogicApp -ResourceGroupName $resourceGroupName -Name $logicAppName
    Write-Host ($logicApp | Format-List | Out-String)
        
    $apiOperation = 'unknown'
    if($desiredState -eq 'Enabled')
    {
        $apiOperation = 'enable'    
    }
    elseif($desiredState -eq 'Disabled')
    {
        $apiOperation = 'disable'
    }
        
    if($logicApp -eq $null)
    {
        Write-Host 'Logic App does not exist: ' $logicAppName
    }
    else
    {
        Write-Host 'Logic App does exist: ' $logicAppName

        $currentState = $logicApp.State.ToLower()        
        if($currentState -eq $desiredState.ToLower())
        {
            Write-Host 'Logic App ' $logicApp.Name ' is already in the desired state'
        }
        else
        {
            $url = 'https://management.azure.com/' + $logicApp.Id + '/' + $apiOperation + '?api-version=2016-06-01'
            $response = az rest --method post --uri $url 
            Write-Host 'Logic App Changed'

            $logicApp = Get-AzLogicApp -ResourceGroupName $resourceGroupName -Name $logicAppName
            Write-Host ($logicApp | Format-List | Out-String)
        } 
                       
    }
}

#Loop through the Logic App workflows and change their state
foreach($logicApp in $logicApps){
    ChangeLogicAppState -logicAppName $logicApp -resourceGroupName $resourceGroup -desiredState $desiredState    
}





 

Buy Me A Coffee