Part 1 (Source Control your Immutable Infrastructure ) : Microsoft Azure ARM Templates and Octopus Deploy in your Digital Pipeline

I have been recently working on lots of projects to enable the digital pipeline within enterprise organisation of various size. “No hugging of environments, so kill it when there is a misbehave and build from source control with trust and confidence.”  This blog post is all about experimented how Octopus Deploy can be used during environment provisioning to Deploy the applications into various environments. This emerged based on the talk I have given during the #abbdevday in Poland. Currently lot of developers gets frustrated because they cannot have a production like replicated kits on their development environments and testers get inconsistent test results because they give up replicating environment since they stuck in long process to rebuild a production like environments. Due to all these nested constraints projects get delayed and lead to rollback of deployments. Lots of this Drama makes blame game much more complicated. But If you look in deep its everyone responsibility to get a feature shipped quickly to production. Hence you are here reading this blog post, we have cloud capability which can enable developers and testers to build environments within minutes and run the tests against the environments. Sometimes management might have a question around the cost, but we have that covered too because once the tests are completed you have the capability to clear down the environments which will be much more cost effective rather than running 24/7. In Essence environments should be treated as cattle not as cats. 

Nearly 60% of developers are not happy about the inconsistent environments. As Chad Fowler mentioned the term immutable infrastructure, which is key to produce consistent environments in different stages of digital pipeline which can only lead to the success of the project. Below method helps any developers can spin up environments against a subscription to use and also it enable even performance testing. On top of all this you are using the same tool sets as you deploy your applications.

The Story goes like this

There are three parts to this 1. Source control the environment provisioning in Microsoft Azure using azure ARM templates, once provisioning is completed 2) use PowerShell DSC to configure the desired state of the server for applications to work properly and finally 3) deploy the applications with essential configurations for the specific environments.

Tools and Technologies

  • Microsoft Azure account
  • ARM Templates
  • Microsoft Visual Studio
  • Octopus Deploy 3.1
  • Azure SDK 2.7
  • Azure Powershell (0.9.7) Latest version
  • DSC Scripts
  • GitHub Account
  • Sample websites
  • Win RM

In this blog post we are assuming you have already octopus deploy server and teamcity installed and configured for use. If you have not done so please install before proceeding further with this article.

Source Control the Infrastructure

Let’s start looking at how to create the ARM templates. Ensure Azure SDK 2.7 or later is installed. Launch the visual studio and select new project then choose the blank template.

Let’s quickly examine the solution. You will be able to see three different folders Scripts, Templates and Tools. Under the templates folder we have DeploymentTemplate.json and DeploymentTemplate.param.json. I have reorganised as shown below

Now, we have added various resources required for the application to run. These resources can be viewed in the JSON outline in visual studio as shown below

Below is the format of your Deployment Template file which you can see in the collapsed manner

The deployment parameters file contains the below format

You can do the parameterization to any level you need to but for this demonstration I have done few and some are left as hard coded values.

Each resources will have the following








When you define the resource, you get to define the Parameters and it contains key properties as

Parameter Name,


Default value

Allowed Values


As shown below

Now in the key part is how you define the deploymentparam.json file. Usually you would specific one of the allowed values from the parameters definition of the template file. But we are not going to follow this standards because we have Octopus Deploy to handle this situation to provide environment specific values.

Once we have the Template ready and available, lets create the Nuspec file to create the nuget packages.

Time has come to package the files as nuget package which Octopus Deploy uses as the source.

In the Teamcity we have a project to build the solution, create a nuget package then finally create a create in octopus deploy if successful

Let’s move to octopus deploy to configure the process steps and we have 2 steps available

We have defined a Script Module which is used to load the azure resource manager. [Note at the time of writing Switch-azuremode exists]

As shown below its included in the project

We have different variable sets included to enable provision of various resources

You can see the mapping from the template file into the octopus variable sets and also see the scoping of the variables

Now you can create a release and deploy to different environments. We have been through so far and looks great we can create networks, storage account and provision the virtual machines but how are we going to add the tentacle as part of this provisioning. The answers you can run the DSC extension ( as part of the Template or you can run a custom script to install Octopus Deploy tentacle.

Download the DSC resource from the storage account and extract to the windows azure powershell modules. Run an DSC script via custom scripts

Below script can be run as a custom script from the ARM template, Thanks to Dave Wyatt in helping around certificates. This script also enable WIN RM to connect remotely and enable the DSC features which will be required in the Part 2 of this series.

After the provision of all these resource you can see the tentacle available under the environments section of octopus deploy.

Always feel free to contact if you need any assistance or questions.

Happy to help out.

In the Part 2 of this series let’s talk about DSC and Octopus deploy to configure servers.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.