I’m becoming a fan of Terraform, when I started using at my work to manage our Azure environments and using it more recently with Azure Devops. Terraform is an infrastructure-as-code tool that allows to create and manage cloud based infrastructure in codified way. It is an open source tool that codifies APIs into declarative configuration files (*tf) that can be source control to version the changes.
Infrastructure as Code (IaC) is provisioning and managing computing infrastructure with declarative approach that can be source control to version the changes that you want to make your infrastructure. Infrastructure-as-code, is a modern approach to managing infrastructure, and is called the “foundation for DevOps”.
Using Infrastructure as Code as part of your deployment process has a number of benefits to your workflow:
- Consistency – The IoC will be consistent through source code management. This is good when it comes to rolling back if mistakes are made.
- Speed – Creating infrastructure through declarative approach will be faster while comparing to manual navigation through interface.
- Reusability – Existing code can be reused for provisioning and deployment across multiple platforms.
- Extensibility – Existing code can be extended for provisioning and deployment.
Terraform uses the concept of “providers”, which are like plugins which extend the capabilities of the tool, to interact with various cloud systems in a number of different ways.
- Download Terraform from https://www.terraform.io/downloads.html.
I’m using Windows 64-bit.
Terraform is packed as zip archive. You can download it using chocolatey, which is good too.
- After downloading terraform, unzip the package.
- Copy files from the zip to “c:\terraform” for example. That’s my terraform PATH. The PATH is the system variable that operating system uses to locate needed executables from the command line or Terminal window.
For Windows 8
- Search for : System (Control panel)
- Click the Advanced system settings link.
- Click Environment Variables.
- In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
- In the Edit System Variable window, append at the end of the PATH environment variable the value of terraform path as ”c:\terraform;”
- Click OK, then OK, then OK
Once you have configured the terraform, you should be able to run terraform commands. Open up command prompt and type terraform. You should see the terraform usage appear.
Terraform Extension with Visual Studio Code
- Download Visual Studio Code (VSC) from https://code.visualstudio.com/download
- Run the installer, check the option to open folders with Visual Studio Code.
- Once Installer is complete and can be opened from the Start Menu.
- To install extensions Press F1 and start typing ext or (Ctrl + Shift + X)
- Choose Extensions: Install Extensions
- Install Terraform and Azure Terraform extensions
Now you’re ready to write some code!