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 CHANGEMEUpdate ACLs:
pveum aclmod / -user terraform-prov@pve -role TerraformProvCreate API Credentials
pveum user token add terraform-prov@pve cstacks --privsep=0Update 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=1Import 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.sampletoproviders.tfand (optionally) uncomment the cloudflare section if you want DNS settings (see below). - Copy
terraform.tfvars.sampletoterraform.tfvarsand 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.tfand ensure therequired_providersblock includescloudflare. (There is an example in that file). - Copy
dns_cloudflare.tf.sampletodns_cloudflare.tf. - Generate an api token with Cloudflare that includes write permissions to the domain.
- Add
cloudflare_api_tokenandcloudflare_account_idto yourterraform.tfvarsfile. The Account ID can be found on the main zone overview page in your cloudflare account (scroll down).
terraform initto install required modules.terraform applyto build your servers.