-
Notifications
You must be signed in to change notification settings - Fork 0
/
windows-2022-template.pkr.hcl
138 lines (116 loc) · 3.18 KB
/
windows-2022-template.pkr.hcl
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
packer {
required_plugins {
windows-update = {
version = "0.14.3"
source = "github.com/rgl/windows-update"
}
proxmox = {
version = "~> 1"
source = "github.com/hashicorp/proxmox"
}
}
}
source "proxmox-iso" "windows2022" {
# Proxmox Host Conection
proxmox_url = var.proxmox_url
insecure_skip_tls_verify = true
username = local.proxmox_user
password = local.proxmox_password
node = var.node
# BIOS - UEFI
bios = "ovmf"
# Machine type
# Q35 less resource overhead and newer chipset
machine = "q35"
efi_config {
efi_storage_pool = var.efi_storage
pre_enrolled_keys = true
efi_type = "4m"
}
# Windows Server ISO File
iso_file = var.windows_iso
unmount_iso = true
additional_iso_files {
cd_files = ["./build_files/drivers/*","./build_files/scripts/ConfigureRemotingForAnsible.ps1","./build_files/software/virtio-win-guest-tools.exe"]
cd_content = {
"autounattend.xml" = templatefile("./build_files/templates/unattend.pkrtpl", {password = local.winrm_password, cdrom_drive = var.cdrom_drive, index = lookup(var.image_index, var.template, "core")})
}
cd_label = "Unattend"
iso_storage_pool = var.iso_storage
unmount = true
device = "sata0"
}
template_name = "templ-win2022-${var.template}"
template_description = "Created on: ${timestamp()}"
vm_name = "win22-${var.template}"
memory = var.memory
cores = var.cores
sockets = var.socket
cpu_type = "host"
os = "win11"
scsi_controller = "virtio-scsi-pci"
cloud_init = false
cloud_init_storage_pool = var.cloud_init_storage
# Network
network_adapters {
model = "virtio"
bridge = var.bridge
vlan_tag = var.vlan
}
# Storage
disks {
storage_pool = var.disk_storage
# storage_pool_type = "btrfs"
type = "scsi"
disk_size = var.disk_size_gb
cache_mode = "writeback"
format = "raw"
}
# WinRM
communicator = "winrm"
winrm_username = var.winrm_user
winrm_password = local.winrm_password
winrm_timeout = "12h"
winrm_port = "5986"
winrm_use_ssl = true
winrm_insecure = true
# Boot
boot_wait = "7s"
boot_command = [
"<enter>"
]
}
build {
name = "Proxmox Build"
sources = ["source.proxmox-iso.windows2022"]
provisioner "windows-restart" {
}
provisioner "windows-update" {
search_criteria = "IsInstalled=0"
filters = [
"exclude:$_.Title -like '*Preview*'",
"include:$true",
]
update_limit = 25
}
provisioner "powershell" {
script = "./build_files/scripts/InstallCloudBase.ps1"
pause_before = "1m"
}
provisioner "file" {
source = "./build_files/config/"
destination = "C://Program Files//Cloudbase Solutions//Cloudbase-Init//conf"
}
provisioner "powershell" {
inline = [
"Set-Service cloudbase-init -StartupType Manual",
"Stop-Service cloudbase-init -Force -Confirm:$false"
]
}
provisioner "powershell" {
inline = [
"Set-Location -Path \"C:\\Program Files\\Cloudbase Solutions\\Cloudbase-Init\\conf\"",
"C:\\Windows\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /unattend:unattend.xml"
]
}
}