Skip to content

OpenTofu

OpenTofu (a fork of Terraform) is used to deploy infrastructure in my Homelab. Resources located in terraform are used to deploy VMs on my Proxmox VE cluster.

Custom Module(s)

My Home-Ops project contains three OpenTofu modules I've created. The only active one is proxmox_cloud_init_config which I use to create a Cloud-init configuration file for each VM. I previously used the proxmox_vm module but I've found that it doesn't provide enough flexibility for me anymore so I've deprecated it.

OpenTofu State

The OpenTofu state is stored in a Backblaze S3 bucket.

🔒 Secrets

The 1Password Terraform provider is used to retrieve credentials for Proxmox and an SSH key used during VM creation.

Usage

  1. Install OpenTofu:

    brew install opentofu
    
  2. Initialize OpenTofu providers and the S3 backend:

    cd terraform
    op run --env-file=./.env -- tofu init
    
  3. Plan the deployment:

    op run --env-file=./.env -- tofu plan
    
  4. If everything looks good, apply the deployment:

    op run --env-file=./.env -- tofu apply
    

Destroying Specific Resources

To destroy specific resources, use the tofu destroy command with the -target flag:

op run --env-file=./.env -- tofu destroy -target module.proxmox_vm_control01 -target module.proxmox_vm_worker01 -target module.proxmox_vm_worker02

Removing State for Manually Destroyed Resources

If resources are manually destroyed, the state file will need to be updated to reflect the changes to the infrastructure. To do this, use the tofu state rm command:

op run --env-file=./.env -- tofu state rm 'module.proxmox_vm_worker02'