Closed puetzk closed 1 year ago
Unfortunately, that's Packer's limitation - it doesn't execute datasources in validation mode:
Therefore data.sshkey.packer.private_key_path
is undefined during validate
run.
Would running packer validate -syntax-only .
serve as a workaround?
I suppose it could, though it's obviously lets more things slip through.
It looks like when it skips executing, in places specific cty.UnknownVal
placeholders. I wonder if one could build on that to realize that these are values that (presumably) will be supplied by the datasource in a real run (maybe using https://github.com/zclconf/go-cty/blob/main/docs/marks.md), and then ignore only those fields during validation, and ignore validation of fields that come out incompletely-defined because they have a datasource-provided thing in them.
But that would indeed be an issue for packer, not your plugin.
FYI, there is a dev's reply regarding this behavior in a similar issue: https://github.com/hashicorp/packer/issues/11197#issuecomment-903578817 I'll leave this issue open and wait for updates from the Packer team.
Another possible workaround is to exclude all builds and perform a dry run:
$ packer build -only=non-existant openbsd.pkr.hcl
Warning: an 'only' option was passed, but not all matches were found for the given build.
Possible build names: [qemu.base.img qemu.full.img].
These could also be matched with a glob pattern like: 'happycloud.*'
==> Wait completed after 2 microseconds
==> Builds finished but no artifacts were created.
As mentioned in https://github.com/hashicorp/packer/pull/12106 packer 1.8.5 now has a -evaluate-datasources
parameter which solves this issue.
Thanks @ivoronin for the link ! it helped me find the solution
When given input like sshkey.pkr.hcl
packer validate sshkey.pkr.hcl
fails with(the same is true for real builders, but this minimal example shows the issue)