TExcelTAD
Home › Infrastructure as Code: Terraform & OpenTofu › What Terraform & OpenTofu Are

What Terraform & OpenTofu Are

The AWS course taught you what a VPC, a subnet, a security group and an RDS instance are, and its CloudFormation and CDK lesson showed AWS's own way to describe them in files. This course does the same job with the tool most teams use for it, across every cloud: Terraform, and its open-source fork OpenTofu.

You write .tf files in HCL (HashiCorp Configuration Language) that say what should exist. The CLI compares that with what it created last time, shows you a plan of the difference, and after you approve it, calls the cloud's API to make the plan real. The idea of declarative, idempotent infrastructure is introduced in Infrastructure as Code & Immutable Infrastructure; here you learn to do it for real.

hcl
resource "aws_s3_bucket" "logs" {
  bucket = "linkly-logs-staging"
  tags   = { team = "platform" }
}

The pieces

Piece What it is
Configuration your .tf files: resources, variables, outputs, modules
Provider a plugin (a separate binary) that knows one API: aws, kubernetes, helm, random, …
State a JSON file mapping each resource in your code to the real object it created (terraform.tfstate)
Backend where the state lives: a local file, or shared storage such as S3
Plan the list of creates, updates and deletes needed to make reality match the code
Module a folder of .tf files you call like a function, with inputs and outputs

The CLI itself knows nothing about AWS. init downloads the providers your code asks for; every other command talks to them over a local plugin protocol. That is why one tool can manage AWS, Azure, Kubernetes, GitHub repositories, DNS records and TLS keys in one plan.

Terraform and OpenTofu

HashiCorp released Terraform in 2014 under the open-source MPL 2.0 licence. In August 2023 it moved new versions (1.6 onwards) to the Business Source License, which restricts using Terraform in products that compete with HashiCorp. Several companies forked the last MPL version as OpenTofu, now a Linux Foundation project, with its first stable release in January 2024. HashiCorp itself is now part of IBM.

For a learner the two are close to interchangeable:

Terraform 1.17 OpenTofu 1.13
command terraform tofu
licence BUSL 1.1 (free for your own infrastructure) MPL 2.0 (open source)
language HCL the same HCL, plus a few extras (e.g. .tofu files)
providers registry.terraform.io registry.opentofu.org (the same provider releases)
unique features HCP Terraform integration, terraform stacks state encryption, -exclude, provider for_each, early variable evaluation

The OpenTofu lesson covers the differences in detail. Both binaries are in this course's sandbox:

bash · try it yourself
tofu version
terraform version
OpenTofu v1.13.2
on linux_amd64
Terraform v1.17.0
on linux_amd64

How the sessions in this course work

Every bash run block is a real session, verified in a fresh container with no network:

  • Providers come from a local mirror holding exactly seven: null, local, random, tls, aws, kubernetes and helm.
  • Resources of the local providers (local_file, random_*, tls_private_key, terraform_data) really get created, so you see plan, apply, state and drift for real.
  • AWS code is checked with validate, fmt, graph, console and tests that use a mocked AWS provider, and planned offline with dummy credentials. Applying it, and remote backends such as S3, need an AWS account, so those are shown as sample sessions (plain bash blocks) with realistic output.
  • Colour is switched off.

The course uses tofu as its main CLI. Every command has the same name in Terraform: replace tofu with terraform and "OpenTofu" with "Terraform" in the messages. Where the two really differ, the lesson shows both.

The same files work with both CLIs. Here each one plans the same configuration:

bash · try it yourself
mkdir demo && cd demo
cat > main.tf <<'HCL'
resource "terraform_data" "hello" {
  input = "same code, two CLIs"
}
HCL
tofu init >/dev/null && tofu plan | grep -E '^(OpenTofu|Plan)'
rm -rf .terraform*
terraform init >/dev/null && terraform plan | grep -E '^(Terraform|Plan)'
OpenTofu used the selected providers to generate the following execution
OpenTofu will perform the following actions:
Plan: 1 to add, 0 to change, 0 to destroy.
Terraform used the selected providers to generate the following execution
Terraform will perform the following actions:
Plan: 1 to add, 0 to change, 0 to destroy.

terraform_data is a resource built into the CLI itself (no provider download), handy for examples and for triggering replacements.

What you will build

The course follows the roadmap's Phase 5.2: HCL basics, state and remote backends, environments, modules, the AWS network and database from the AWS course written as code, a pipeline that plans on every pull request and applies on merge, and OpenTofu's extras. The Mini Project ends with a VPC + database module applied to two environments from a pipeline, which is the IaC part of the DevOps Capstone.

Test yourself

What does a Terraform provider do?

  1. Stores the state file
  2. Translates resources in your code into calls to one API, such as AWS
  3. Runs the plan in the cloud
  4. Formats HCL files

What did HashiCorp change in August 2023 that led to OpenTofu?

  1. It removed HCL
  2. It moved Terraform from MPL 2.0 to the Business Source License
  3. It stopped publishing providers
  4. It made state remote-only

You see tofu plan in a lesson but use Terraform. What do you run?

  1. terraform plan
  2. terraform tofu plan
  3. Nothing: Terraform cannot read the same files
  4. tofu is required