Skip to content
Snippets Groups Projects
Verified Commit 0ba3f222 authored by Kristian Klausen's avatar Kristian Klausen :tada:
Browse files

packer: Convert from JSON to HCL

As of version 1.7.0, HCL2 is the preferred way to write Packer
templates. The documentation reflect this and it is easier if we use the
preferred format.
parent 73b219e3
No related branches found
No related tags found
1 merge request!748Misc changes for supporting aurweb's review apps need
......@@ -45,7 +45,7 @@ tasks.
We use packer to build snapshots on hcloud to use as server base images.
In order to use this, you need to install packer and then run
packer build -var $(misc/get_key.py misc/vaults/vault_hetzner.yml hetzner_cloud_api_key --format env) packer/archlinux.json
packer build -var $(misc/get_key.py misc/vaults/vault_hetzner.yml hetzner_cloud_api_key --format env) packer/archlinux.pkr.hcl
This will take some time after which a new snapshot will have been created on the primary hcloud archlinux project.
......
{
"variables": {
"hetzner_cloud_api_key": null
},
"sensitive-variables": ["hetzner_cloud_api_key"],
"builders": [{
"type": "hcloud",
"snapshot_name": "archlinux-{{ isotime \"2006-01-02T15:04\" }}",
"snapshot_labels": {
"custom_image": "archlinux"
},
"token": "{{ user `hetzner_cloud_api_key` }}",
"image": "ubuntu-22.04",
"server_type": "cx11",
"ssh_username": "root",
"location": "fsn1",
"rescue": "linux64"
}],
"provisioners": [{
"type": "ansible",
"playbook_file": "playbooks/tasks/install_arch.yml",
"host_alias": "packer-base-image",
"inventory_directory": ".",
"use_proxy": false
}]
}
# https://www.packer.io/docs/templates/hcl_templates/blocks/packer
packer {
required_plugins {
ansible = {
source = "github.com/hashicorp/ansible"
version = ">= 1.1.0"
}
hcloud = {
source = "github.com/hashicorp/hcloud"
version = ">= 1.0.0"
}
}
}
# https://www.packer.io/docs/templates/hcl_templates/variables#type-constraints
variable "hetzner_cloud_api_key" {
type = string
sensitive = true
}
# https://www.packer.io/docs/templates/hcl_templates/blocks/source
source "hcloud" "rescue" {
image = "ubuntu-22.04"
location = "fsn1"
rescue = "linux64"
server_type = "cx11"
snapshot_labels = {
custom_image = "archlinux"
}
snapshot_name = "archlinux-${timestamp()}"
ssh_username = "root"
token = var.hetzner_cloud_api_key
}
# https://www.packer.io/docs/templates/hcl_templates/blocks/build
build {
sources = ["source.hcloud.rescue"]
provisioner "ansible" {
host_alias = "packer-base-image"
inventory_directory = "."
playbook_file = "playbooks/tasks/install_arch.yml"
use_proxy = false
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment