HashiCorp - Terraform Associate Study Guide

    2: Terraform fundamentals

    This chapter explains how Terraform connects HCL configuration to real infrastructure through providers, version constraints, and state. It walks through declaring required providers, the plugin-based architecture that powers every CRUD operation, composing configurations that target several providers at once, and the persistence model that lets Terraform reconcile desired state with what already exists.

    Learning Objectives

    By the end of this chapter, you will be able to:

    • Install Terraform providers, write source addresses against the Terraform Registry, and pin versions with constraint operators.
    • Describe the plugin-based architecture that separates Terraform Core from provider binaries and explain how that boundary shapes operations.
    • Compose HCL that drives multiple providers in a single working directory, including provider aliases, instance selection on resources, and provider passing into modules.
    • Explain what Terraform state is, why it exists, how locking and sensitivity work, and how to inspect or repair state with CLI subcommands.

    Executive Summary

    • Providers are the gRPC plugins that translate HCL into API calls; they are declared in the terraform block under required_providers, downloaded by terraform init, and pinned through the .terraform.lock.hcl dependency lock file.
    • Version constraints (=, >=, ~>, !=, comma-joined ranges) decouple a configuration's compatibility window from any single released version, while the lock file pins exact selections for reproducible runs.
    • A single configuration can target many providers; provider aliases plus the provider = aws.useast1 meta-argument let you split resources across regions, accounts, or clouds inside one working directory.
    • State is the source of truth that maps configuration to real resources, stores metadata that the cloud APIs do not return, and gives plan/apply something to diff against; state must be locked, treated as sensitive, and never edited by hand without using the documented subcommands.

    Assumptions

    • Examples use illustrative providers (random, null, local, plus a generic public-cloud provider) so the material stays focused on Terraform mechanics rather than any single cloud's service catalog.
    • All commands target Terraform 1.12 with the renamed HCP Terraform offering; older naming (Terraform Cloud) is not used in narrative prose except when explicitly contrasting nomenclature.
    • The reader is expected to read HCL fluently after this chapter; the syntax is introduced inline only where a fundamental block first appears.

    Sections in this chapter

    1. Free
    2. Free with account
    3. Free with account
    4. Free with account
    5. Free with account