Azure Web app deployment - use a variable rather than target role

modelling

(mcalnd) #1

Hi, I have a 2 step project, step 1 is to use an ARM template from a zip file in the Octopus Library and run it into Azure. This works perfectly.

My next step is to deploy a Nuget package (also from the Octopus Library) into the Web App that step 1 created. Using the “Deploy an Azure Web App” process step, it states I need to create a “target role” (under the On Behalf of section) which would mean I would need to set up lots of Deployment Targets AND target roles

The deployment / target role would end up being the name of the Web App Service that was already named in the ARM template from step 1.

Is there a better way of setting this up so that pre-defined Deployment Targets and Target Roles don’t need to be created?

Thanks in advance

Neil


(Jayden Platell) #2

Hi Neil,

Thank you for contacting us!

A target will need to be created for the new infrastructure, and a role assigned, and we have some APIs for doing just that. If you haven’t already, I recommend looking at this blog post we created earlier this year which goes through a very similar process you are using to create new Azure infrastructure with ARM templates and then deploy to it.

Specifically, the Powershell it uses to create the new target is:

New-OctopusAzureWebAppTarget -name $SiteName `
                             -azureWebApp $SiteName `
                             -azureResourceGroupName $SiteResourceGroup  `
                             -octopusAccountIdOrName "azure" `
                             -octopusRoles "CloudWebSite" `
                             -updateIfExisting

Although you will be creating a new target for the infrastructure your ARM template creates, those targets don’t need a unique role, and should be assigned an existing role which Step 2 is deploying to.

I hope that helps! Let me know if I can assist you further.

Regards,
Jayden


(mcalnd) #3

Hi Jayden, thanks for the reply.

With this Powershell could you call in vars from a Variable set? Otherwise it seems that it is the same amount of work to maintain this Powershell per-project as it is to set up Deployment Targets and Target roles in advance.

Thanks

Neil


(Jayden Platell) #4

Neil,

Certainly! You can access all available variables in a deployment through $OctopusParameters. For example, if you have a variable named WebAppName you can access that variable in Powershell via $OctopusParameters["WebAppName"].

Check out the documentation on Variables in PowerShell Scripts for more info.

Regards,
Jayden


(mcalnd) #5

Thanks for the reply, I’ve gone through the blog post and made good progress.

For the prior dynamic Powershell step I modified the script to use variable sets to allocate role names. e.g.

-OctopusRoles $OctopusParameters[“octovar-targetrole-app-prod-mydotnetcorewebapp”]

This worked perfectly.

However I have reached an impasse at the point in the blog post where you use the “Deploy to an Azure Web App” step and putting in the target role part, as it appears that the section doesn’t support using variables. This will cause issues with deploying through the lifecycle of enviornments (dev/uat/prod etc.)

Is there a workaround?


(Jayden Platell) #6

Neil,

Roles shouldn’t be environment specific for this exact reason. The purpose of roles is to provide a way of tagging the different types of targets in each environment. They typically describe the type of technology (Web, database, etc) and sometimes also the application being deployed (BackendWebServer, for example).

Are you able to make the roles non-environment-specific? If not, would you mind briefly explaining the architecture you are deploying and why you need the roles to include the environment?

Regards,
Jayden


(mcalnd) #7

Thanks Jayden, that makes perfect sense, I’ve moved around that issue now. I have another issue, but that will be another post - Thanks for your help

Neil