[editor comment: if you don’t know what Infrastructure As Code (IaC) is I recommend reading this post first]
What Is Terraform
Terraform is an open source tool that helps you provision, manage the state of and update, infrastructure. Terraform works by using Infrastructure as Code (IaC) to provision and update infrastructure such as networking, virtual servers, storage and much more. Configuration files (or definitions) are used to describe infrastructure. These configuration files are written in a plain text language, one that is quick to learn. These configuration files define a blueprint of your infrastructure. For example, you may have a file that defines a vSphere Distributed Switch Port Group; the number of ports, security configuration, traffic shaping settings etc. This file is read by Terraform which in turn creates a plan. The plan encapsulates all the changes that will be made to the environment. In our case, it will show the changes to the Distributed Switch when the Distributed Portgroup is created, along with all of the portgroup settings that we will add, change or delete. Then plan can be saved to a file, so the application of the change can be done at a later date. When Terraform is fed the plan and told to apply it, it will make the ‘planned’ changes to your environment. Terraform doesn’t require expensive infrastructure to get going. On Windows, a single executable file (terraform.exe) is required. That is it, nothing else!
Terraform Key Terms
Infrastructure as Code (Infastructure Definitions)
Infrastructure is defined in code using a simple syntax driven language. The definitions are saved in plain text files allowing you to utilise popular development processes (such as storing code in a Git repository) without having to jump through any complex or propriatery hoops.
Plans detail exactly what changes will take place, including additions, changes and removal of settings or infrastructure. Plans are also known as ‘Execution Plans.’ Terraform will only execute on the contents of a plan.
Once a plan has been applied a state is stored by Terraform. The state comprises the infrastructure after the plan has been applied. By storing the state, Terraform can be used to monitor configuration shift, plan against changes and easily allow you to scale out deployed infrastructure components.
Terraform creates a graph that outlines all the components and settings in your plan. This allows Terraform to map dependencies and therefore when applying a plan, execute as much of the plan as possible in parallel. This ensures that infrastructure changes can be carried out as quickly and as efficiently as possible.
A provider is used to broker between your defined infrastructure (in your IaC files) and the target system. The provider can translate both ways, exposing resources and executing the correct API calls to manipulate the infrastructure. There are lots of providers out there but should one you require not be available, you can write your own to bridge the gap.
When you write IaC for use with Terraform, you don’t even need to worry about obtaining the providers you need. Terraform is able to read the IaC files and from this, understand what providers are required. Terraform will then download the providers for you!
So Now What?
Many of the tutorials and examples for Terraform (both in books and on the web) utilise AWS. In a following series of posts, I will demonstrate the use of Terraform within a VMware vSphere environment.