Terraform configurations for provisioning homelab VMs.
(Optional) Set up API access to Proxmox if you do not wish to use cluster admin to execute tasks. Follow the Telmate Proxmox Terraform Provider Docs.
Set up sensitive PVE connection variables using pve.hvl.sample
as a reference.
Initialize the configuration directory to download and install the providers defined in the configuration:
terraform init
Format your configurations. Terraform will print out the names of the files it modified, if any:
terraform fmt
Make sure your configuration is syntactically valid and internally consistent
terraform validate
Execute a dry run to verify configuration and see what would be done before executing apply:
terraform plan
Apply the plan and provision infrastructure as declared in configurations:
terraform apply
Note: use the -auto-approve
flag to skip interactive approval of plan before applying.
Unprovision infrastructure as declared in configurations:
terraform destroy
Using -compact-warnings
flag will compact output, but still outputs errors in full.
Any resources defined in main.tf
can be targeted by using -target="<RESOURCE>.<RESOURCE NAME>"
.
For example, target base-infra
module:
terraform apply -target=module.base-infra
main.tf # Main file used by Terraform commands
variables.tf # Global variables
modules/ # Reusable modules
pve-vm/ # Proxmox VE VM provisioning template module
envs/ # Environments dir
prod/ # Production infra definitions
base-infra/ # Base infrastructure needed for services
vars.tf # Input variables
outputs.tf # Output variables
main.tf # Resources to be provisioned using modules
service-infra/ # Services infrastructure
dev/ # Development infra definitions
dev-vm/ # Development VM