chapter two

2 Terraform HCL components

 

This chapter covers

  • How to configure a Workspace and its Providers
  • The basic syntax of Terraform Blocks
  • How to lookup data with Data Source
  • Managing infrastructure with Resource blocks
  • Changing the behavior of Resources with Meta Arguments
  • Using Modules for reusable components

In the last chapter we talked a bit about Terraform and Declarative languages. Using Terraform’s Declarative Language you define how you want your systems to look, and then Terraform builds and updates your systems based on that language. One way to look at it is to compare it to construction; an architect creates a plan and then a construction team builds it based on that plan. In this scenario, you’re the systems architect and Terraform is your construction crew.

In this chapter, we’re going to talk about how to define those plans. Just like construction workers, Terraform has its own language that it reads and interprets to build things. In this case, we’re not creating buildings, but rather systems of interconnected resources hosted by vendors such as Cloud Providers like AWS, GCP, or Azure. As the systems grow and evolve the “blueprints” can be updated, which then allows Terraform to upgrade the running systems until they line up with those blueprints.

2.1 Hello World

2.1.1 Research and Design

2.1.2 Create Project

2.1.3 Setup Providers

2.1.4 Get Our Configuration Values

2.1.5 Create Instance

2.1.6 Run Workspace

2.2 Block Syntax

2.2.1 Block Types

2.2.2 Labels and Subtypes

2.2.3 Arguments and Subblocks

2.2.4 Attributes

2.2.5 Ordering

2.2.6 Style

2.3 Terraform Settings

2.3.1 Backend and Cloud Blocks

2.3.2 Experiments

2.4 Providers

2.4.1 Provider Registry

2.4.2 Required Providers

2.4.3 Provider Configuration

2.4.4 Provider Aliases

2.5 Resources

2.5.1 Resource Usage

2.6 Data Sources

2.7 Meta Arguments

2.7.1 Providers

2.7.2 Lifecycle

2.7.3 Explicit Dependencies

2.8 Modules

2.9 Import and Moved

2.10 Summary