Commit Graph
18297 Commits
Author SHA1 Message Date
Lucas Bajolet 4f5d8151a3 hcl2template: move initialization logic to builds
Since the initialization code was embedded in the sequential logic that
we'll be moving away from soon, we move that to the build block itself,
so we're able to invoke it in any order later on.
2023-10-11 14:28:27 -04:00
Lucas Bajolet 17cdd71a37 hcl2template: make config's cmd arguments public
Since those arguments will need to be updated from outside the
hcl2template package, we change their visibility from private to public.
2023-10-11 14:28:27 -04:00
Lucas Bajolet 1a0be5ec6f hcl2template: track unused only/except options
When a user specifies a --only/--except option in their command-line,
and it turns-out to be unused, Packer signals it with a Warning
diagnostic.

This diagnostic, in previous versions of Packer, would only state that
one option did not match anything, without stating which option did not
match a build or post-processor.

This commit tracks the usage of each option so we can report later which
of those options was not used in this warning diagnostic.
2023-10-11 14:28:27 -04:00
Lucas Bajolet 7d75e0985e hcl2template: breakdown CoreBuild creation
When processing builds, we convert build blocks/sources to a series of
CoreBuild, which contains the sequence of provisioners and
post-processors to run, and the builder to use to boot the instance and
create the image from.

This process of converting builds used to be completely sequential, and
orchestrated by the `GetBuilds' function.

This gets broken down into a `ToCoreBuild' function on the build block,
whose function is to lift and filter-out (based on --only/--except) the
core builds from a valid build block, and this gets invoked from
`GetBuilds'.
This breakdown is useful as a preparation to the DAG's introduction to
the code later on.
2023-10-11 14:28:27 -04:00
Lucas Bajolet bfa438178f hcl2template: make consts and functions public
Since these constants and functions will be later useful for the
extraction of the sequential logic in a scheduler, we change the
visibility of those now.
2023-10-11 14:28:27 -04:00
Lucas Bajolet 2c9378a07b hcl2template: use diags.Extend instead of append
Since hcl.Diagnostics supports extending it through the `Extend' method,
we might as well use it instead of manually appending a series of
diagnostics to it.
2023-10-11 14:28:27 -04:00
Lucas Bajolet a078debc66 hcl2template: remove value validation for locals
Local variables can't have a validation block in their definition, so
this step in not useful and should be removed.

Besides, since the validation was done on the local variables before
evaluation, it did nothing at all, as the PackerConfig.LocalVariables
collection gets populated during evaluation, so this is essentially a
no-op, and can be safely removed.
2023-10-11 14:28:27 -04:00
Lucas Bajolet 5870543d6c hcl2template: breakdown local variable evaluation
As with datasources, we break down the local variable evaluation in two
functions, one doing the evaluation for a local variable, and the
sequential/recursive evaluation of all the local variables lifted from
the packer template.
This, plus dependency management will let us later reuse it for another
evaluation strategy, while reusing those components as much as
possible.
2023-10-11 14:28:27 -04:00
Lucas Bajolet aee537914a hcl2template: split traversal filtering
In some cases, rather than walking through a full block of HCL in order
to lift the references to other components of a build, we only have the
expression to walk on.
From this expression, we can lift the variables as a collection of
hcl.Traversal, from which we then filter only those that interest us.

So, since this is a use-case, we split the function that lifts the
expressions from a hcl block and filter them based on the root type of
the traversal into two separate functions.
2023-10-11 14:28:27 -04:00
Lucas Bajolet 4eae2df2f1 hcl2template: break down datasource execution
Since we want to allow for independently executing datasources when
needed, we break down the logic to do so.

Each datasource will now hold a list of dependencies. For now, these
dependencies are all datasources themselves, but this may change in the
future.

Then, actual execution of the datasource is self-contained within a
method of the structure, so that we can individually execute them.

Finally, we replace the current sequential execution by a method of the
PackerConfig with an approach akin to local variable evaluation, where
we execute all the datasources one-by-one, and if they cannot be
executed, move along.
We retry this loop for as many times as we don't reach either a state
where all the datasources have been executed; or when we reach a
terminal state where datasources cannot be evaluated because of
dependencies remaining, and no changes have occurred after a try.
2023-10-11 14:28:27 -04:00
Lucas Bajolet 96a528be0a hcl2template: make datasources hold pointer refs
The `Datasources' type holds a map of datasource references to their
respective block.
In this map, the blocks were structures rather than pointer to
structures, which makes updating their contents a harder process than it
should be.

To allow for in-place changes for the datasource blocks, we change the
type of the blocks to be a pointer instead.
2023-10-11 14:27:25 -04:00
Lucas Bajolet a80a61c40d hcl2template: rework parsing logic
In previous versions of Packer, the parser would load a HCL file (in
either HCL or JSON format), and process it in phases.
This process meant that if the file was not valid in the first place,
we'd have some duplicate errors first.

Another thing is that sources and build blocks were not being parsed at
the beginning of the parsing phase at all, but were discovered later in
the process, when the data sources have been executed and variables have
been evaluated.

This commit changes the parsing to happen all at once, so we parse the
files with the parser, which will fail should one file be malformatted,
then we visit the body once using the top-level schema for a Packer
build template, handling misplaced blocks once in the process.

Then, since the builds and sources may contain some dynamic blocks that
need to be expanded once their context is ready (i.e. the
variables/datasources they depend on), we can expand the build block for
them, and populate their respective objects.

This last step should also be adapted for datasources later, as they may
need to support dynamic blocks, and be expanded lazily.
2023-10-11 14:27:25 -04:00
Tor Arne Vestbø a1722abf07 website: Add community maintained IPSW data source Packer plugin 2023-10-05 14:19:52 -04:00
Lucas Bajolet 434a1637f8 hcl2template: fix func to get vars from a config
The previous implementation of the GetVarsByType function worked only on
top-level attributes, ignoring the nested blocks in the structure.

This implies that if a datasource depends on another through an
expression within a nested block, we may not execute it first, and then
executing this datasource before its dependent is possible, resulting in
an error in the end.

This commit is an attempt at making this more reliable for HCL configs,
but only works on configs lifted from HCL files for now. We need to make
this more reliable for later iterations.
2023-10-05 10:31:04 -04:00
Lucas Bajolet 51ec78622d hcl2template: simplify startDatasource function 2023-10-05 10:31:04 -04:00
Lucas Bajolet d9259d6d12 hcl2template: extract attr filter code from ds
Datasources use their attribute's expressions to determine whether or
not they depend on another datasource, in order to get the list of
dependencies and execute them before executing a datasource.

This code may be useful later on for figuring out the dependencies for
any block, so we move this code to the utils.go file, and use this for
datasources.
2023-10-05 10:31:04 -04:00
Lucas Bajolet 14b6ad10fe hcl2template: report localtion for cycle detection
When a datasource fails to be evaluated because a cycle has been
detected, we point out one of the links of the chain now so that users
have a better idea of what to look at.
2023-10-05 10:31:04 -04:00
Lucas Bajolet 2a6ccaccab hcl2template: simplify datasource evaluation
Since datasources are recursively evaluated depending on their
dependencies, we don't need to pre-execute those that depend on nothing,
as the recursive traversal of the datasources will take care of that for
us.
2023-10-05 10:31:04 -04:00
Lucas Bajolet 8438d81d4d hcl2template: remove unused shouldContinue bool
Not sure why this was defined and returned, but the value was set, but
never used, as such this is not useful to keep in the code, so let's
simplify this now.
2023-10-05 10:31:04 -04:00
Wilken Rivera 8dcc6b9fd9 Bump Go tooling version to 1.20.8 2023-10-03 10:32:42 -04:00
Wilken Rivera 8490333f55 Fix broken acctest for Amazon data source
This change updates the Ubuntu image being from 16.04 to something more recent.
2023-10-02 06:50:04 -04:00
Lucas Bajolet c0e594738b init: warn if no requirements specified
When users call `packer init' on a template that does not specify a
`required_plugin' block, the command succeeds but does nothing, which is
not helpful for users that may expect their plugins to install.

To remedy that problem, we now output a message like what `packer
plugins required' does on templates without such a block, so that users
have an idea of what to change in order to get the command to work.
2023-09-27 14:47:00 -04:00
Shengjing Zhu d56db70a57 Bump github.com/pierrec/lz4 to v4.1.18 2023-09-26 12:16:40 -04:00
guoguangwu 7eb6a45cd4 chore: remove refs to deprecated io/ioutil
Signed-off-by: guoguangwu <[email protected]>
2023-09-26 11:13:31 -04:00
guoguangwu 324e628b86 chore: unnecessary use of fmt.Sprintf
Signed-off-by: guoguangwu <[email protected]>
2023-09-21 09:38:23 -04:00
Wilken Rivera 7f7567f686 Remove plugins on the integration framework
The active plugins that resided in a HashiCorp repository have been migrated to
the integrations framework and no longer need to be listed within the plugins-manifest file.
2023-09-15 12:04:29 -04:00
Sk.Lv 6fa0d25c51 website: register ksyun docuement 2023-09-15 09:13:31 -04:00
Lucas Bajolet 318529f373 hcl2template: remove value validation for locals
Local variables can't have a validation block in their definition, so
this step in not useful and should be removed.

Besides, since the validation was done on the local variables before
evaluation, it did nothing at all, as the PackerConfig.LocalVariables
collection gets populated during evaluation, so this is essentially a
no-op, and can be safely removed.
2023-09-06 12:07:37 -04:00
Wilken Rivera 48e8c3e680 Update version output for -v and --version flags
The flags -v and --version are handled by the CLI runner, which
outputs the raw version string. This change shortcuts the handling of
the flags to force Packer to run the version subcommand.

Closes: #12565
2023-08-28 14:59:34 -04:00
Ilya Voronin 2325c7e9c7 Set ivoronin/packer-plugin-sshkey version to 'latest' 2023-08-25 10:55:11 -04:00