-
Notifications
You must be signed in to change notification settings - Fork 4
/
arm.pkr.hcl
231 lines (183 loc) · 6.25 KB
/
arm.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
locals {
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
image_version = formatdate("YYYY.M.D", timestamp())
}
variable "client_id" {
type = string
default = ""
}
variable "client_secret" {
type = string
default = ""
}
variable "subscription_id" {
type = string
default = ""
}
variable "tenant_id" {
type = string
default = ""
}
variable "use_azure_cli_auth" {
type = bool
default = true
}
variable "resource_group" {
type = string
default = "cloudmonk"
}
variable "image_name" {
type = string
default = "K8sToolsetImage"
}
variable "init_script" {
type = string
default = "init.sh"
}
variable "vm_size" {
type = string
default = "Standard_D4s_v4"
}
variable "cloud_environment_name" {
type = string
default = "Public"
}
# source blocks are generated from your builders; a source can be referenced in
# build blocks. A build block runs provisioner and post-processors on a
# source. Read the documentation for source blocks here:
# https://www.packer.io/docs/templates/hcl_templates/blocks/source
source "azure-arm" "k8s-toolset" {
use_azure_cli_auth = var.use_azure_cli_auth
cloud_environment_name = var.cloud_environment_name # One of Public, China, Germany, or USGovernment. Defaults to Public. Long forms such as USGovernmentCloud and AzureUSGovernmentCloud are also supported.
build_resource_group_name = var.resource_group
shared_image_gallery_destination {
image_name = var.image_name
image_version = local.image_version
resource_group = var.resource_group
gallery_name = "toolsetvms" # Shared Image Gallery must already exist in resource group
replication_regions = [ "eastus", "westus2", "centralus", "westcentralus", "northeurope", "ukwest", "southeastasia", "australiasoutheast" ]
}
managed_image_resource_group_name = var.resource_group
managed_image_name = "${var.image_name}${local.timestamp}"
managed_image_storage_account_type = "Premium_LRS"
os_type = "Linux"
os_disk_size_gb = 60
image_publisher = "Canonical" # e.g., az vm image list-publishers --location westus2 -o table
image_offer = "0001-com-ubuntu-server-jammy" # e.g., az vm image list-offers --location westus2 --publisher Canonical -o table
image_sku = "22_04-lts-gen2" # e.g., az vm image list-skus --location westus2 --publisher Canonical --offer 0001-com-ubuntu-minimal-jammy -o table
image_version = "latest"
vm_size = var.vm_size # e.g., az vm list-sizes --location westus -o table
ssh_username = "ubuntu"
}
# a build block invokes sources and runs provisioning steps on them. The
# documentation for build blocks can be found here:
# https://www.packer.io/docs/templates/hcl_templates/blocks/build
build {
name = "with-tanzu"
sources = [
"source.azure-arm.k8s-toolset"
]
provisioner "file" {
source = "install-krew-and-plugins.sh"
destination = "/home/ubuntu/install-krew-and-plugins.sh"
}
provisioner "file" {
source = "dist/"
destination = "/home/ubuntu"
}
provisioner "file" {
source = "fetch-tanzu-cli.sh"
destination = "/home/ubuntu/fetch-tanzu-cli.sh"
}
provisioner "file" {
source = "install-tap-plugins.sh"
destination = "/home/ubuntu/install-tap-plugins.sh"
}
provisioner "file" {
source = "fetch-and-install-oci-cli.sh"
destination = "/home/ubuntu/fetch-and-install-oci-cli.sh"
}
provisioner "file" {
source = "inventory.sh"
destination = "/home/ubuntu/inventory.sh"
}
provisioner "file" {
source = "kind-load-cafile.sh"
destination = "/home/ubuntu/kind-load-cafile.sh"
}
provisioner "shell" {
inline = [
"chmod +x /home/ubuntu/tanzu",
"chmod +x /home/ubuntu/inventory.sh",
"chmod +x /home/ubuntu/kind-load-cafile.sh",
"chmod +x /home/ubuntu/fetch-tanzu-cli.sh",
"chmod +x /home/ubuntu/fetch-and-install-oci-cli.sh",
"chmod +x /home/ubuntu/install-tap-plugins.sh",
"chmod +x /home/ubuntu/install-krew-and-plugins.sh"
]
}
provisioner "shell" {
script = var.init_script
# @see https://www.packer.io/docs/provisioners/shell#sudo-example
execute_command = "echo 'packer' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'"
}
post-processor "checksum" {
checksum_types = ["md5", "sha512"]
}
post-processor "manifest" {
output = "manifest.json"
strip_path = true
}
}
build {
name = "standard"
sources = [
"source.azure-arm.k8s-toolset"
]
provisioner "file" {
source = "install-krew-and-plugins.sh"
destination = "/home/ubuntu/install-krew-and-plugins.sh"
}
provisioner "file" {
source = "fetch-tanzu-cli.sh"
destination = "/home/ubuntu/fetch-tanzu-cli.sh"
}
provisioner "file" {
source = "install-tap-plugins.sh"
destination = "/home/ubuntu/install-tap-plugins.sh"
}
provisioner "file" {
source = "fetch-and-install-oci-cli.sh"
destination = "/home/ubuntu/fetch-and-install-oci-cli.sh"
}
provisioner "file" {
source = "inventory.sh"
destination = "/home/ubuntu/inventory.sh"
}
provisioner "file" {
source = "kind-load-cafile.sh"
destination = "/home/ubuntu/kind-load-cafile.sh"
}
provisioner "shell" {
inline = [
"chmod +x /home/ubuntu/inventory.sh",
"chmod +x /home/ubuntu/kind-load-cafile.sh",
"chmod +x /home/ubuntu/fetch-tanzu-cli.sh",
"chmod +x /home/ubuntu/fetch-and-install-oci-cli.sh",
"chmod +x /home/ubuntu/install-tap-plugins.sh",
"chmod +x /home/ubuntu/install-krew-and-plugins.sh"
]
}
provisioner "shell" {
script = var.init_script
# @see https://www.packer.io/docs/provisioners/shell#sudo-example
execute_command = "echo 'packer' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'"
}
post-processor "checksum" {
checksum_types = ["md5", "sha512"]
}
post-processor "manifest" {
output = "manifest.json"
strip_path = true
}
}