-
Notifications
You must be signed in to change notification settings - Fork 11
/
azure.pkr.hcl
173 lines (140 loc) · 3.59 KB
/
azure.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
packer {
required_plugins {
azure = {
source = "github.com/hashicorp/azure"
version = "~> 2"
}
}
}
variable "client_id" {
type = string
default = ""
}
variable "oidc_request_url" {
type = string
default = env("ACTIONS_ID_TOKEN_REQUEST_URL") // Github built-in variable
}
variable "oidc_request_token" {
type = string
default = env("ACTIONS_ID_TOKEN_REQUEST_TOKEN") // Github built-in variable
}
variable "subscription_id" {
type = string
}
variable "tenant_id" {
type = string
default = ""
}
variable "image_name" {
type = string
default = "spacelift-{{ timestamp }}"
}
variable "image_resource_group" {
type = string
}
variable "gallery_resource_group" {
type = string
default = null
}
variable "gallery_name" {
type = string
}
variable "gallery_image_name" {
type = string
default = null
}
variable "gallery_image_version" {
type = string
default = null
}
variable "gallery_replication_regions" {
type = list(string)
default = null
}
variable "source_image_publisher" {
type = string
default = "Canonical"
}
variable "source_image_offer" {
type = string
default = "0001-com-ubuntu-server-focal-daily"
}
variable "source_image_sku" {
type = string
default = "20_04-daily-lts-gen2"
}
variable "vm_size" {
type = string
default = "Standard_B2S"
}
variable "additional_tags" {
type = map(string)
default = {}
}
variable "packer_work_group" {
type = string
default = ""
description = "The resource group for Packer to use while building the VM"
}
source "azure-arm" "spacelift" {
client_id = var.client_id
subscription_id = var.subscription_id
tenant_id = var.tenant_id
oidc_request_url = var.oidc_request_url
oidc_request_token = var.oidc_request_token
managed_image_name = var.image_name
managed_image_resource_group_name = var.image_resource_group
shared_image_gallery_destination {
subscription = var.subscription_id
resource_group = var.gallery_resource_group
gallery_name = var.gallery_name
image_name = var.gallery_image_name
image_version = var.gallery_image_version
dynamic target_region {
for_each = var.gallery_replication_regions
content {
name = target_region.value
}
}
}
os_type = "Linux"
image_publisher = var.source_image_publisher
image_offer = var.source_image_offer
image_sku = var.source_image_sku
build_resource_group_name = var.packer_work_group
vm_size = var.vm_size
azure_tags = merge(var.additional_tags, {
Name = "Spacelift Worker Image"
SourceImagePublisher = var.source_image_publisher
SourceImageOffer = var.source_image_offer
SourceImageSku = var.source_image_sku
CreatedAt = "{{ timestamp }}"
})
}
build {
sources = ["source.azure-arm.spacelift"]
provisioner "shell" {
scripts = [
"shared/scripts/data-directories.sh",
"shared/scripts/apt-update.sh",
"shared/scripts/apt-install-docker.sh",
"shared/scripts/gvisor.sh",
"shared/scripts/apt-install-jq.sh",
"azure/scripts/azure-cli.sh",
]
env = {
DEBIAN_FRONTEND = "noninteractive"
}
}
# Deprovision VM
provisioner "shell" {
execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'"
inline = [
"/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"
]
inline_shebang = "/bin/sh -x"
}
post-processor "manifest" {
output = "manifest_azure.json"
}
}