learn-terraform

Course outlines for learning terraform.

View the Project on GitHub robertdebock/learn-terraform

Introduction to Infrastructure as Code with Terraform

expected time requirements
60 minutes none

Goal: Understand what Infrastructure as code is.

Why Infrastructure as Code (IaC)?

What is the problem IaC is trying to solve?

  1. Manual work is difficult.
  2. Manual work is error prone.
  3. Manual work is slow.
  4. Manual work leads to “pets” over “cattle”.

Not specifically Terraform, but IaC (Infrastructure as Code) in general has these benefits:

Benefits are listed here

There are some drawback too:

Terraform

Let’s learn a bit more on Terraform:

There are many providers and modules.

Terraform keeps state. State is sort of a book-keeping of what Terraform has created. This means it can compare the (local) state to the desired state, making deployment faster and allowing users to clean-up resources remove from the configuration. This also allows people or teams to collaborate.

+----- Team A ------+     +----- Team B ------+
| resources.tf      |     | resources.tf      |
| terraform.tfstate |     | terraform.tfstate |
+-------------------+     +-------------------+
         |                         |
         V                         V
+------------- Cloud provider X --------------+
| +--- instance A ---+   +--- instance B ---+ |
| |                  |   |                  | |
| +------------------+   +------------------+ |
+---------------------------------------------+

Having state means Terraform will remove resources that are not described anymore.

Demo

Actually; let’s create your machines.

You are free to use this machine. If you’d like to run Terraform from another machine, maybe your laptop, please install Terraform.

Questions

  1. Terraform keeps state, what is the benefit?
  2. Terraform and configuration management differ, for what situation would you use either?
  3. In your own words, what are some benefits of infrastructure as code?
  4. You (maybe) have see it can take a while for the “playground” machines to be ready. What could you do to make this deployment quicker?

What tools to use when?

There is no clear answer to this question. I suggest to use the right tool for the type of work. Most companies use Terraform and some other configuration management system, for example.

In other words, just Terraform is not always sufficient.