Skip to main content
In this lesson we recap how to install OpenTofu and introduce the basics of HashiCorp Configuration Language (HCL). You’ll learn how to get the OpenTofu binary on your PATH, what HCL resource blocks look like, and the core OpenTofu workflow for provisioning resources.
OpenTofu binaries are distributed as pre-built releases for multiple platforms (Linux, macOS, Solaris, OpenBSD). After placing the binary in a directory on your PATH, verify installation with tofu version before proceeding to provisioning.

Install the OpenTofu CLI

Downloading and installing OpenTofu is typically a matter of fetching the release archive for your platform, extracting the binary, and moving it into a directory on your PATH. For example, on a Linux amd64 host:
Example output:
Once the binary responds to tofu version, you’re ready to write HCL and provision infrastructure.

HCL (HashiCorp Configuration Language) basics

OpenTofu configuration files use HCL and typically have the .tf extension. HCL is declarative and organized with blocks and arguments:
  • Blocks declare infrastructure elements (for example: provider, resource, module).
  • Arguments within blocks are key = value pairs that configure the block.
A simple example that creates a local file (save as local.tf):
Key points:
  • Blocks are delimited by { ... }.
  • The resource block begins with the keyword resource, followed by the resource type and a resource name.
    • Resource type here is "local_file". The portion before the underscore (local) indicates the provider; the portion after (file) is the resource kind.
    • "pet" is a logical name you choose to reference the resource in your configuration.
  • Inside the block, filename and content are arguments specific to the local_file resource.
Another example (S3 bucket):
The structure is identical: resource keyword → resource type (aws_s3_bucket) → resource name (data) → provider-specific arguments. What is a resource?
  • A resource is an object OpenTofu manages. Examples include local files, compute instances (EC2), cloud storage (S3), IAM users, serverless functions, and more. OpenTofu supports many resource types exposed by community and vendor providers.
How do you know which arguments a resource supports?
  • OpenTofu reuses providers compatible with Terraform. Consult the provider documentation in the Terraform Registry for the full resource catalog and argument details:
Each provider maintains its own resource catalog and argument set (AWS, GCP, Azure, etc.), so consult the provider docs when authoring configurations.
A diagram comparing cloud providers that maps a "Provider" to "Resource_type" and corresponding "Arguments," with AWS and Google Cloud service icons shown in separate columns. The left side shows the provider/resource/arguments flow while the middle and right display example AWS and GCP resource icons.

Core OpenTofu workflow

A typical OpenTofu workflow has four main steps:
  1. Write one or more configuration files (*.tf).
  2. Initialize the working directory with tofu init.
  3. Review the execution plan with tofu plan.
  4. Apply the changes with tofu apply.
Table: Common OpenTofu commands

Initialize the directory

Using the local_file example, first initialize:
Example output (truncated):
tofu init detects referenced providers and downloads the provider plugins needed to execute your configuration.

Plan: preview changes

Preview actions with:
Example plan output (truncated):
  • The + indicates resources that will be created.
  • The plan shows both declared arguments and computed attributes (e.g., file permissions).
Remember: tofu plan only shows what will happen; it does not change anything.

Apply: make changes

When you’re satisfied with the plan, apply it:
You will be shown the plan again and prompted to confirm. Type yes to proceed. Example interactive session (truncated):
You can bypass the confirmation prompt with:
Use -auto-approve carefully. It bypasses the confirmation prompt and will immediately apply whatever actions are in the plan. As a best practice, always review the plan before applying changes.

Inspecting state

After applying, inspect the latest state:
Example tofu show output for the local file (truncated and reformatted):

Additional resources

To recap:
  • Use resource blocks to declare infrastructure objects.
  • Inside resource blocks, use provider-specific arguments to define resource behavior.
  • Run tofu init, tofu plan, and tofu apply to provision resources; use tofu show to inspect state.
  • Always review the execution plan before applying changes.
That’s it for this lesson. A future lesson will cover providers and provider plugins in more detail.

Watch Video