Update of packer-vagrant project using HCL

Posted on May 13, 2021 by Adrian Wyssmann ‐ 2 min read

Since I last used packer it's been a while and when I recently wanted to create a new Windows vm, I used my project. This is where I realized certain things have changed with packer since I started the project.

Since I last looked at packer, Hashicorp introduced HCL Configuration Language. The new format is different, although they also support a .json format. But I decided the new format. So first, I start to convert my existing files:

packer hcl2_upgrade FILENAME

The most notable difference is the declaration and usage of variables. They are now declared in a variable block:

variable "image_id" {
  type = string

variable "availability_zone_names" {
  type    = list(string)
  default = ["us-west-1a"]

variable "docker_ports" {
  type = list(object({
    internal = number
    external = number
    protocol = string
  default = [
      internal = 8300
      external = 8300
      protocol = "tcp"

Variable definitions on the other hand are stored in .pkrvars.hcl or .auto.pkrvars.hcl - latter is loaded automatically. It is used as before:

packer build -var-file="testing.pkrvars.hcl"

The content consists only of variable name assignments:

image_id = "ami-abc123"
availability_zone_names = [

The conversions of my variable files from json to the hcl-format, I had to do manually, which was some work. That’s it, you can check my [my packer-vagrant project] for the detailed changes made.

Beside of that I also updated some of the iso configurations, and removed some outdated ones. I made a quick test and the conversion of the file seems fine but there seems other issues with the ubuntu images and virtualbox: When I boot the live image for ubuntu server 20.04 or 21.04 I get a kernel panic

ubuntu kernel panic
kernel panic while booting ubuntu in virtualbox

I have to further investigate what’s exactly happening and if this also happens to other Linux distributions.