Octopus deploy runbook to azure app service settings

In octopus deploy I want to add a runbook that will loop through all app services in the tenant and turn on “https only” tls/ssl setting.

I think adding a azure script step in a runbook is the best option to achieve this.

Hey there @junaid.ahmed , welcome to the forum!

You’re spot on, runbooks are a great option for this type of task. I did some testing locally and wound up with this script, which should allow you to selectively name and update Azure webapps using an authenticated AZ CLI login

#  WebApp Names to convert
$appNamesToConvert = @('mywebapp-dev', 'mywebapp-production')

# Get relevant app services and resource group names from the CLI, convert them to a native PowerShell object
$webAppList = az webapp list --query '[].{Name:name, ResourceGroup:resourceGroup}' | ConvertFrom-Json

# Filter list to items matching the specified names
$webAppList = $webAppList | Where-Object { $appNamesToConvert -contains $_.Name }

# Complete required updates and write out validation to Task Log
foreach($app in $webAppList) {
    $cliCommand = (az webapp update -g $app.ResourceGroup -n $app.Name --https-only true) | ConvertFrom-Json
    Write-Highlight "$($cliCommand.Name) had it's `https-only` config value updated to $($cliCommand.httpsOnly)"

Let me know if you have any questions or run into any issues, I’m happy to help!

Hey Junaid, there’s a great reference to executing AZ CLI scripts in the documentation here. Sorry, I should have included that with my initial response!

Depending on whether you’re executing from the Octopus server itself or on a worker, you’ll need to make sure the AZ CLI is installed so the commands can be executed.

Let me know if you have any other questions or run into any other challenges, I’m happy to assist!

Hi @cory.reid , thanks for your help again. Actually I managed to fix that so that’s why I deleted my above reply.
Thanks alot for your help

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.