Skip to content

Instantly share code, notes, and snippets.

packer {
required_plugins {
amazon = {
version = ">= 1.2.8"
source = "github.com/hashicorp/amazon"
}
ansible = {
version = "~> 1"
source = "github.com/hashicorp/ansible"
}
build {
sources = [
"source.googlecompute.packed_image"
]
provisioner "shell" {
script = "./scripts/setup.sh"
}
provisioner "file" {
source = "./rootfs"
variable project_id {}
variable region {}
variable zone {}
variable network_project_id {}
variable network_name {}
variable subnet_name {}
variable image_name {}
variable target_image_family {}
variable source_image_family {default = null}
variable source_image {default = null}
locals {
# Let's calculate the hash of all the contents of the packer directory.
# We'll use this hash to determine if anything changed in the packer directory.
packer_contents_hash = md5(join(",", [for f in fileset("${path.module}/packer", "**") : filemd5("${path.module}/packer/${f}") if f != ".manifest.json"]))
image_source_build_params = var.source_image != null ? "-var source_image=${var.source_image}}" : "-var source_image_family=${var.source_image_family}"
image_target_build_params = "-var image_name=${var.target_image_name} -var target_image_family=${var.target_image_family}"
builder_network_project_id = var.builder_network_project_id == null ? var.builder_project_id : var.builder_network_project_id
}
@albertogeniola
albertogeniola / medium-provisioner-local-exec.tf
Last active October 13, 2024 17:31
Run packer build from Terraform
# This is the resource that will trigger the packer image creation
resource "terraform_data" "packer_image" {
triggers_replace = [local.packer_contents_hash, local.image_source_build_params, local.image_target_build_params]
provisioner "local-exec" {
when = create
working_dir = "${path.module}/packer/"
command = "packer build ${local.image_source_build_params} ${local.image_target_build_params} -var region=${var.builder_region} -var project_id=${var.builder_project_id} -var zone=${var.builder_zone} -var network_project_id=${local.builder_network_project_id} -var network_name=${var.builder_network_name} -var subnet_name=${var.builder_subnet_name} image.pkr.hcl"
}
@cGandom
cGandom / RaspberryPi4-qemu.md
Last active March 5, 2026 21:23
Emulating Raspberry Pi 4 with Qemu

Emulating Raspberry Pi 4 with Qemu

Just a quick update before we dive in: what we're actually doing here is running Raspberry Pi OS (64-bit) on a QEMU virtual ARM setup. This isn't full-blown hardware emulation of the Raspberry Pi 4, but more about creating a virtual environment for the OS. It doesn't mimic all the specific hardware features of the Pi 4, but it's pretty useful and great for general testing. I turned to this solution mainly to extract a modified sysroot from the Raspberry Pi OS, something not readily available in other resources. For those looking into detailed emulation of the actual Raspberry Pi 4's hardware in QEMU, check out this link for the latest updates: https://gitlab.com/qemu-project/qemu/-/issues/1208.

Hope it helps! :D

Shortcomings: No GUI yet, only console.

Steps

@ethanmdavidson
ethanmdavidson / preemptible-builder.pkr.hcl
Last active October 13, 2024 17:35
Packer Configuration for GCP spot/preemptible instances
source googlecompute preemptible-builder {
project_id = "<PROJECT_ID>"
zone = "us-west4-b" # using us-west4 because they have much cheaper spot prices right now.
ssh_username = "packer"
source_image = "debian-11-bullseye-v20230306"
wrap_startup_script = false
disk_size = 10
preemptible = true
metadata = {
#if instance gets preempted, send SIGINT to packer (prevents packer from hanging for 20m trying to reconnect)
@shantanoo-desai
shantanoo-desai / README.md
Last active October 13, 2024 17:35
Creating a Root Filesystem for Ubuntu 20.04 ARM64 using Hashicorp Packer + Docker

From Docker Container to Bootable Disk Images but with Packer

Source based on Blog Post @iximiuz (Ivan Velichko)

Putting it together

  1. Create the Filesystem Tarball with Kernel and SystemD
@Chester-Gillon
Chester-Gillon / AlmaLinux_8_installation.md
Last active November 25, 2025 07:51
Notes about installing AlmaLinux 8 and making customisation's

0. Introduction

Describes notes made about installing AlmaLinux 8, and making customisations as required. The installation was performed on a HP Z640 workstation, and to avoid changing the Windows and Ubuntu installations on the existing RAID arrays used a USB external disk as the target for the AlmaLinux installation.

1. Creation of install media and initial installation.

The full DVD ISO image was downloaded from AlmaLinux-8.4-x86_64-dvd.iso

Followed the instructions at Installation instructions to verify the checksum of the downloaded ISO which was succesful in that the SHA256 of the ISO file matched the expected value:

aquarion@Typhoon ~/code/IDL/ansible-webstack (master *): cat packer/ami.pkr.hcl
source "amazon-ebs" "cornerstone" {
profile = "pr-globalcms"
region = "us-east-1"
source_ami = "ami-019212a8baeffb0fa"
instance_type = "t2.micro"
ssh_username = "ubuntu"
ami_name = "cornerstone_AWS {{timestamp}}"