'packer validate' throws errors
pommetjehorlepiep opened this issue · comments
packer
version 1.8.3 is throwing validation errors.
For example on Ubuntu 22.04 Jammy base.pkr.hcl
:
❯ packer validate base.pkr.hcl
Error: Unsupported block type
on base.pkr.hcl line 4, in packer:
4: required_providers {
Blocks of type "required_providers" are not expected here.
Error: Unsupported block type
on base.pkr.hcl line 4, in packer:
4: required_providers {
Blocks of type "required_providers" are not expected here.
Format has changed (for virtualbox for example)
from
required_providers {
virtualbox = {
source = "github.com/hashicorp/packer-plugin-virtualbox"
version = ">= 1.0.0, < 2.0.0"
}
}
to
required_plugins {
virtualbox = {
source = "github.com/hashicorp/virtualbox"
version = ">= 1.0.0, < 2.0.0"
}
}
Thanks, @pommetjehorlepiep . I don't have an easy way/place to test these at the moment so your help is appreciated.
https://hacktoberfest.com/ is just around the corner too in case folks were keen to try doing some pull-requests.
@tylert the partial fix doesn´t solve the problem (at least for me using 22.04 Jammy)
I now get this:
Error: Unsupported block type
on base.pkr.hcl line 4, in packer:
4: required_providers {
Blocks of type "required_providers" are not expected here.
Error: Unsupported block type
on base.pkr.hcl line 4, in packer:
4: required_providers {
Blocks of type "required_providers" are not expected here.
Changing required_providers
to required_plugins
solves the above issue.
But then a new issue is raised:
Error: Error in function call
on base.pkr.hcl line 305:
(source code not available)
with var as object with 52 attributes,
var.user_data_location as "user-data".
Call to function "templatefile" failed: user-data:119,20-29: Unsupported
attribute; This object does not have an attribute named "username"., and 1 other
diagnostic(s).
Error: Error in function call
on base.pkr.hcl line 364:
(source code not available)
with var as object with 52 attributes,
var.user_data_location as "user-data".
Call to function "templatefile" failed: user-data:119,20-29: Unsupported
attribute; This object does not have an attribute named "username"., and 1 other
diagnostic(s).
Well, it's clear that Packer uses a slightly different syntax in the "packer" block than other HashiCorp tools (e.g.: https://www.terraform.io/language/providers/requirements#requiring-providers).
@pommetjehorlepiep I made the "easy" changes suggested by the output above but the rest is likely to be a bit more involved. If you would like to try solving this issue and submit a pull-request, I'll be happy to merge it in. Otherwise, I'm not likely going to be able to do much about the remaining validation errors you were seeing here.