how/workflow
What Terraform does on each command. The three sources of truth (HCL, state, the cloud), how they line up and drift apart, and why apply without plan is a bad habit.
Terraform is a machine that keeps three copies of one idea in agreement:
terraform.tfstate) is what Terraform thinks about reality. Its own cache.The lifecycle is four commands, each working with its own set of these three sources. In the first tutorial lesson you run them in order against a single S3 bucket in LocalStack (see tf-init, tf-plan, tf-apply, tf-destroy). Press ▶ to see what happens behind each command.
A project folder with one file, main.tf. It describes
two resources: an S3 bucket and a random suffix for its name.
State is empty. The cloud is empty. Terraform has not seen either one yet. The commands below run in order.
recap
What to remember:
init runs once per project (and after changing the provider or backend). It downloads plugins and creates .terraform.lock.hcl.plan changes nothing. Run it as often as you like. Between refresh and diff everything happens in your head and in RAM, not in the cloud.apply is the only command that actually creates anything. It is also the only one that touches state.apply, a repeat plan must show No changes. If it shows changes, that is [[drift|drift]], and you go investigate.destroy is symmetric to apply: the state empties, the cloud empties. A mirror.Next: tf-state-anatomy on what lives inside state, and tf-drift on how HCL and the cloud drift apart.