My OpenTofu homelab infrastructure
This project uses OpenTofu to manage the infrastructure.
Overview
This OpenTofu configuration manages various self-hosted services primarily as Docker/Podman containers. The goals are:
- Reproducibility: Easily set up or replicate the homelab environment.
- Version Control: Track all infrastructure changes using Git.
- Automation: Automate the provisioning and management of services.
- Modularity: Organize infrastructure into reusable and understandable components.
Prerequisites
Before you begin, ensure you have the following installed and configured:
- OpenTofu: Version
1.6.0or higher. Installation Guide - Git: For version control.
- Docker/Podman: to host containers.
Project Structure
The project is organized as follows:
homelab/
├── .gitignore # Files and directories to ignore
├── README.md # This file
├── main.tf # Root module: orchestrates module calls
├── variables.tf # Root module: global input variables
├── outputs.tf # Root module: global outputs
├── providers.tf # Root module: provider configurations
├── modules/ # Local modules for different components
├───┐
│ ├── 00-globals/ # Optional: Global data sources/locals
│ ├── 01-networking/
│ │ ├── docker-network/
│ ├── 10-generic/
│ │ └── docker-service/ # Generic module for deploying Docker containers
│ └── 20-services-entertainment/ # Application-specific wrapper modules
│ ├── jellyfin/
│ └── ... # Other application modules
│
└── services/ # Application services (Docker containers)
Configuration
-
Clone the repository:
git clone https://github.com/yurisasc/homelab.git cd homelab -
Create a
.envfile: Copy all.env.examples to.env:cp .env.example .envEdit
.envto set your specific values. This file is included in.gitignoreby default as it's expected to contain secrets. They exist in
Usage
Make sure you are in the root directory of the project (homelab/).
-
Initialize OpenTofu: This downloads the necessary provider plugins. Run this once when you first set up the project or when you add/change providers or modules.
tofu init -
Plan Changes: This command shows you what OpenTofu will do to reach the desired state defined in your configuration files. Review the plan carefully.
tofu plan -
Apply Changes: This command applies the changes outlined in the plan. You will be prompted for confirmation.
tofu apply -
View Outputs: If you have defined outputs in
outputs.tfor in your modules, you can view them:tofu output -
Destroy Infrastructure (Use with Extreme Caution!): This command will attempt to destroy all resources managed by this OpenTofu configuration.
tofu destroy