~samirnassar/debian

53082f170a1d52a347f7961c50e14f9fadcb6238 — Samir Nassar 2 years ago
Import and cleanup from the old pacer-templates repository
3 files changed, 103 insertions(+), 0 deletions(-)

A .gitignore
A README.md
A debian.pkr.hcl
A  => .gitignore +2 -0
@@ 1,2 @@
builder.pkrvars.hcl
*.auto.pkrvars.hcl

A  => README.md +35 -0
@@ 1,35 @@
# debian packer template for Hetzner Cloud

This repo is used to debian linux images (as snapshots) for use with
[Hetzner Cloud](https://www.hetzner.de/cloud) by means of HashiCorp's
[Packer](https://packer.io/).

## Building Images using this Repo

Please ensure that you have done the following:

  - installed `packer` on your development machine
  - set the `HCLOUD_TOKEN` environment variable to your API token
  - reviewed/overriden the templates' variables (as necessary)

### Internals

The resulting images are intended to support a Terraform-based (or
custom) workflow that feels close to the one of native Hetzner VMs.

In particular, support for the following features available on
standard Hetzner VMs is desired:

  - dynamic hostname
  - dynamic root ssh keys
  - free-form cloud-init userdata
  - full IPv6/IPv4 support
  - Hetzner Cloud Networks
  - Hetzner Cloud Volumes

## License

You can redistribute and/or modify these files unter the terms of the
GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any
later version. See the LICENSE file for details.

A  => debian.pkr.hcl +66 -0
@@ 1,66 @@
variable "hcloud_token" {
  type = string
}

variable "ssh_keys" {
  type = string
}

locals {
  snapshotbuildtime = formatdate("YYYY-MM-DD-hhmm", timestamp())
  # Also here I believe naming this variable `buildtime` could lead to 
  # confusion mainly because this is evaluated a 'parsing-time'.
  hcloud-servertype = "cx11"
  arch-release = "{{ isotime `2006-01` }}-01"
  system-keymap = "us"
  system-locale = "en_US.UTF-8"
  system-timezone = "UTC"
  extra-packages = ""
}

source "hcloud" "debian-11" {
  image        = "debian-11"
  location     = "hel1"
  server_type  = "cx11"
  ssh_username = "root"
  token        = "${var.hcloud_token}"
  rescue       = "linux64"
  ssh_keys     = ["${var.ssh_keys}"]
  ssh_agent_auth = true
  server_name = "debian-11-${ local.snapshotbuildtime }"
  snapshot_name = "debian-11-${ local.snapshotbuildtime }"
  snapshot_labels = {
    "packer.io/version" = "${packer.version}",
    "packer.io/build.time" = "${ local.snapshotbuildtime }",
    "os-flavor" = "debian-11",
    "image_type" = "debian-11"
  }
}

build {
  sources = ["source.hcloud.debian-11"]

  provisioner "shell" {
    inline = ["echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections"]
  }

  provisioner "shell" {
    inline = ["/usr/bin/apt-get update"]
  }

  provisioner "shell" {
    inline = ["/usr/bin/apt-get -y upgrade"]
  }

  provisioner "shell" {
    inline = ["/usr/bin/apt-get -y install python3 python3-pip python3-setuptools python3-wheel"]
  }

  provisioner "shell" {
    inline = ["/usr/bin/apt-get -y install ssl-cert"]
  }

  provisioner "shell" {
    inline = ["make-ssl-cert generate-default-snakeoil --force-overwrite"]
  }
}