2 Terraform HCL components

 

This chapter covers

  • How to configure a workspace and its providers
  • The basic syntax ofterraform blocks
  • How to look up data with data sources
  • 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 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 Creating the project

2.1.3 Setup providers

2.1.4 Getting our configuration values

2.1.5 Creating an instance

2.1.6 Running Terraform

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