Skip to content

Infrastructure as Code (OpenTofu/Terraform)

[TODO] update to tofu and add good practices, add short info about each project

We use OpenTofu (open-source Terraform fork) for Infrastructure-as-Code (IaC) deployment and management.

Status: In Transition

This section is being updated as we transition from Terraform to OpenTofu. The commands and concepts are largely the same.


Installation

Install Terraform

Install Terraform using Homebrew:

brew tap hashicorp/tap
brew install hashicorp/tap/terraform

Verify Installation

Check the installed version:

terraform version

Getting Started

Clone the IaC Repository

Clone the infrastructure repository (replace with actual repo URL):

git clone https://github.com/majority-dev/dt-infrastructure.git
cd dt-infrastructure

Project Structure

Typical structure:

infrastructure/
├── environments/
│   ├── dev/
│   ├── stage/
│   └── prod/
├── modules/
│   ├── bigquery/
│   ├── storage/
│   └── compute/
├── variables.tf
├── main.tf
└── outputs.tf


Basic Workflow

1. Navigate to Environment

cd /path/to/your/terraform/project

2. Initialize Terraform

Initialize the Terraform project (download providers and modules):

terraform init

This will: - Download required provider plugins - Initialize the backend - Set up module dependencies

3. Plan Changes

Preview what resources Terraform will create or modify:

terraform plan

Review the output carefully: - + indicates resources to be created - ~ indicates resources to be modified - - indicates resources to be deleted

4. Apply Changes

Apply the configuration to create or update resources:

terraform apply

Terraform will: 1. Show you the plan again 2. Ask for confirmation (type yes) 3. Execute the changes 4. Show you the results