Hi I have this definition into image.pkr.hdl
source "googlecompute" "base" {
project_id = var.project_id
source_image_family = var.source_image_family
ssh_username = "packer"
zone = var.zone
image_name = "base"
network = "packer"
subnetwork = "packer"
}
and I have this variables.pkr.hcl file
variable "project_id" {
type = string
}
variable "source_image_family" {
type = string
default = "centos-7"
}
variable "zone" {
type = string
default = "us-east1-b"
}
I run this command
packer validate -var 'zone=us-east1-b' -var 'source_image_family=centos-7' -var 'project_id=mcc-digital-lab' image.pkr.hcl
But I get this error:
A "zone" variable was passed in the command line but was not found in known
variables. To declare variable "zone", place this block in one of your .pkr
files, such as variables.pkr.hcl
Error: Undefined -var variable
A "source_image_family" variable was passed in the command line but was not
found in known variables. To declare variable "source_image_family", place this
block in one of your .pkr files, such as variables.pkr.hcl
Error: Undefined -var variable
A "project_id" variable was passed in the command line but was not found in
known variables. To declare variable "project_id", place this block in one of
your .pkr files, such as variables.pkr.hcl
Is it a internal misbehaving of packer validation?
I can create the image with the same files.
The packer version is 1.6.4
Try packer validate -var 'zone=us-east1-b' -var 'source_image_family=centos-7' -var 'project_id=mcc-digital-lab' .
-- when you're using HCL and want to split your image and variables files, you need to call the packer build command against the whole project directory, not against the image file. Otherwise Packer will not try to load the other files in the directory.
Most helpful comment
Try
packer validate -var 'zone=us-east1-b' -var 'source_image_family=centos-7' -var 'project_id=mcc-digital-lab' .
-- when you're using HCL and want to split your image and variables files, you need to call the packer build command against the whole project directory, not against the image file. Otherwise Packer will not try to load the other files in the directory.