-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPacker-CTXAZPK-VDA-Citrix.pkr.hcl
182 lines (153 loc) · 6.75 KB
/
Packer-CTXAZPK-VDA-Citrix.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
variable "AZURE_CLIENT_ID" {
type = string
default = "${env("AZURE_CLIENT_ID")}"
sensitive = true
}
variable "AZURE_CLIENT_SECRET" {
type = string
default = "${env("AZURE_CLIENT_SECRET")}"
sensitive = true
}
variable "AZURE_MDT" {
type = string
default = "${env("AZURE_MDT")}"
sensitive = true
}
variable "AZURE_LOCALUSER" {
type = string
default = "${env("AZURE_LOCALUSER")}"
sensitive = true
}
variable "managed_image_name" {
type = string
default = "citrix-packer-image"
}
variable "subscription_id" {
type = string
default = "<azure subscription id>"
}
variable "temp_compute_name" {
type = string
default = "CTXAZPK16VDA001"
}
# The "legacy_isotime" function has been provided for backwards compatability, but we recommend switching to the timestamp and formatdate functions.
# 1 error occurred upgrading the following block:
# unhandled "lower" call:
# there is no way to automatically upgrade the "lower" call.
# Please manually upgrade to `lower(var.example)`
# Visit https://www.packer.io/docs/templates/hcl_templates/functions/string/lower for more infos.
source "azure-arm" "autogenerated_1" {
azure_tags = {
application = "citrix"
}
#Azure Info
subscription_id = "${var.subscription_id}"
client_id = "${var.AZURE_CLIENT_ID}"
client_secret = "${var.AZURE_CLIENT_SECRET}"
cloud_environment_name = "AzureUSGovernmentCloud"
#Packer Azure
build_resource_group_name = "<azure resource grouop>"
custom_resource_build_prefix = "ctxpk"
managed_image_name = "${var.managed_image_name}-${formatdate("YYYY-MM-DD-hhmm-0700",timestamp())}"
managed_image_resource_group_name = "<azure resource group>"
managed_image_storage_account_type = "Premium_LRS"
#Azure Marketplace Sku
os_type = "Windows"
image_offer = "WindowsServer"
image_publisher = "MicrosoftWindowsServer"
image_sku = "2016-datacenter-gensecond"
image_version = "latest"
#VM details
private_virtual_network_with_public_ip = false
#temp_compute_name = "${var.temp_compute_name}${legacy_isotime("06010203")}"
temp_compute_name = "${var.temp_compute_name}"
virtual_network_name = "<azure virtual network>"
virtual_network_resource_group_name = "<azure resource group>"
virtual_network_subnet_name = "<azure subnet name>"
vm_size = "Standard_B4ms"
#WinRM
communicator = "winrm"
winrm_insecure = "true"
winrm_timeout = "5m"
winrm_use_ssl = "true"
winrm_username = "packer"
}
build {
sources = ["source.azure-arm.autogenerated_1"]
provisioner "powershell" {
inline = ["while ((Get-Service RdAgent).Status -ne 'Running') { Start-Sleep -s 5 }", "while ((Get-Service WindowsAzureGuestAgent).Status -ne 'Running') { Start-Sleep -s 5 }", "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12", "Start-sleep -s 5"]
}
provisioner "windows-restart" {
restart_check_command = "powershell -command \"& {Write-Output 'Machine restarted1.'}\""
}
provisioner "powershell" {
environment_vars = ["AZURE_LOCALUSER=${var.AZURE_LOCALUSER}"]
scripts = ["./Azure-Packer-PreReqs.ps1"]
valid_exit_codes = [0, 1, 3010]
}
provisioner "windows-restart" {
restart_check_command = "powershell -command \"& {Write-Output 'Machine restarted2.'}\""
}
provisioner "powershell" {
environment_vars = ["Azure_MDT=${var.AZURE_MDT}"]
scripts = ["./Azure-Packer-Base.ps1"]
elevated_user = "Administrator"
elevated_password = "${var.AZURE_LOCALUSER}"
valid_exit_codes = [0, 1, 3010]
}
provisioner "windows-restart" {
restart_check_command = "powershell -command \"& {Write-Output 'Machine restarted3.'}\""
restart_timeout = "20m"
}
provisioner "powershell" {
environment_vars = ["Azure_MDT=${var.AZURE_MDT}"]
scripts = ["./Azure-Packer-Citrix-Installs.ps1"]
elevated_user = "Administrator"
elevated_password = "${var.AZURE_LOCALUSER}"
valid_exit_codes = [0, 1, 3, 3010]
}
provisioner "windows-restart" {
restart_check_command = "powershell -command \"& {Write-Output 'Machine restarted4.'}\""
restart_timeout = "20m"
}
provisioner "powershell" {
environment_vars = ["Azure_MDT=${var.AZURE_MDT}"]
scripts = ["./Azure-Packer-Global-App-Installs-1.ps1"]
elevated_user = "Administrator"
elevated_password = "${var.AZURE_LOCALUSER}"
valid_exit_codes = [0, 1, 3, 3010]
}
provisioner "windows-restart" {
restart_check_command = "powershell -command \"& {Write-Output 'Machine restarted5.'}\""
restart_timeout = "20m"
}
provisioner "powershell" {
environment_vars = ["Azure_MDT=${var.AZURE_MDT}"]
scripts = ["./Azure-Packer-SecurityAgent-Installs-1.ps1"]
elevated_user = "Administrator"
elevated_password = "${var.AZURE_LOCALUSER}"
valid_exit_codes = [0, 1, 3, 3010]
}
provisioner "windows-restart" {
restart_check_command = "powershell -command \"& {Write-Output 'Machine restarted6.'}\""
restart_timeout = "20m"
}
provisioner "powershell" {
environment_vars = ["Azure_MDT=${var.AZURE_MDT}"]
scripts = ["./Azure-Packer-Final-Seal-2.ps1"]
elevated_user = "Administrator"
elevated_password = "${var.AZURE_LOCALUSER}"
valid_exit_codes = [0, 1, 3, 3010]
}
provisioner "windows-restart" {
restart_check_command = "powershell -command \"& {Write-Output 'Machine restarted7.'}\""
restart_timeout = "20m"
}
provisioner "powershell" {
inline = ["while ((Get-Service RdAgent).Status -ne 'Running') { Start-Sleep -s 5 }", "while ((Get-Service WindowsAzureGuestAgent).Status -ne 'Running') { Start-Sleep -s 5 }", "Set-ExecutionPolicy Bypass -Scope Process -Force", "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12", "Start-sleep -s 5", "& $env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /quiet /quit", "while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10 } else { break } }"]
}
post-processor "manifest" {
output = "./manifests/manifest-${legacy_isotime("2006-01-02-0304")}.json"
strip_path = true
}
}