OpenTofu: A Beginners Guide to a Terraform Fork Including Migration From Terraform

Introduction to Infrastructure as Code

Types of IAC Tools

Before diving into OpenTofu, it’s helpful to understand the three main categories of Infrastructure as Code (IaC) tools. Each category addresses a different stage of the automated infrastructure lifecycle:

CategoryPurposeExamples
Configuration ManagementInstall and manage software on existing resourcesAnsible, Puppet, SaltStack
Server TemplatingBuild immutable VM or container imagesPacker, Vagrant, Docker
Provisioning & OrchestrationDeclaratively provision and manage infrastructureOpenTofu, Terraform, CloudFormation

Configuration Management Tools

Configuration management tools automate the installation and configuration of software on servers, databases, and network devices. They ensure a consistent state across multiple hosts by defining idempotent code that only applies necessary changes.

The image lists types of Infrastructure as Code (IAC) tools, highlighting features like software management, standard structure, version control, and idempotency, alongside logos for Ansible, Puppet, and SaltStack.

Note

Idempotency guarantees that running the same playbook multiple times will not alter resources that are already in the desired state.

Example: An Ansible playbook checks for a package before installing:

- name: Ensure Nginx is installed
  hosts: webservers
  tasks:
    - name: Install Nginx
      apt:
        name: nginx
        state: present

Server Templating Tools

Server templating tools create fully configured, immutable images—such as VM snapshots, AWS AMIs, or Docker containers—that bundle all necessary software and dependencies. By baking the environment beforehand, you eliminate runtime configuration drift.

The image describes types of Infrastructure as Code (IAC) tools, focusing on server templating with examples like Packer, Vagrant, and Docker. It highlights pre-installed software, dependencies, and virtual machine or Docker images.

Key benefits:

  • Consistent deployment artifacts
  • Faster boot times
  • Simplified rollout of updates via new image versions

Provisioning & Orchestration Tools

Provisioning tools—also called orchestration tools—allow you to declare the desired state of your entire infrastructure: servers, databases, networking, and more. The tool then computes and applies only the changes needed to reach that state.

The image describes types of Infrastructure as Code (IAC) tools, focusing on provisioning tools like OpenTofu, CloudFormation, and Terraform, used for deploying immutable infrastructure resources such as servers, databases, and network components.

For example, CloudFormation offers a native AWS experience, whereas OpenTofu (a Terraform fork) supports a broad ecosystem of provider plugins for multi-cloud and hybrid deployments.

Procedural vs. Declarative Provisioning

Configuration management tools can provision resources procedurally. In Ansible, you might write:

- name: Provision AWS Resources
  hosts: localhost
  tasks:
    - name: Launch EC2 instances
      ec2:
        key_name: appserver
        instance_type: t2.micro
        image: ami-0d8ad3ab25e7abc51
        exact_count: 2
        region: us-east-1

To remove instances, you need an explicit task:

    - name: Terminate instances
      ec2:
        state: absent
        instance_ids: '{{ ec2.instance_ids }}'

Warning

Procedural scripts may inadvertently create duplicate resources if you omit repeat protection (exact_count) or forget teardown tasks.

Orchestration tools use a declarative model. In OpenTofu, you simply define:

resource "aws_instance" "app" {
  ami           = "ami-0d8ad3ab25e7abc51"
  instance_type = "t2.micro"
  count         = 2
  key_name      = "appserver"
  tags = {
    Name = "appserver"
  }
}

Running tofu apply ensures the actual infrastructure matches this block:

> tofu apply
No changes. Your infrastructure matches the configuration.
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Choosing the Right IaC Tool

There’s no single best IaC tool. Consider:

  • AWS-only environments: AWS CloudFormation may offer deep native integration.
  • Multi-cloud or hybrid: OpenTofu or Terraform provide vendor-agnostic provisioning.
  • Post-provisioning configuration: Combine orchestration tools with configuration management (e.g., OpenTofu + Ansible).

Watch Video

Watch video content

Previous
Course Objectives