Terraform

1 min read

Terraform

Explain what Terraform is and how does it works

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.

Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. Terraform generates an execution plan describing what it will do to reach the desired state, and then executes it to build the described infrastructure. As the configuration changes, Terraform is able to determine what changed and create incremental execution plans which can be applied.

The infrastructure Terraform can manage includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features, etc.

What benefits infrastructure-as-code has?

  • fully automated process of provisioning, modifying and deleting your infrastructure
  • version control for your infrastructure which allows you to quickly rollback to previous versions
  • validate infrastructure quality and stability with automated tests and code reviews
  • makes infrastructure tasks less repetitive

Why Terraform and not other technologies? (e.g. Ansible, Puppet, CloudFormation)

A common wrong answer is to say that Ansible and Puppet are configuration management tools and Terraform is a provisioning tool. While technically true, it doesn't mean Ansible and Puppet can't be used for provisioning infrastructure. Also, it doesn't explain why Terraform should be used over CloudFormation if at all.

The benefits of Terraform over the other tools:

  • It follows the immutable infrastructure approach which has benefits like avoiding a configuration drift over time
  • Ansible and Puppet are more procedural (you mention what to execute in each step) and Terraform is declarative since you describe the overall desired state and not per resource or task. You can give the example of going from 1 to 2 servers in each tool. In Terraform you specify 2, in Ansible and Puppet you have to only provision 1 additional server so you need to explicitly make sure you provision only another one server.
Orestis Pantazos

Orestis Pantazos

DevOps Engineer