1 Getting started with Terraform

This chapter covers

  • Understanding the syntax of HCL
  • Fundamental elements and building blocks of Terraform
  • Setting up a Terraform workspace
  • Configuring and deploying an Ubuntu virtual machine on AWS

Terraform is a deployment technology for anyone who wants to provision and manage their infrastructure as code (IaC). Infrastructure refers primarily to cloud-based infrastructure, although anything that could be controlled through an application programming interface (API) technically qualifies as infrastructure. Infrastructure as code is the process of managing and provisioning infrastructure through machine-readable definition files. We use IaC to automate processes that used to be done manually.

When we talk about provisioning, we mean the act of deploying infrastructure, as opposed to configuration management, which deals mostly with application delivery, particularly on virtual machines (VMs). Configuration management (CM) tools like Ansible, Puppet, SaltStack, and Chef are extremely popular and have been around for many years. Terraform does not supplant these tools, at least not entirely, because infrastructure provisioning and configuration management are inherently different problems. That being said, Terraform does perform many of the functions once reserved by CM tools, and many companies find they do not need CM tools after adopting Terraform.

1.1 What makes Terraform so great?

1.1.1 Provisioning tool

1.1.2 Easy to use

1.1.3 Free and open source software

1.1.4 Declarative programming

1.1.5 Cloud-agnostic

1.1.6 Richly expressive and highly extensible

1.2 “Hello Terraform!”

1.2.1 Writing the Terraform configuration

1.2.2 Configuring the AWS provider

1.2.3 Initializing Terraform

1.2.4 Deploying the EC2 instance

1.2.5 Destroying the EC2 instance

1.3 Brave new “Hello Terraform!”

1.3.1 Modifying the Terraform configuration

1.3.2 Applying changes

1.4 Fireside chat