-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoci.pkr.hcl
200 lines (163 loc) · 4.46 KB
/
oci.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
packer {
required_plugins {
oracle = {
version = ">= 1.0.1"
source = "github.com/hashicorp/oracle"
}
}
}
locals {
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
}
variable "image_name" {
type = string
default = "springone-2021-k8s-toolset-image"
}
variable "machine_type" {
type = string
default = "VM.Standard2.2"
}
variable "init_script" {
type = string
default = "init.sh"
}
variable "access_cfg_file" {
type = string
default = "~/.oci/config"
}
variable "key_file" {
type = string
default = "~/.oci/oci_api_key.pem"
}
variable "region" {
type = string
default = "us-phoenix-1"
}
variable "availability_domain" {
type = string
default = "imYr:PHX-AD-3"
}
variable "compartment_ocid" {
type = string
default = ""
}
variable "subnet_ocid" {
type = string
default = ""
}
# 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 "oracle-oci" "k8s-toolset" {
access_cfg_file = var.access_cfg_file
key_file = var.key_file
compartment_ocid = var.compartment_ocid
region = var.region
availability_domain = var.availability_domain
base_image_filter {
operating_system = "Canonical Ubuntu"
operating_system_version = "20.04"
display_name_search = "^Canonical-Ubuntu-20\\.04-2021\\.\\d+"
}
image_name = "${var.image_name}-${local.timestamp}"
shape = var.machine_type
ssh_username = "ubuntu"
subnet_ocid = var.subnet_ocid
tags = {
CreationDate = "${local.timestamp}"
}
disk_size = 80
}
# 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.oracle-oci.k8s-toolset"
]
provisioner "file" {
source = "dist/"
destination = "/home/ubuntu"
}
provisioner "file" {
source = "fetch-tanzu-cli.sh"
destination = "/home/ubuntu/fetch-tanzu-cli.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"
]
}
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.oracle-oci.k8s-toolset"
]
provisioner "file" {
source = "fetch-tanzu-cli.sh"
destination = "/home/ubuntu/fetch-tanzu-cli.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"
]
}
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
}
}