2024-03-30 17:01:00 +01:00
|
|
|
packer {
|
|
|
|
|
required_plugins {
|
|
|
|
|
hcloud = {
|
|
|
|
|
source = "github.com/hetznercloud/hcloud"
|
|
|
|
|
version = "~> 1"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variable "hcloud_token" {
|
|
|
|
|
type = string
|
|
|
|
|
default = "${env("HCLOUD_TOKEN")}"
|
|
|
|
|
sensitive = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variable "hcloud_server_type" {
|
|
|
|
|
type = map(string)
|
|
|
|
|
default = {
|
2024-05-30 15:50:14 +02:00
|
|
|
x86 = "cx11"
|
|
|
|
|
arm = "cax11"
|
2024-03-30 17:01:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 15:50:14 +02:00
|
|
|
variable "channel" {
|
|
|
|
|
type = string
|
|
|
|
|
default = "beta"
|
2024-03-30 17:01:00 +01:00
|
|
|
}
|
|
|
|
|
|
2024-04-15 20:54:33 +02:00
|
|
|
variable "image_version_id" {
|
2024-05-30 15:50:14 +02:00
|
|
|
type = string
|
|
|
|
|
default = "current"
|
2024-04-15 20:54:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variable "flatcar_install_script" {
|
2024-05-30 15:50:14 +02:00
|
|
|
type = string
|
|
|
|
|
default = "https://raw.githubusercontent.com/flatcar/init/flatcar-master/bin/flatcar-install"
|
2024-03-30 17:01:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
locals {
|
2024-05-30 15:50:14 +02:00
|
|
|
hcloud_location = "fsn1"
|
|
|
|
|
hcloud_rescue = "linux64"
|
2024-03-30 17:01:00 +01:00
|
|
|
hcloud_initial_os = "ubuntu-22.04"
|
2024-05-30 15:50:14 +02:00
|
|
|
flatcar_oem_id = "hetzner"
|
2024-04-15 20:54:33 +02:00
|
|
|
|
|
|
|
|
board = {
|
2024-05-30 15:50:14 +02:00
|
|
|
x86 = "amd64-usr"
|
|
|
|
|
arm = "arm64-usr"
|
2024-04-15 20:54:33 +02:00
|
|
|
}
|
2024-03-30 17:01:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source "hcloud" "flatcar" {
|
|
|
|
|
token = var.hcloud_token
|
|
|
|
|
|
2024-05-30 15:50:14 +02:00
|
|
|
image = local.hcloud_initial_os
|
|
|
|
|
location = local.hcloud_location
|
|
|
|
|
rescue = local.hcloud_rescue
|
2024-03-30 17:01:00 +01:00
|
|
|
|
|
|
|
|
snapshot_labels = {
|
2024-05-30 15:50:14 +02:00
|
|
|
os = "flatcar"
|
2024-03-30 17:01:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ssh_username = "root"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build {
|
|
|
|
|
source "hcloud.flatcar" {
|
2024-05-30 15:50:14 +02:00
|
|
|
name = "x86"
|
|
|
|
|
server_type = var.hcloud_server_type["x86"]
|
2024-04-11 19:13:23 +02:00
|
|
|
snapshot_name = "flatcar-x86"
|
2024-03-30 17:01:00 +01:00
|
|
|
}
|
|
|
|
|
|
2024-04-15 20:54:33 +02:00
|
|
|
source "hcloud.flatcar" {
|
2024-05-30 15:50:14 +02:00
|
|
|
name = "arm"
|
|
|
|
|
server_type = var.hcloud_server_type["arm"]
|
2024-04-15 20:54:33 +02:00
|
|
|
snapshot_name = "flatcar-arm"
|
2024-03-30 17:01:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
provisioner "shell" {
|
|
|
|
|
inline = [
|
|
|
|
|
# Download script and dependencies
|
|
|
|
|
"apt-get -y install gawk",
|
|
|
|
|
"curl -fsSLO --retry-delay 1 --retry 60 --retry-connrefused --retry-max-time 60 --connect-timeout 20 ${var.flatcar_install_script}",
|
|
|
|
|
"chmod +x flatcar-install",
|
|
|
|
|
|
|
|
|
|
# Install flatcar
|
2024-05-30 15:50:14 +02:00
|
|
|
"./flatcar-install -v -s -o hetzner -b https://${var.channel}.release.flatcar-linux.net/${local.board[source.name]} -V ${var.image_version_id}",
|
2024-03-30 17:01:00 +01:00
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|