HashiCorp - Terraform Associate Study Guide

    3: Core Terraform workflow

    This chapter walks through the day-to-day commands that turn a working directory of HCL into running infrastructure: writing configuration, initializing the directory, validating syntax offline, generating and reading execution plans, applying changes against real providers, tearing infrastructure down, and keeping files canonically formatted. The focus is on the exact subcommand surface tested on Terraform Associate (004), the flags that change behavior, and the mistakes that bite practitioners at the CLI.

    Learning Objectives

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

    • Describe the Terraform workflow (Write -> Plan -> Apply)
    • Initialize a Terraform working directory (terraform init)
    • Validate a Terraform configuration (terraform validate)
    • Generate and review an execution plan (terraform plan)
    • Apply changes to infrastructure (terraform apply)
    • Destroy Terraform-managed infrastructure (terraform destroy)
    • Apply formatting and style adjustments (terraform fmt)

    Executive Summary

    • The core workflow is a strict pipeline: author HCL, run init once per working directory or whenever providers or backends change, optionally run validate and fmt, then iterate plan and apply until the proposed change set is empty.
    • init is the only subcommand that contacts the registry to download providers and modules, configures the backend, and writes .terraform.lock.hcl; nothing else in the workflow can run before init succeeds in a working directory.
    • validate runs entirely offline against the configuration graph; plan does the network work of refreshing state and computing a diff; apply is the only subcommand other than destroy that mutates real infrastructure.
    • terraform fmt is non-functional but reorganizes whitespace and alignment in place; running it as part of pre-commit and CI keeps diffs reviewable and prevents stylistic noise from masking semantic changes.

    Assumptions

    • Examples target generic providers (random, local, null) and a fictional acme cloud where a concrete cloud resource is needed; the workflow is provider-agnostic.
    • Commands are shown for an interactive shell on Linux or macOS; PowerShell behavior is identical for the subcommands covered.
    • Terms defined in earlier chapters (provider, dependency lock file, state, backend, drift, refresh) are reused without redefinition.

    Sections in this chapter

    1. Free
    2. Free with account
    3. Free with account
    4. Free with account
    5. Free with account
    6. Free with account
    7. Free with account
    8. Free with account