mirror of
https://github.com/apricote/flatcar-packer-hcloud.git
synced 2026-01-13 13:21:01 +00:00
I missed the note in the docs that the ignition config specified on `install-flatcar` will disable the `fetch` stage in ignition. This stage is required to read the user data ignition config from the metadata service. By moving our OEM ignition config to `oemfs/base/base.ign` it will always be merged with the user data config.
100 lines
2.2 KiB
HCL
100 lines
2.2 KiB
HCL
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 = {
|
|
x86 = "cx11"
|
|
arm = "cax11"
|
|
}
|
|
}
|
|
|
|
variable "flatcar_install_script" {
|
|
type = string
|
|
default = "https://raw.githubusercontent.com/flatcar/init/flatcar-master/bin/flatcar-install"
|
|
}
|
|
|
|
variable "flatcar_channel" {
|
|
type = string
|
|
default = "alpha"
|
|
}
|
|
|
|
locals {
|
|
hcloud_location = "fsn1"
|
|
hcloud_rescue = "linux64"
|
|
hcloud_initial_os = "ubuntu-22.04"
|
|
flatcar_oem_id = "hetzner"
|
|
}
|
|
|
|
source "hcloud" "flatcar" {
|
|
token = var.hcloud_token
|
|
|
|
image = local.hcloud_initial_os
|
|
location = local.hcloud_location
|
|
rescue = local.hcloud_rescue
|
|
|
|
snapshot_labels = {
|
|
os = "flatcar"
|
|
"flatcar.channel" = var.flatcar_channel
|
|
}
|
|
|
|
ssh_username = "root"
|
|
}
|
|
|
|
|
|
build {
|
|
source "hcloud.flatcar" {
|
|
name = "x86"
|
|
server_type = var.hcloud_server_type["x86"]
|
|
snapshot_name = "flatcar-${var.flatcar_channel}-x86"
|
|
}
|
|
|
|
source "hcloud.flatcar" {
|
|
name = "arm"
|
|
server_type = var.hcloud_server_type["arm"]
|
|
snapshot_name = "flatcar-${var.flatcar_channel}-arm"
|
|
}
|
|
|
|
provisioner "file" {
|
|
source = "ignition-oem.json"
|
|
destination = "/ignition.json"
|
|
}
|
|
|
|
provisioner "shell" {
|
|
inline = [
|
|
# Download script and dependencies
|
|
"apt-get update",
|
|
"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
|
|
"./flatcar-install -s -C ${var.flatcar_channel}",
|
|
|
|
# Setup Ignition Config & Kernel Parameters for OEM Platform
|
|
"mkdir /root/OEM",
|
|
"mount /dev/disk/by-label/OEM /root/OEM",
|
|
|
|
## Kernel Parameter
|
|
"echo 'set oem_id=${local.flatcar_oem_id}' > /root/OEM/grub.cfg",
|
|
|
|
## Base Ignition Config (merged with user data)
|
|
"mkdir /root/OEM/base",
|
|
"cp /ignition.json /root/OEM/base/base.ign",
|
|
|
|
"umount /root/OEM",
|
|
]
|
|
}
|
|
}
|