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
initonce per working directory or whenever providers or backends change, optionally runvalidateandfmt, then iterateplanandapplyuntil the proposed change set is empty. initis 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 beforeinitsucceeds in a working directory.validateruns entirely offline against the configuration graph;plandoes the network work of refreshing state and computing a diff;applyis the only subcommand other thandestroythat mutates real infrastructure.terraform fmtis 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 fictionalacmecloud 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.
