-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhyperVWindowsServer2025.pkr.hcl
More file actions
112 lines (92 loc) · 2.76 KB
/
Copy pathhyperVWindowsServer2025.pkr.hcl
File metadata and controls
112 lines (92 loc) · 2.76 KB
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
/*
Windows Server 2025 Datacenter: Azure Edition -x64 Gen2
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2025-datacenter-azure-edition",
"version": "latest",
"exactVersion": "26100.4652.250713"
}
*/
packer {
required_plugins {
azure = {
source = "github.com/hashicorp/azure"
version = "~> 2"
}
}
}
variable "tenant_id" {
type = string
}
variable "subscription_id" {
type = string
}
variable "image_name" {
type = string
default = "hyperVWindowsServer2025"
}
variable "resource_group" {
type = string
default = "images"
}
variable "image_version" {
type = string
default = "1.0.0"
}
source "azure-arm" "windows" {
location = "UK South"
vm_size = "Standard_E2bds_v5"
subscription_id = var.subscription_id
tenant_id = var.tenant_id
use_azure_cli_auth = true
managed_image_resource_group_name = var.resource_group
managed_image_name = var.image_name
async_resourcegroup_delete = true
managed_image_storage_account_type = "Premium_LRS"
os_type = "Windows"
image_publisher = "MicrosoftWindowsServer"
image_offer = "WindowsServer"
image_version = "26100.4652.250713"
image_sku = "2025-datacenter-azure-edition"
communicator = "winrm"
winrm_username = "packer"
winrm_insecure = true
winrm_use_ssl = true
winrm_timeout = "1h"
}
build {
sources = ["source.azure-arm.windows"]
# Configure HyperVisor, as its off by default
provisioner "powershell" {
inline = [
"bcdedit /set hypervisorlaunchtype auto"
]
}
# restart to apply changes
provisioner "windows-restart" {
restart_check_command = "powershell -command \"& {Write-Output 'restarted.'}\""
}
provisioner "powershell" {
inline = [
"Install-WindowsFeature -Name DHCP,Hyper-V -IncludeManagementTools", # install HyperV
"Set-VMHost -EnableEnhancedSessionMode $True", # allow for copy-paste into Hyper-V VMs, and resizing of windows
"New-ItemProperty -Path 'HKLM:\\SYSTEM\\CurrentControlSet\\Services\\partmgr\\Parameters' -Name 'SanPolicy' -Value 1 -PropertyType DWORD -Force" # should set all new disks to be "offline"
]
}
# setup SSH, as an alternative to WinRM (backup)
provisioner "powershell" {
scripts = [
"./files/scripts/sshd.ps1"
]
}
# restart windows server before SysPrep to apply any updates
provisioner "windows-restart" {
restart_check_command = "powershell -command \"& {Write-Output 'restarted.'}\""
}
provisioner "powershell" {
scripts = [
"./files/scripts/deprovision-image.ps1"
]
}
}