Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
HashiCorp · Terraform 004

The core workflow: init, plan, apply

Terraform 004 · Lesson 4 of 18 · 22:51

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the HashiCorp Terraform Associate (004) exam. In this lesson: the write, plan, and apply workflow, what terraform init sets up, how to read a plan and its symbols, saved plans, and what terraform apply does to the infrastructure and the state. Includes three original practice questions, with Bluefin Logistics, a fictional parcel delivery company, as the example.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

A first real change

Bluefin's platform team is ready for its first real change: a storage bucket for delivery photos, written in a configuration file. Every Terraform change follows the same core workflow, from writing the code to changing the infrastructure. This lesson covers that workflow, then the three commands at its heart: terraform init, terraform plan, and terraform apply.

The core workflow

The core workflow has three steps: write, plan, and apply. Write means authoring the infrastructure as code, in configuration files, usually kept in a Git repository. Plan means previewing the changes that Terraform will make, before anything happens to the infrastructure. Apply means making those changes, after which Terraform updates its state. In a team, each change is written on a branch, its plan is reviewed in a pull request, and it is applied only after approval, a flow that HCP Terraform can run for you.

terraform init

terraform init is the first command to run in a new working directory, and it is always safe to run it again. It initializes the backend, where the state is kept, and downloads the modules that the configuration calls, into the dot terraform directory. It also installs the providers, and creates or checks the dependency lock file. Run it again whenever you add or change a provider, a module, or the backend: until you do, terraform plan stops with an error. And its options include upgrade, for newer versions, and reconfigure and migrate state, for a changed backend.

terraform plan

terraform plan creates an execution plan, and changes nothing. It refreshes the state from the real objects, compares them with the configuration, and lists the actions that would make them match. Each action has a symbol: a plus to create, a tilde to update in place, a minus to destroy, and minus plus to destroy and then create a replacement. The out option saves the plan to a file: a saved plan, which you can apply later, exactly as it was reviewed. Behind the scenes, Terraform builds a graph of the resources, and works on up to ten of them in parallel by default.

terraform apply

terraform apply makes the changes. Without a plan file, it first creates a new plan, shows it, and waits for you to confirm by typing yes. The auto approve option skips that confirmation, which suits automation, but removes your last chance to review. With a saved plan file, terraform apply carries out that plan without asking, since it was already reviewed. And if an error stops an apply halfway, what was done stays done and is written to the state: Terraform does not roll back, so you fix the cause and apply again.

Recap

Let's recap. The core workflow is write, plan, and apply, and in a team, the plan is reviewed before anything is applied. The init command prepares the working directory, with the backend, modules, providers, and lock file, and runs again after any of them changes. The plan command refreshes the state, compares it with the configuration, and shows the actions, which the out option can save. And the apply command asks you to confirm, unless you pass auto approve or a saved plan, and it never rolls back on its own.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. Bluefin's team keeps its configuration in Git and reviews every change in a pull request. What should reviewers check before the change is applied?

    • The state file from the last apply
    • Only the formatting of the code
    • The resources in the cloud console
    • The plan output for the change
    Show the answer

    The plan output for the change

    The plan shows exactly what Terraform will create, change, or destroy, which is what reviewers need to approve. “The state file from the last apply” is wrong, because the state describes the infrastructure before this change. “Only the formatting of the code” is wrong, because formatting says nothing about what will happen. And “The resources in the cloud console” is wrong, because the console shows what exists today, not what the change will do.

  2. An engineer adds a module block for a new registry module, then runs terraform plan: it stops, because the module is not installed. Which command should run first?

    • terraform validate
    • terraform init
    • terraform apply -auto-approve
    • terraform fmt -recursive
    Show the answer

    terraform init

    Terraform init downloads the modules that the configuration calls, and it must run again after a module is added. “terraform validate” would check the configuration, but it installs nothing. “terraform apply -auto-approve” would stop with the same error, and it would also skip the confirmation. And “terraform fmt -recursive” only rewrites the layout of the files, in every subdirectory.

  3. An engineer runs terraform plan -out=photos.tfplan, the team reviews the plan, then the engineer runs terraform apply photos.tfplan. What happens?

    • It builds a new plan and asks for yes
    • It shows the plan and changes nothing
    • It applies that plan without a prompt
    • It only checks the configuration syntax
    Show the answer

    It applies that plan without a prompt

    Terraform carries out the saved plan without asking for confirmation, because it was already reviewed. “It builds a new plan and asks for yes” is how apply behaves without a plan file. “It shows the plan and changes nothing” is a description of terraform plan, not apply. And “It only checks the configuration syntax” is a description of terraform validate.