-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
97 lines (83 loc) · 2.69 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
terraform {
required_version = ">=1.5.0"
required_providers {
proxmox = {
source = "bpg/proxmox"
version = ">=0.53.1"
}
}
}
provider "proxmox" {
endpoint = var.pve_api_url
api_token = "${var.pve_token_id}=${var.pve_token_secret}"
insecure = false
}
# Create Single VM
module "vm_minimal_config" {
source = "github.com/trfore/terraform-bpg-proxmox//modules/vm-clone"
node = "pve" # required
vm_id = 100 # required
vm_name = "vm-example-minimal" # optional
template_id = 9000 # required
ci_ssh_key = "~/.ssh/id_ed25519.pub" # optional, add SSH key to "default" user
}
output "id" {
value = module.vm_minimal_config.id
}
output "public_ipv4" {
value = module.vm_minimal_config.public_ipv4
}
# Create Multiple VMs
module "vm_multiple_config" {
source = "github.com/trfore/terraform-bpg-proxmox//modules/vm-clone"
for_each = tomap({
"vm-example-01" = {
id = 101
template = 9000
},
"vm-example-02" = {
id = 102
template = 9022
},
})
node = "pve" # required
vm_id = each.value.id # required
vm_name = each.key # optional
template_id = each.value.template # required
ci_ssh_key = "~/.ssh/id_ed25519.pub" # optional, add SSH key to "default" user
}
output "id_multiple_vms" {
value = { for k, v in module.vm_multiple_config : k => v.id }
}
output "public_ipv4_multiple_vms" {
value = { for k, v in module.vm_multiple_config : k => flatten(v.public_ipv4) }
}
# Create Single VM with Additional Disks
module "vm_disk_config" {
source = "github.com/trfore/terraform-bpg-proxmox//modules/vm-clone"
node = "pve" # required
vm_id = 103 # required
vm_name = "vm-example-disks" # optional
template_id = 9000 # required
ci_ssh_key = "~/.ssh/id_ed25519.pub" # optional, add SSH key to "default" user
disks = [
{
disk_interface = "scsi0", # default cloud image boot drive
disk_size = 10,
},
{
disk_interface = "scsi1", # example add extra disk
disk_size = 4,
},
]
}
# Create Single VM using UEFI
module "vm_uefi_config" {
source = "github.com/trfore/terraform-bpg-proxmox//modules/vm-clone"
node = "pve" # required
vm_id = 104 # required
vm_name = "vm-example-uefi" # optional
template_id = 9000 # required
bios = "ovmf" # optional, set UEFI bios
ci_ssh_key = "~/.ssh/id_ed25519.pub" # optional, add SSH key to "default" user
}