-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.pkr.hcl
169 lines (143 loc) · 4.44 KB
/
template.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
# my-packer-image-builds jeffs-gce-image-ubuntu-2204
variable "account_file" {
type = string
default = ""
}
variable "disk_size" {
type = string
default = "30"
}
variable "disk_type" {
type = string
default = "pd-standard"
}
variable "image_description" {
type = string
default = "GCE custom machine image for Jeffs Repo my-packer-image-builds"
}
variable "image_name" {
type = string
default = ""
}
variable "machine_type" {
type = string
default = "e2-standard-2"
}
variable "prefix" {
type = string
default = "jeffs"
}
variable "project_id" {
type = string
default = ""
}
variable "source_image" {
type = string
default = "ubuntu-2204-jammy-v20230214"
}
variable "source_image_family" {
type = string
default = "ubuntu-2204-lts"
}
variable "ssh_username" {
type = string
default = "packer"
}
variable "user_home" {
type = string
default = "${env("HOME")}"
}
variable "zone" {
type = string
default = "us-east4-c"
}
# The "legacy_isotime" function has been provided for backwards compatability, but we recommend switching to the timestamp and formatdate functions.
locals {
postfix = "${legacy_isotime("20060102")}"
}
source "googlecompute" "example" {
account_file = "${var.account_file}"
communicator = "ssh"
disk_size = "${var.disk_size}"
disk_type = "${var.disk_type}"
image_description = "${var.image_description}"
image_name = "${var.prefix}-${var.image_name}-image"
instance_name = "packer-${var.image_name}-instance"
machine_type = "${var.machine_type}"
project_id = "${var.project_id}"
source_image = "${var.source_image}"
source_image_family = "${var.source_image_family}"
ssh_timeout = "5m"
ssh_username = "${var.ssh_username}"
use_internal_ip = false
zone = "${var.zone}" # Where the image will be built.
}
build {
sources = [
"source.googlecompute.example"
]
provisioner "shell" {
inline = ["echo THIS IS NEEDED!!! Only doing this to add a pause before file transfers"]
pause_after = "3s"
pause_before = "3s"
}
provisioner "file" {
destination = "/tmp/welcome.txt"
source = "./install-files/welcome.txt"
}
provisioner "file" {
destination = "/tmp/hello-go.service"
source = "./install-files/hello-go.service"
}
provisioner "file" {
destination = "/tmp/.dircolors"
source = "./install-files/.dircolors"
}
provisioner "file" {
destination = "/tmp/settings.json"
source = "./install-files/settings.json"
}
provisioner "file" {
destination = "/tmp/gce-github-vm.pub"
source = "${var.user_home}/.ssh/gce-github-vm.pub"
}
provisioner "file" {
destination = "/tmp/gce-github-vm"
source = "${var.user_home}/.ssh/gce-github-vm"
}
provisioner "file" {
destination = "/tmp/gce-universal-key-for-all-vms.pub"
source = "${var.user_home}/.ssh/gce-universal-key-for-all-vms.pub"
}
provisioner "file" {
destination = "/tmp/gce-universal-key-for-all-vms"
source = "${var.user_home}/.ssh/gce-universal-key-for-all-vms"
}
provisioner "shell" {
execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo -E {{ .Path }}"
pause_before = "4s"
scripts = [
"./install-scripts/update-upgrade-system.sh",
"./install-scripts/install-packages.sh",
"./install-scripts/add-user-jeff.sh",
"./install-scripts/move-welcome-file-to-jeff.sh",
"./install-scripts/edit-bashrc-for-root.sh",
"./install-scripts/edit-bashrc-for-jeff.sh",
"./install-scripts/add-colors-for-jeff.sh",
"./install-scripts/add-gce-universal-ssh-keys-to-jeff.sh",
"./install-scripts/add-github-ssh-keys-to-root.sh",
"./install-scripts/add-github-ssh-keys-to-jeff.sh",
"./install-scripts/install-docker.sh",
"./install-scripts/run-dockerhub-image-at-boot.sh",
"./install-scripts/install-go-and-config-for-root.sh",
"./install-scripts/config-go-for-jeff.sh",
"./install-scripts/install-protocol-buffers-for-go.sh",
"./install-scripts/clone-git-aware-prompt-for-jeff.sh",
"./install-scripts/add-vscode-settings-json-file.sh",
"./install-scripts/pull-private-repos-for-jeff.sh",
"./install-scripts/service-install.sh",
"./install-scripts/service-enable-at-boot.sh",
"./install-scripts/remove-github-ssh-keys.sh"
]
}
}