1 A brief overview of Terraform

 

This chapter covers

  • Infrastructure as code
  • Basic Terraform components
  • Declarative languages and graphs
  • The Terraform deployment workflow
  • The relationship between Terraform and OpenTofu

The first time I set up an Amazon Web Services (AWS) virtual private cloud (VPC; the abstraction AWS uses to isolate networks), it was done by hand, and it took me several days. Even after I gained experience with the system, it still took several hours to manually create and configure a VPC that followed the suggested best practices.

When I first discovered Terraform, I attempted to build a VPC again. Terraform was the first infrastructure as code tool I had used: Terraform promised to let me define infrastructure, such as VPCs, using a simple programming language and then let Terraform handle creating the infrastructure itself. Instead of creating it manually, I wrote code using the Terraform language to describe my VPC and all of the components that it needed.

When I first ran the code, I was blown away. Terraform launched over 70 resources needed to create that highly available VPC structure, and it did it in about a minute. From then on, whenever I needed a VPC, it was a simple matter of reusing that code. A task that previously took hours was now an afterthought. Just as importantly, that task was suddenly easy.

1.1 Infrastructure as code

1.1.1 Software development practices with IaC

1.1.2 Repeatability and shareability

1.1.3 Continuous integration and deployment

1.2 Terraform overview

1.2.1 Terraform language

1.2.2 Terraform CLI and core

1.2.3 Providers

1.2.4 Vendors

1.2.5 Backends

1.2.6 Workspaces

1.3 Declarative languages

1.3.1 Declarative vs. imperative languages

1.3.2 Dependency resolution

1.3.3 Pitfalls of declarative languages

1.4 Terraform deployment flow

1.4.1 Change desired

1.4.2 Init

1.4.3 Plan

1.4.4 Apply

sitemap