💡 Introduction
OpenTofu is an open-source fork of Terraform.
It allows full automation of server provisioning even in your local machine—not just cloud infrastructure.
In this guide, we automate:
All using OpenTofu and null_resource.
This is perfect for:
🔧 Prerequisites
Ubuntu machine (local, VM, or cloud)
Install OpenTofu:
sudo apt update -y
sudo apt upgrade -y
sudo snap install --classic opentofu
📁 Project Setup
mkdir tofu-docker-wordpress
cd tofu-docker-wordpress
nano main.tf
🧱 OpenTofu Code (main.tf)
terraform {
required_providers {
null = {
source = "hashicorp/null"
}
}
}
###############################
# 1) INSTALL DOCKER + COMPOSE
###############################
resource "null_resource" "install_docker" {
provisioner "local-exec" {
command = <<-EOT
echo "--- Updating system ---"
# Add Docker's official GPG key:
sudo apt update -y
sudo apt install ca-certificates curl -y
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <
OpenTofu is an open-source fork of Terraform.
It allows full automation of server provisioning even in your local machine—not just cloud infrastructure.
In this guide, we automate:
- Docker installation
- Docker Compose installation
- Creating volumes + networks
- Deploying a full WordPress + MySQL stack
- Starting the containers
All using OpenTofu and null_resource.
This is perfect for:
- DevOps practice
- Local development setup
- CI/CD environments
- Rapid application testing
🔧 Prerequisites
Ubuntu machine (local, VM, or cloud)
Install OpenTofu:
sudo apt update -y
sudo apt upgrade -y
sudo snap install --classic opentofu
📁 Project Setup
mkdir tofu-docker-wordpress
cd tofu-docker-wordpress
nano main.tf
🧱 OpenTofu Code (main.tf)
terraform {
required_providers {
null = {
source = "hashicorp/null"
}
}
}
###############################
# 1) INSTALL DOCKER + COMPOSE
###############################
resource "null_resource" "install_docker" {
provisioner "local-exec" {
command = <<-EOT
echo "--- Updating system ---"
# Add Docker's official GPG key:
sudo apt update -y
sudo apt install ca-certificates curl -y
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <