What is IaC?
Infrastructure as code is a process of provisioning hardware using scripts.
In the past provisioning and setting up new hardware was a long and tedious process. With clouds (not the fluffy ones) creating a new server or database is just a couple of clicks away. IaC is just a way to script those clicks to make it easy to re-create environments as needed.
IaC for Azure
There are several good options for IaC in Azure:
- arm templates — native azure option
- terraform — popular OSS and cloud
- ansible- another popular platform supported by RedHat.
- pulumi — new kid on the block
Each one of these can be used to provision and deploy resources in Azure. They mostly have similar features like:
- preview changes
- rollback changes
- clean up
- some form of script/code re-use
- easy to integrate into CD pipelines
- scripts/code can be versioned in source control
But there are some major differences also. Let’s go through them in some detail.
ARM Templates
There are two versions of arm templates.
classic way is Json
a newer approach is to use Bicep, which is a wrapper around ARM templates It looks a bit more like a real programming language:
Good:
- keeping things in one stack/env (Microsoft) can be better than integrating with yet another 3rd party
- up to date
Bad:
- learn yet another language. If only Microsoft had one or two other languages that they could re-use for this? Hmmm…..
Terraform
Has been around since 2014. Uses HashiCorp Config Language.
Looks like this:
Good:
- oldish and well-known tool
- supports Python and TypeScript through SDK
Bad:
- learn yet another language
- have to manage State manually. Most others provide SaaS offerings.
Ansible
Another old-timer from 2012.
Written in Python, so very friendly to Python developers.
Uses Yaml for declaring Infrastructure resources.
Good:
- Open Source (owned by Red Hat)
- Has a big community — 54K stars.
Bad:
- learn yet another language
Pulumi
https://www.pulumi.com/docs/intro/vs/
You probably noticed a common “bad” trend of the tools above: you have to learn a new language. But don’t fear… There is a new kid on the block: Pulumi.
Pulumi supports multiple programming languages: TypeScript, Python, C# and a bunch of others. With Pulumi, Microsoft developers can continue working in Visual Studio and using C#, but now they can use it to create infrastructure in the cloud.
Here is an example:
Good:
- Can use C# !!!
- Up to date with Azure Native API
- Documentation is really good with code examples for pretty much every resource
Bad:
- New and a bit unproven
Conclusion
We have looked at various options for implementing IaC in the Azure environment. And the winner is … Pulumi!
It has support for C# and excellent documentation, which allows for a small learning curve. It is not as established as some other older Tools, but it has a very promising future.
Here is an accompanying Demo video with a sample code