Describe the bug
It seems that whenever additional parameters are specified in the packer_image resource Packer errors out (it's printing its help output instead of creating the image).
packer {
required_plugins {
docker = {
version = ">= 1.0.0"
source = "github.com/hashicorp/docker"
}
}
}
variable "image_name" {
type = string
}
# Pull the pre-built image from Dockerhub
source "docker" "image" {
image = var.image_name
commit = true
}
# Cache the image in own repo
build {
sources = ["source.docker.image"]
post-processors {
post-processor "docker-tag" {
repository = "my-repo/my-image"
tags = ["latest"]
}
}
}
Expected behavior
I expect that Packer builds the image.
Additional information (please complete the following information):
The additional parameters are placed incorrectly on the Packer command line. The error message when trying to run terraform init and terraform apply on the minimal example above shows the following Packer command line in the output:
packer_image.image: Creating...
╷
│ Warning: Failed to run command /tmp/felix_wolfheimer/devbox-manager/registry.terraform.io/toowoxx/packer/0.15.0/linux_amd64/terraform-provider-packer_v0.15.0 build -var image_name=ubuntu:latest -force ./config.pkr.hcl -parallel-builds=1
Describe the bug It seems that whenever additional parameters are specified in the
packer_image
resource Packer errors out (it's printing its help output instead of creating the image).To Reproduce
main.tf
:config.pkr.hcl
:Expected behavior I expect that Packer builds the image.
Additional information (please complete the following information): The additional parameters are placed incorrectly on the Packer command line. The error message when trying to run
terraform init
andterraform apply
on the minimal example above shows the following Packer command line in the output:The additional parameter
-parallel-builds=1
is placed after the template file on the command line. However, Packer requires that the template file is the last argument on the command line. The error seems to be here: https://github.com/toowoxx/terraform-provider-packer/blob/main/provider/resource_packer_image.go#L189-L190 . These two lines need to be swapped.