SSH into the proxmox host and run:
Create the User and permissions
pveum role add TerraformProv -privs "Datastore.AllocateSpace Datastore.Audit Pool.Allocate Sys.Audit VM.Allocate VM.Audit VM.Clone VM.Config.CDROM VM.Config.CPU VM.Config.Cloudinit VM.Config.Disk VM.Config.HWType VM.Config.Memory VM.Config.Network VM.Config.Options VM.Monitor VM.PowerMgmt Sys.Console Sys.Modify VM.Migrate SDN.Use"
Set the password: This won't be used.
pveum user add terraform-prov@pve --password CHANGEME
Update ACLs:
pveum aclmod / -user terraform-prov@pve -role TerraformProv
Create API Credentials
pveum user token add terraform-prov@pve cstacks --privsep=0
Update the terraform.tfvars
values as follows:
proxmox_api_token_id => full-tokenid
proxmox_api_token_secret => value
Are you using a self-signed certificate for proxmox? If yes, also adjust proxmox_insecure_ssl
to true.
SSH into the proxmox host and run the following commands, while taking care to change the following values to match your environment:
Name
: Replacetmpl-debian-12
.ID
: Replace999
.Disk Location
: Replacelocal-lvm
.Network Bridge
: Replacevmbr0
.
wget https://f.cscdn.cc/file/cstackscdn/machine-images/debian-12-computestacks.qcow2
qm create 999 --name tmpl-debian-12 \
--net0 virtio,bridge=vmbr0 \
--ostype l26 \
--cpu host \
--boot c \
--bootdisk scsi0 \
--serial0 socket \
--vga serial0 \
--agent enabled=1
Import the disk and convert the virtual machine to a template.
qm importdisk 999 debian-12-computestacks.qcow2 local-lvm
qm set 999 --scsihw virtio-scsi-single \
--scsi0 local-lvm:vm-999-disk-0,discard=on,iothread=1,ssd=1 \
--ide2 local-lvm:cloudinit
qm template 999
- Copy
providers.tf.sample
toproviders.tf
and (optionally) uncomment the cloudflare section if you want DNS settings (see below). - Copy
terraform.tfvars.sample
toterraform.tfvars
and add all required parameters. (You can see a list of all available options and help text in the filevariables.tf
).
We have provided an example cloudflare file (dns_cloudflare.tf.sample
) that you can use to automate the provisioning of DNS records. You may also use that as a guide for use with your dns provider of choice. Alternatively, this terraform package will output the required DNS settings to result/dns_settings.txt
after provisioning.
To enable automated cloudflare dns configuration:
- Edit
providers.tf
and ensure therequired_providers
block includescloudflare
. (There is an example in that file). - Copy
dns_cloudflare.tf.sample
todns_cloudflare.tf
. - Generate an api token with Cloudflare that includes write permissions to the domain.
- Add
cloudflare_api_token
andcloudflare_account_id
to yourterraform.tfvars
file. The Account ID can be found on the main zone overview page in your cloudflare account (scroll down).
terraform init
to install required modules.terraform apply
to build your servers.