Infrastructure as Code with .net
John woke up from his sleep as his mobile rang and clock showed 4 AM .Over the other end , Mike is in panic mode urging him to be in office as if it is end of the world.
John : Mike , relax .. What is happening ?
Mike : Our main server is getting bombarded with more and more traffic because of the holiday season, So,we have requested for more servers .
John : Oh not again !! Has the business announced the discount yesterday ?
Mike : John ! I don't have time for it now. I want you to come down to configure the application in the new servers which we got .
John : But mike , I need to know all the IIS settings ,environment variables and few other things . I might need more help to complete the task .
Mike : Ok John, Come down . I will get more people .
John reaches office and found an another developer waiting for him in half sleep state .
They started working on and found each settings from a running IIS and copied the settings from the other new server
John: Mike , we have done it. But it was a nightmare .
Mike : Thanks john !! But I am gonna ask you to configure couple of more servers . Hope you don’t mind configuring it

I am going to stop here and ask what will you do if this happens to you.This can happen in any company .
Well you are not alone as this problem persist for sometime , in the recent years the lots of companies has come up with some good practices and solution for this problem. And collective of those practices are called infrastructure as code.
In this blog I will explain what are those best practices and the current toolset available in .net platform . Before getting into that I will explain the possible approach we take .
To Start with , easiest way to solve this you can document the steps and maintain it so you can just hand over whenever it happens. Problem with above approach is there is no way to test it automatically, so there is high chance this happens to manually .
Second Approach : We can have scripts written and have it ready for the use. This is where the Powershell comes for rescue in windows server . This is a great start for a infrastructure as a code practices. But this is not enough , we need to maintain this script just like code and make sure the script can be executed with or without manual interventions .
Infrastructure as Code Practices
Maintain the script just like code:
Script has to go into git or TFS or subversion and it should be maintained with the version just like code and always
Make small changes instead of batches for script
Continuously test systems and Process
Make sure the scripts are good enough that it can recreate the environment from scratch as well as when things are available. Always strive to make the scripts produce a reproducible builds .
To make reproducible builds is not a easy practice , it comes with lots of practices . This is where tools come into help .
One such a tool which can help in this process in Otter . This offers the server configuration and infrastructure automation support .
This provides a better way to manage the things also provides a better way to manage windows infrastructure . Otter doesn’t ask you to write script , instead it provides a definition file

This goes with the next best practices , Make the script as a definition file
Make script as human-readable definition files
This will allow scripts to be easily understandable and easy to work for anybody . But this definition files can be executed only by the specific tools .
This approach is followed by lot of other tools like Vagrant , docker and ansible . But these tools are quite not ready or consider windows as a secondary citizen when it come to automation.
With definition files we can make the infrastructure configuration as self documented system and process .
There is also one more great tool in .net space which is doing a great job in the space is Octopus deploy . even though it is quite not in complete infrastructure as code way , It does a pretty good job in maintaining the configuration .
I have purposefully talked only about tools which gives preference to windows,also I have not talked about Azure resource manager or AWS cloud watch . Reason being , I want the tools to be environment agnostic and even help people with inhouse infrastructure.
Also last but not least , Ottor and Octopus deploy are paid and I have not found any free tools for this job or even these tools don’t have free versions other than a trial version . we as a community has not done a good job in coming up with a free tool which can provide a excellent support .
So that will be my next blog post on demystifying the deployment tools and planning to write one myself. You can follow it in my github repository.
Dropseed.Server - Make your infrastructure and deployment as immutable using code.github.com
Also if you want to learn more about the infrastructure as code , You can watch this presentation .
That's it folks .