Skip to content

Commit fc14656

Browse files
committed
complete example has been redone
1 parent e90e871 commit fc14656

File tree

4 files changed

+214
-124
lines changed

4 files changed

+214
-124
lines changed

examples/complete/README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Complete Virtual Machine Deployment
22

3-
This example demonstrates how you would deploy a Virtual Machine with multiple network adapters, multiple disks, and using an Ubuntu Cloudinit template.
4-
5-
***NOTE:*** If your Virtual Machine template does ***NOT*** have the Cloudinit drive set to `ide2`, the Terraform provider may fail to provision your Virtual Machine.
3+
This example demonstrates most of the working configurations you can give to a virtual machine. Within `locals.tf`, there's a long list of variables and what said variable does.
64

75
## Step 1. Configure Terraform environment variables
86

@@ -26,13 +24,9 @@ export PM_PASS="proxmox_account_password"
2624

2725
Rename `terraform.tfvars.example` to `terraform.tfvars`. Once renamed, modify the three variables within the file to match your environment.
2826

29-
The values in `terraform.tfvars` illustrate using more than one storage location for your Virtual Machine. If you do **NOT** have multiple storage locations, just set both the values to the same datastore (e.g., local-pve).
30-
3127
## Step 3. Modify Virtual Machine configuration
3228

33-
Once you've populated the required variables in `terraform.tfvars`, you may open `locals.tf` to see all of the settings that you may modify. I've populated the file with three different network adapters, two different disks, and I've started adding Cloudinit settings.
34-
35-
Feel free to play around with these values to get a feel of how to deploy an out-of-ordinary Virtual Machine.
29+
Once you've populated the required variables in `terraform.tfvars`, you may open `locals.tf` to see all of the variables you may modify.
3630

3731
## Step 4. Deploy Virtual Machine
3832

@@ -72,8 +66,7 @@ No resources.
7266
| Name | Description | Type | Default | Required |
7367
|------|-------------|------|---------|:--------:|
7468
| <a name="input_clone"></a> [clone](#input\_clone) | The base VM from which to clone to create the new VM. Note that clone is mutually exclussive with pxe and iso modes. | `string` | n/a | yes |
75-
| <a name="input_storage_location_1"></a> [storage\_location\_1](#input\_storage\_location\_1) | The location of where Disk 1 will be located. | `string` | n/a | yes |
76-
| <a name="input_storage_location_2"></a> [storage\_location\_2](#input\_storage\_location\_2) | The location of where Disk 2 will be located. | `string` | n/a | yes |
69+
| <a name="input_storage_location"></a> [storage\_location](#input\_storage\_location) | The storage location for the Virtual Machine. | `string` | n/a | yes |
7770
| <a name="input_target_node"></a> [target\_node](#input\_target\_node) | The name of the Proxmox Node on which to place the VM. | `string` | n/a | yes |
7871

7972
## Outputs

examples/complete/locals.tf

Lines changed: 180 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,196 @@
11
locals {
22

3-
# Adjust the Virtual Machine's specs here
4-
memory = 1024
5-
cores = 1
3+
# Automatically reboot the VM when parameter changes require this. If disabled the provider will emit a warning when the VM needs to be rebooted.
4+
automatic_reboot = true
65

7-
# Cloudinit Settings
6+
# Override the default cloud-init user's password. Sensitive.
7+
cipassword = "my_password"
8+
9+
# Override the default cloud-init user for provisioning.
810
ciuser = "my_username"
9-
# See the homepage README.md on how to add SSH Keys.
10-
sshkeys = ""
11+
12+
# The base VM from which to clone to create the new VM. Note that clone is mutually exclussive with pxe and iso modes.
13+
clone = var.clone
14+
15+
# The number of CPU cores per CPU socket to allocate to the VM.
16+
cores = 1
17+
18+
# The type of CPU to emulate in the Guest. See the docs about CPU Types for more info. ('host' allows you to virtualize on said VM)
19+
cpu = "host"
20+
21+
# Controls if virtual machine should be created.
22+
create_vm = true
23+
24+
# The description of the VM. Shows as the 'Notes' field in the Proxmox GUI.
25+
description = "Virtual Machine's description"
1126

1227
/*
13-
Disk Configurations
14-
15-
Create 2 Disks
16-
Disk 1 (virtio0):
17-
- Set type to 'virtio'
18-
- Set storage_location_1 variable in terraform.tfvars
19-
- Set size to 10G
20-
Disk 2 (scsi0):
21-
- Set type to 'scsi'
22-
- Set storage_location_2 variable in terraform.tfvars
23-
- Set size to 25G
24-
- Enable writethrough cache
25-
*/
26-
# Set the disk locations in terraform.tfvars
27-
storage_location_1 = var.storage_location_1
28-
storage_location_2 = var.storage_location_2
28+
Disk Configuration
2929
30+
type - The type of disk device to add. Options: ide, sata, scsi, virtio.
31+
storage - The name of the storage pool on which to store the disk.
32+
size - The size of the created disk, format must match the regex \d+[GMK], where G, M, and K represent Gigabytes, Megabytes, and Kilobytes respectively.
33+
format - The drive’s backing file’s data format.
34+
cache - The drive’s cache mode. Options: directsync, none, unsafe, writeback, writethrough
35+
backup - Whether the drive should be included when making backups.
36+
iothread - Whether to use iothreads for this drive. Only effective with a disk of type virtio, or scsi when the the emulated controller type (scsihw top level block argument) is virtio-scsi-single.
37+
replicate - Whether the drive should considered for replication jobs.
38+
discard - Controls whether to pass discard/trim requests to the underlying storage. Only effective when the underlying storage supports thin provisioning.
39+
mbps - Maximum r/w speed in megabytes per second. 0 means unlimited.
40+
mbps_rd - Maximum read speed in megabytes per second. 0 means unlimited.
41+
mbps_rd_max - Maximum read speed in megabytes per second. 0 means unlimited.
42+
mbps_wr - Maximum write speed in megabytes per second. 0 means unlimited.
43+
mbps_wr_max - Maximum throttled write pool in megabytes per second. 0 means unlimited.
44+
media - The drive’s media type. Options: cdrom, disk.
45+
iops - Maximum r/w I/O in operations per second.
46+
iops_rd - Maximum read I/O in operations per second.
47+
iops_rd_max - Maximum unthrottled read I/O pool in operations per second.
48+
iops_rd_max_length - Maximum length of read I/O bursts in seconds.
49+
iops_wr - Maximum write I/O in operations per second.
50+
iops_wr_max - Maximum unthrottled write I/O pool in operations per second.
51+
iops_wr_max_length - Maximum length of write I/O bursts in seconds.
52+
53+
*/
3054
disks = [
31-
# This will create disk virtio0
3255
{
33-
type = "virtio"
34-
storage = local.storage_location_1
35-
size = "10G"
36-
},
37-
# This will create disk scsi0 with writethrough cache enabled
38-
{
39-
type = "scsi"
40-
storage = local.storage_location_2
41-
size = "25G"
42-
cache = "writethrough"
56+
type = "virtio"
57+
storage = var.storage_location
58+
size = "10G"
59+
format = "raw"
60+
cache = "writeback"
61+
backup = true
62+
iothread = 0
63+
replicate = 0
64+
discard = 0
65+
mbps = 0
66+
mbps_rd = 0
67+
mbps_rd_max = 0
68+
mbps_wr = 0
69+
mbps_wr_max = 0
70+
media = "disk"
71+
iops = 0
72+
iops_rd = 0
73+
iops_rd_max = 0
74+
iops_rd_max_length = 0
75+
iops_wr = 0
76+
iops_wr_max = 0
77+
iops_wr_max_length = 0
4378
}
4479
]
4580

81+
# If false, and a vm of the same name, on the same node exists, terraform will attempt to reconfigure that VM with these settings.
82+
# Set to true to always create a new VM (note, the name of the VM must still be unique, otherwise an error will be produced.).
83+
force_create = false
84+
/*
85+
If the value of this string changes, the VM will be recreated. Useful for allowing this resource to be recreated when arbitrary attributes change.
86+
An example where this is useful is a cloudinit configuration (as the cicustom attribute points to a file not the content).
87+
88+
force_recreate_on_change_of = data.template_file.cicustom.rendered
89+
*/
90+
force_recreate_on_change_of = ""
91+
92+
/*
93+
hagroup - The HA group identifier the resource belongs to (requires hastate to be set!).
94+
hastate - Requested HA state for the resource. One of 'started', 'stopped', 'enabled', 'disabled', or 'ignored'. See the docs about HA for more info.
95+
96+
hagroup = "my_resource_group"
97+
hastate = enabled
98+
*/
99+
hagroup = ""
100+
hastate = ""
101+
102+
/*
103+
Comma delimited list of hotplug features to enable. Options: network, disk, cpu, memory, usb. Set to 0 to disable hotplug.
104+
105+
To add memory into hotplug, you would set the variable to:
106+
hotplug = "cpu,memory,network,disk,usb"
107+
*/
108+
hotplug = "cpu,network,disk,usb"
109+
110+
# The amount of memory to allocate to the VM in Megabytes.
111+
memory = 2048
112+
113+
# Sets default DNS server for guest.
114+
nameserver = "example.com"
46115

47116
/*
48-
Create 3 Network Adapters
49-
- All adapters will be assigned model `virtio` and point to network bridge `vmbr0`.
50-
However, you can adjust these values as needed.
51-
- Network Adapter 1 (net0) - Set to DHCP
52-
- Network Adapter 2 (net1) - IP: 192.168.2.58/24 with gateway of 192.168.2.1
53-
- Network Adapter 3 (net2) - Set to DHCP
117+
Network Adapter Configurations
118+
119+
bridge - Bridge to which the network device should be attached. The Proxmox VE standard bridge is called vmbr0.
120+
model - Network Card Model. The virtio model provides the best performance with very low CPU overhead. If your VM does not support it, next best option is e1000
121+
gateway - The IPv4 Gateway of the Virtual Machine. Does NOT need to be in CIDR-notation (e.g., this will work: 192.168.1.1)
122+
gateway6 - The IPv6 Gateway of the Virtual Machine. Does NOT need to be in CIDR-notation.
123+
ip - The IPv4 Address of the Virtual Machine. MUST be in CIDR-notation (e.g., 192.168.1.123/24)
124+
ip6 - The IPv6 Address of the Virtual Machine. MUST be in CIDR-notation.
125+
dhcp - Set dhcp to true to enable dhcp for IPv4 Addresses. This will override static IP assignments.
126+
dhcp6 - Set dhcp6 to true to enable dhcp for IPv6 Addresses. This will override static IP assignments.
127+
firewall - Whether to enable the Proxmox firewall on this network device.
128+
link_down - Whether this interface should be disconnected (like pulling the plug).
129+
macaddr - Override the randomly generated MAC Address for the VM. Requires the MAC Address be Unicast.
130+
queues - Number of packet queues to be used on the device. Requires virtio model to have an effect.
131+
rate - Network device rate limit in mbps (megabytes per second) as floating point number. Set to 0 to disable rate limiting.
132+
vlan_tag - The VLAN tag to apply to packets on this device. -1 disables VLAN tagging.
54133
*/
55-
# Network Adapter net0 IP Configuration
56-
network_adapter_1 = {
57-
dhcp = true
58-
}
59-
network_model_1 = "virtio"
60-
network_bridge_1 = "vmbr0"
61-
62-
# Network Adapter net1 IP Configuration
63-
network_adapter_2 = {
64-
# By default, DHCP is set to False if it isn't provided
65-
ip = "192.168.2.58/24"
66-
gateway = "192.168.2.1"
67-
}
68-
network_model_2 = "virtio"
69-
network_bridge_2 = "vmbr0"
70-
71-
# Network Adapter net2 IP Configuration
72-
network_adapter_3 = {
73-
# By default, DHCP is set to False if it isn't provided
74-
dhcp = true
75-
}
76-
network_model_3 = "virtio"
77-
network_bridge_3 = "vmbr0"
134+
networks = [{
135+
bridge = "vmbr0"
136+
model = "virtio"
137+
gateway = ""
138+
gateway6 = ""
139+
ip = ""
140+
ip6 = ""
141+
dhcp = true
142+
dhcp6 = false
143+
firewall = true
144+
link_down = false
145+
#macaddr = "" # Commented-out as this will generate an error if you do not provide an address.
146+
queues = 1
147+
rate = 0
148+
vlan_tag = -1
149+
}]
150+
151+
# Whether to enable Non-Uniform Memory Access in the guest. Must have 'memory' in hotplug.
152+
numa = false
153+
154+
# Whether to have the VM startup after the PVE node starts.
155+
onboot = true
156+
157+
# Whether to have the VM startup after the VM is created.
158+
oncreate = true
159+
160+
# The resource pool to which the VM will be added.
161+
pool = ""
162+
163+
# The SCSI controller to emulate. Options: lsi, lsi53c810, megasas, pvscsi, virtio-scsi-pci, virtio-scsi-single.
164+
scsihw = "virtio-scsi-pci"
165+
166+
# Sets default DNS search domain suffix.
167+
searchdomain = "example_domain.com"
168+
169+
# The number of CPU sockets for the Master Node.
170+
sockets = 1
171+
172+
/*
173+
Newline delimited list of SSH public keys to add to authorized keys file for the cloud-init user
174+
175+
Example (omitted most of the key to save space):
176+
177+
sshkeys = <<EOF
178+
ssh-rsa AAAAB3NzaC1yc2YcS+LkeTl9JaW/XzZrzGpb5kQhBNXoSXQ== zackshomelab\zack@ZHLDT01
179+
EOF
180+
*/
181+
sshkeys = ""
182+
183+
# Tags of the VM. This is only meta information.
184+
tags = ["tag1", "tag2", "tag3"]
185+
186+
187+
# The name of the Proxmox Node on which to place the VM.
188+
target_node = var.target_node
189+
190+
# The virtual machine name.
191+
vm_name = "vm-name-example"
192+
193+
# The ID of the VM in Proxmox.
194+
# The default value of 0 indicates it should use the next available ID in the sequence.
195+
vmid = 0
78196
}

examples/complete/main.tf

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,33 @@ provider "proxmox" {
55
module "cloudinit_vm" {
66
source = "../../"
77

8-
vm_name = "ubuntu-complete"
9-
target_node = var.target_node
10-
clone = var.clone
11-
12-
onboot = true
13-
14-
# Specs
15-
cores = local.cores
16-
memory = local.memory
17-
18-
# Disk(s)
19-
scsihw = "virtio-scsi-pci"
20-
21-
disks = local.disks
22-
23-
# Network Cards
24-
networks = [
25-
# This will create Network Adapter net0
26-
{
27-
model = local.network_model_1
28-
bridge = local.network_bridge_1
29-
},
30-
31-
# This will create Network Adapter net1
32-
{
33-
model = local.network_model_2
34-
bridge = local.network_bridge_2
35-
},
36-
37-
# This will create Network Adapter net2
38-
{
39-
model = local.network_model_3
40-
bridge = local.network_bridge_3
41-
}
42-
]
43-
44-
# IP Configuration for net0
45-
ipconfig0 = local.network_adapter_1
46-
ipconfig1 = local.network_adapter_2
47-
ipconfig2 = local.network_adapter_3
48-
49-
50-
# Cloudinit settings
51-
ciuser = local.ciuser
52-
sshkeys = local.sshkeys != null ? local.sshkeys : null
8+
automatic_reboot = local.automatic_reboot
9+
cipassword = local.cipassword
10+
ciuser = local.ciuser
11+
clone = local.clone
12+
cores = local.cores
13+
cpu = local.cpu
14+
create_vm = local.create_vm
15+
description = local.description
16+
disks = local.disks
17+
force_create = local.force_create
18+
force_recreate_on_change_of = local.force_recreate_on_change_of
19+
hagroup = local.hagroup
20+
hastate = local.hastate
21+
hotplug = local.hotplug
22+
memory = local.memory
23+
nameserver = local.nameserver
24+
networks = local.networks
25+
numa = local.numa
26+
onboot = local.onboot
27+
oncreate = local.oncreate
28+
pool = local.pool
29+
scsihw = local.scsihw
30+
searchdomain = local.searchdomain
31+
sockets = local.sockets
32+
sshkeys = local.sshkeys
33+
tags = local.tags
34+
target_node = local.target_node
35+
vm_name = local.vm_name
36+
vmid = local.vmid
5337
}

examples/complete/variables.tf

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
variable "storage_location_1" {
2-
description = "The location of where Disk 1 will be located."
3-
type = string
4-
}
5-
6-
variable "storage_location_2" {
7-
description = "The location of where Disk 2 will be located."
1+
variable "storage_location" {
2+
description = "The storage location for the Virtual Machine."
83
type = string
94
}
105

0 commit comments

Comments
 (0)