Commit graph

12 commits

Author SHA1 Message Date
Lucas Bajolet
61c810e720 command: rework HCP-related error messages
The HCP error messages were sometimes a bit terse in terms of the
information it bubbles up to the user.
This made them useful for people who already knew what to look for, but
newcomers would almost certainly be lost because of the lack of
information in those.

To improve on this situation, we reword most of those error messages in
this commit.
2022-10-21 10:32:45 -04:00
Lucas Bajolet
35496e533d packer: include builder type in HCP name for JSON
JSON templates used only to report the builder's type in HCP builds,
even if the name was specified.

This commit changes this behaviour to include both if they're available,
in a similar fashion as what is done on the HCL2 templates.
2022-10-20 17:12:33 -04:00
Wilken Rivera
12e9316f94 Add documenation for HCPConfigMode type 2022-10-13 15:13:29 -04:00
Wilken Rivera
148d5e3a2d Add initialize method to Iteration
Fingerprint initialize was previously occurring during the creation of a
bucket. We want to be able to initialize a bucket and defer the setting
of a fingerprint to a later point.

* Update test to reflect new function signatures for Bucket and Iteration
2022-10-13 15:13:29 -04:00
Wilken Rivera
7f7f397124 Rename withHCLBucketConfiguration function 2022-10-13 15:13:29 -04:00
Wilken Rivera
a4a97d5c05 Move datasource data into its own bucketConfiguratioOpts func 2022-10-13 15:13:29 -04:00
Wilken Rivera
cf9304266e Consolidate bucket configuration logic 2022-10-13 15:13:29 -04:00
Lucas Bajolet
b3188637bf registry: load bucket slug in command/registry
Loadgin the slug from the environment within the Bucket implied that the
Bucket was successfully created, which may fail outside of a Git
directory when the iteration fingerprint is not set through environment
variables.

To make it possible to print as much information regarding the
environment to the users at once rather than stopping immediately when
this step fails, we move the logic to read the default value from the
environment to the HCP setup code.
2022-10-13 15:13:29 -04:00
Lucas Bajolet
9267d933bc command: report multiple errors in bad HCP config
When HCP is detected to be enabled, but some configuration is missing,
we returned immediately on the first error.

This commit changes this behaviour by reporting every error at once, so
users will know immediately if something is wrong when they invoke
Packer with HCP support, and one or more environment variables is not
defined as we'd expect them.
2022-10-13 15:13:29 -04:00
Lucas Bajolet
ae15ed339c registry: add function to detect explicit HCP
The HCP_PACKER_REGISTRY environment variable had its behaviour changed
recently, as prior versions of Packer expected the attribute to be
forcefully set to a value that is neither "off" nor "0" in order to
get HCP integration to work, or that a "hcp_packer_registry" block was
defined in an HCL template. Now, this environment variable defaults to
not explicitely enable, but instead to explicitely disable HCP
integration, and the feature switch fall upon HCP_PACKER_BUCKET_NAME.

As an extra feature, we keep the prior behaviour alive when it is
explicitely defined as a value to enable it. That way we can report
errors if the rest is not defined, rather than silently ignore it.

This function we add to env is the first stone to enable this behaviour.
2022-10-13 15:13:29 -04:00
Lucas Bajolet
779a31a25f hcp: use HCP_PACKER_REGISTRY to disable HCP
The current behaviour for HCP integration is based on the presence of
the HCP_PACKER_REGISTRY environment variable, where if it is either not
"0" or "off", the HCP integration is enabled.

This commit changes the behaviour to only use this variable to
explicitely disable HCP, and the HCP_PACKER_BUCKET_NAME variable will
condition if the HCP integration is enabled for a build or not in JSON
templates.

For HCL templates, the integration can also be disabled if the
HCP_PACKER_REGISTRY variable is set to "0" or "off", and will be
considered enabled if the HCP_PACKER_BUCKET_NAME is set, or there is a
"hcp_packer_registry" block in a build.
2022-09-19 11:22:13 -04:00
Lucas Bajolet
7cd095062a parser: extract HCP logic out of the HCL parser
Before this commit, some HCP-related logic was embedded in the parser,
making all of it common to all commands.

This complexifies the logic as some parts rely on the template being in
a HCP-valid environment, and the datasources need to be evaluated in
order for some operations to be executed.

To simplify this and avoid those pitfalls, we move this logic to its own
set of functions that will be performed after the parsing is done, on
any valid HCL2 or JSON template.
2022-08-12 11:54:21 -04:00