DEV Community

Cover image for Configure CD for Azure WebApp with Terraform Provider for Octopus Deploy
Anton Sizikov
Anton Sizikov

Posted on

Configure CD for Azure WebApp with Terraform Provider for Octopus Deploy

In this post, I'm going to configure the continuous delivery process for Azure WebApp (Azure Function in this case, but that's pretty much the same) with Octopus Deploy. To make it a little bit interesting I'm going to use Configuration-as-Code approach with a brand new Octopus provider for Terraform.

Buckle up and let's get started...



I'm going to need terraform on my machine:

Octopus Deploy

For this post, I've signed up for a free tier of Octopus Deploy SaaS offering. Of course, the self-hosted version will work as well.

When signed up and configured my account I can generate a new API key that I'm going to use with Terraform

All configuration is going to be made against the default Space (Spaces-1), however, that's configurable too.


To connect Octopus Deploy with Azure I'm going to need a Service Principal.

# (!) make sure to follow the principle of least privilege here 
# and define the role and scope
az ad sp create-for-rbac --name sp-octopus-deploy
Enter fullscreen mode Exit fullscreen mode

Grap the tenant Id, application Id, password, and subscription Id values. We'll heed them later.

Azure Function

For the demo, I'm going to use this super simple Azure Function that replies to your GET request with a list of headers supplied.

The complete source code is published here.

the .csx gist is the following

Azure DevOps

I'm running the CI part in Azure DevOps.

Project configuration is pretty simple and it's terraform set up can be found here.

the pipeline itself it here.

Nothing complicated:

  • Build Azure Function
  • Pack Azure DevOps artifact (zip)
  • Upload it to Octopus Deploy's built-in feed
  • Create and trigger Octopus Deploy release

I'm still waiting for the fix to my bug-report to be delivered, without it I cannot make this demo end-to-end :(


Terraform provider is no different from other providers and can be found on Terraform Registry

and terraform init will download missing files


For the demo, I'm going to have this terraform.tfvars file to provide configuration values to Terraform.

Configure Environment

Now we're ready to start. At first, I'm going to configure a new Environment.

Environments are how you organize your deployment targets (whether on-premises servers or cloud services) into groups that represent the different stages of your deployment pipeline, for instance, development, test, and production.

You'd probably have more than one, but that'll do for now.

Deployment Target

The next crucial part is Deployment Target

With Octopus Deploy, you can deploy software to Windows servers, Linux servers, Microsoft Azure, AWS, Kubernetes clusters, cloud regions, or an offline package drop. Regardless of where you're deploying your software, these machines and services are known as your deployment targets.

I'm using octopusdeploy_azure_web_app_deployment_target, It's quite specific. I could have used a more generic octopusdeploy_deployment_target instead.

This is where I link Azure (my Service Principal) with Octopus.

Now we have a nice and clean infrastructure defined in Octopus.


The next step is to configure our Project.

Projects let you create and manage your deployment processes, releases, and runbooks from the Octopus REST API and Octopus Web Portal.

I'm setting up an Echo Api project here, placing it into Default Project Group with the default lifecycle.

Deployment process

And now the juicy part.

My deployment is super simple actually, just one step that is picking up the package from a built-in feed and pushing it to my only environment.

I wish all deployments were that simple...


Initially, I wanted to automate the release creation and trigger it via my Azure DevOps pipeline, but due to a very recent bug, I'm blocked here. I'll update this post when things are fixed so for now just a manual process.

I'm creating a new release from the zip file in my built-in package feed

And now I can sit back and watch it deploying my function.

Voilà, it's up and running.


The neat part about Octopus Deploy is its resource ID's system. It's always easy to find the id of the object which makes it super easy to import existing resources into your terraform state.

Let's assume that I already have an environment configured.
Enter fullscreen mode Exit fullscreen mode

The URL looks this way. Environments-7 is the id of my environment.

All it takes to import the environment is to declare the resource and type one command:

this is such a breath comparing to long and not so easy to get Ids in Azure :)

this is a cross-post from my personal blog.

Top comments (0)