forked from coder/packages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.pkr.hcl
137 lines (117 loc) · 4.18 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
packer {
required_plugins {
amazon = {
version = ">= 0.0.2"
source = "github.com/hashicorp/amazon"
}
googlecompute = {
version = ">= 1.1.1"
source = "github.com/hashicorp/googlecompute"
}
}
}
variable "coder_version" {
type = string
}
local "safe_version" {
expression = replace(var.coder_version, "v", "")
}
variable "append_version" {
type = string
default = ""
}
source "amazon-ebs" "ubuntu" {
ami_name = "coder-v${local.safe_version}${var.append_version}"
ami_description = <<EOF
Coder v${local.safe_version}${var.append_version}: Self-Hosted Remote Development Environments
Ubuntu 22.04 AMI with Coder pre-installed, Docker, and TLS public tunnel.
https://github.com/coder/packages
EOF
instance_type = "t2.large"
region = "us-east-1"
source_ami_filter {
filters = {
name = "ubuntu/images/*ubuntu-jammy-22.04-amd64-server-*"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["099720109477"]
}
ssh_username = "ubuntu"
tags = {
name = "Coder"
os = "Ubuntu"
}
}
source "googlecompute" "ubuntu" {
project_id = "coder-enterprise-market-public"
image_name = "coder-v${replace(local.safe_version, ".", "-")}${replace(var.append_version, ".", "-")}"
source_image_family = "ubuntu-2204-lts"
image_licenses = ["projects/coder-enterprise-market-public/global/licenses/cloud-marketplace-83f16b4fa9cb1dff-df1ebeb69c0ba664"]
image_description = <<EOF
Coder v${replace(local.safe_version, ".", "-")}${replace(var.append_version, ".", "-")}: Self-Hosted Remote Development Environments
Ubuntu 22.04 AMI with Coder pre-installed, Docker, and TLS public tunnel.
https://github.com/coder/packages
EOF
zone = "us-east1-b"
machine_type = "n2-standard-8"
ssh_username = "ubuntu"
image_labels = {
name = "coder"
os = "ubuntu"
}
}
build {
name = "coder"
sources = [
"source.amazon-ebs.ubuntu",
"source.googlecompute.ubuntu"
]
provisioner "shell" {
inline = ["cloud-init status --wait"]
}
provisioner "shell" {
inline = ["mkdir -p /tmp/packer/etc/coder.d/"]
}
provisioner "shell" {
environment_vars = ["DEBIAN_FRONTEND=noninteractive", "LC_ALL=C", "LANG=en_US.UTF-8", "LC_CTYPE=en_US.UTF-8"]
inline = ["apt-get -qqy update", "apt-get -qqy -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' full-upgrade", "apt-get -qqy -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install apt-transport-https ca-certificates curl jq linux-image-extra-virtual software-properties-common", "apt-get -qqy clean"]
execute_command = "echo 'packer' | sudo -S env {{ .Vars }} {{ .Path }}"
}
provisioner "file" {
destination = "/tmp/packer/etc/coder.d/coder.env"
source = "files/etc/coder.d/coder_aws.env"
only = ["amazon-ebs.ubuntu"]
}
provisioner "file" {
destination = "/tmp/packer/etc/coder.d/coder.env"
source = "files/etc/coder.d/coder_gcp.env"
only = ["googlecompute.ubuntu"]
}
provisioner "shell" {
inline = ["rsync -a /tmp/packer/ / && rm -rf /tmp/packer/"]
execute_command = "echo 'packer' | sudo -S env {{ .Vars }} {{ .Path }}"
}
provisioner "shell" {
environment_vars = ["VERSION=${local.safe_version}", "DEBIAN_FRONTEND=noninteractive", "LC_ALL=C", "LANG=en_US.UTF-8", "LC_CTYPE=en_US.UTF-8"]
scripts = [
"files/scripts/010-docker.sh",
"files/scripts/011-grub-opts.sh",
"files/scripts/012-ufw-config.sh",
"files/scripts/013-postgresql.sh",
"files/scripts/014-coder.sh"
]
execute_command = "echo 'packer' | sudo -S env {{ .Vars }} {{ .Path }}"
}
provisioner "shell" {
environment_vars = ["DEBIAN_FRONTEND=noninteractive", "LC_ALL=C", "LANG=en_US.UTF-8", "LC_CTYPE=en_US.UTF-8"]
scripts = ["files/scripts/999-cleanup.sh"]
execute_command = "echo 'packer' | sudo -S env {{ .Vars }} {{ .Path }}"
}
# Store details in packer-manifest.json
# to retrieve AMI and GCE image IDs
post-processor "manifest" {
output = "packer-manifest.json"
}
}