Commit graph

777 commits

Author SHA1 Message Date
Lucas Bajolet
548893bbee build: don't suggest lack of HCP support on fail
When running a build with HCP Packer enabled, Packer attempts to push
the build status to HCP.
If the build fails, we update the status to BUILD_FAILED, and that's the
end of it.
If however the build succeeds, Packer attempts to get the HCP artifact
from the builder, which will only succeed if the builder supports it.
Otherwise, we'll get either nil, or an artifact type that is not
compatible with what is expected for HCP support.

When either of those happens, we warn that the builder may not support
HCP Packer at all, so users are aware of the problem.

However, when the error was introduced, it only looked at the fact that
an error was produced, independently of the type of error. This caused
legitimate errors while building to be reported as potential
incompatibility between the builder and HCP, which was confusing to
users.

This commit changes this by introducing a new error type, only produced
when the artifact either is nil, or failed to be deserialised into a HCP
artifact, which lets us produce the incompatibility warning with more
accuracy.
2024-02-13 14:47:06 -05:00
Wilken Rivera
12b8c885a3
Update error messaging for HCP incompatible plugin builds (#12800)
* Update error messaging for HCP incompatible plugin builds

* Update command/build.go

Co-authored-by: Lucas Bajolet <105649352+lbajolet-hashicorp@users.noreply.github.com>

---------

Co-authored-by: Lucas Bajolet <105649352+lbajolet-hashicorp@users.noreply.github.com>
2024-01-25 11:32:18 -05:00
Devashish
3fa637c608
Migrate HCP Packer to API V2 and new nomenclature changes (#12794)
* add hcp packer new nomenclature updates

* Update docs with nomenclature changes

* Update navigation bar links

* Bump github.com/hashicorp/hcp-sdk-go from 0.81.0 to 0.82.0

* fix acceptance test template

---------

Co-authored-by: sylviamoss <moss@hashicorp.com>
Co-authored-by: Wilken Rivera <dev@wilkenrivera.com>
2024-01-24 13:17:35 -05:00
Lucas Bajolet
6c99f387a0 packer: remove single-component plugins
Single-component plugins are a relic from the past that has been
deprecated from version 1.7.0 and onwards.

Since we're revisiting how plugins are installed/loaded, and the changes
will be incompatible with those, we remove them in preparation of this
work.
2024-01-12 09:06:22 -05:00
Wilken Rivera
2241b1fba7 Update spacing for flags within Help text
Before Change
```

Options:
  - path <path>: install the plugin from a locally-sourced plugin binary. This
                 installs the plugin where a normal invocation would, but will
                 not try to download it from a remote location, and instead
                 install the binary in the Packer plugins path.
                 This option cannot be specified with a version constraint.
  - force:       forces reinstallation of plugins, even if already installed.

```

After Change
```
Options:
  -path <path>                  Install the plugin from a locally-sourced plugin binary.
                                This installs the plugin where a normal invocation would, but will
                                not try to download it from a remote location, and instead
                                install the binary in the Packer plugins path. This option cannot
                                be specified with a version constraint.
  -force                        Forces reinstallation of plugins, even if already installed.
```
2023-12-06 07:29:10 -05:00
Lucas Bajolet
97e2e9e637 docs: add exerpt on packer plugins install --path 2023-12-04 16:34:31 -05:00
Lucas Bajolet
8e2a22e583 command: simplify local binary installation
Read original binary into memory to fix case when installation
destination and source were the same, resulting in an empty binary.
2023-12-04 16:34:31 -05:00
Lucas Bajolet
e293f2d890 command: plugins install reject non-releases
When installing a plugin with packer plugins install --path, we only
accept release versions of a plugin, as otherwise the loading can be
inconsistent if for example a user specifies a required_plugins block in
their template, in which case the plugins will be ignored.

Until we have a simpler loading scheme then, we will reject non-release
versions of plugins to avoid confusion.
2023-12-04 16:34:31 -05:00
Lucas Bajolet
ae5b91864c command: reject version with --path for install
To avoid plugins being installed with a specific version when a path is
used for installing a plugin from a locally sourced plugin binary, we
explicitly reject the combination of both a path and a version for
plugins install.
2023-12-04 16:34:31 -05:00
Lucas Bajolet
a2d9c9dce4 command: add --force option to init/install
The --force option for packer init and packer plugins install enforces
installation of a plugin, even if it is already locally installed.

This will become useful if for some reason a pre-existing plugin
binary/version is already installed, and we want to overwrite it.
2023-12-04 16:34:31 -05:00
Lucas Bajolet
6f43a82e02 command: add packer plugins install path flag
This new flag allows the `packer plugins install' command to install a
plugin from a local binary rather than from Github.

This command will only call `describe' on the plugin, and won't do any
further checks for functionality. The SHA256SUM will be directly
computed from the binary, so as with anything manual and potentially
sourced by the community, extra care should be applied when invoking
this.
2023-12-04 16:34:31 -05:00
Wilken Rivera
ebaf831562 cmd/hcl2upgrade: Add VirtualBox as known plugin 2023-11-28 15:15:09 -05:00
Lucas Bajolet
f221a799d8 command: error on invalid plugins remove
If a user attempts to remove a plugin through the `packer plugins
remove' subcommand, and the specified plugin is not installed, the
command succeeds, but does nothing, and exits silently.

This is not clear what is happening, and arguably, calling a command
that does nothing, not even explain what went wrong, is not intuitive.

Because of that, this commit changes how the command behaves in this
case, stating what went wrong, and exiting with a non-zero status.
2023-10-31 11:28:50 -04:00
Lucas Bajolet
d47cbe7f48 command: remove SHA256SUM file on plugin removal
When a user invokes `packer plugins remove', the plugin binary gets
removed, but not the corresponding SHA256SUM file.

This patch changes this so that when a binary is removed, so is its
SHA256SUM file.
2023-10-26 12:49:36 -04:00
Wilken Rivera
da061169bc cmd/hcl2_upgrade: Don't error when using a HashiCorp plugin that is not installed
This change updates hcl2_upgrade to not flag known plugin components, those used for generating the required plugins
block, when upgrading a legacy JSON template to HCL2. Any unknown plugins will be installed after running packer init
on the generated template so we don't error. We may want to suggest running packer init to install any missing plugins.

* Move knownPluginPrefixes into the hcl2_upgrade command
2023-10-24 06:00:42 -04:00
Wilken Rivera
e8d5436228 Remove functions for detecting plugin usage
With the removal of vendored_plugins we are no longer interested in tacking bundled plugins usage.
For plugins such as file, null, or anything bultin into Packer we don't track because there is no
way to install them outside of Packer, for now.
2023-10-24 06:00:42 -04:00
Wilken Rivera
c65bb2fdca Remove amazon plugin from acceptance test 2023-10-24 06:00:42 -04:00
Wilken Rivera
ac71611cf5 Remove all HashiCorp vendored plugins 2023-10-24 06:00:42 -04:00
Lucas Bajolet
020f18e37f command: remove unused FlagSetFlags enum
The enumeration for FlagSetFlags, which presumably was added when the
Meta structure was introduced, aims to pre-populate the flagset for a
subcommand with a series of arguments.

However, despite it being documented, it is actually not used, and
therefore can safely be removed from the codebase.
2023-10-16 09:51:53 -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
guoguangwu
7eb6a45cd4 chore: remove refs to deprecated io/ioutil
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
2023-09-26 11:13:31 -04:00
guoguangwu
324e628b86 chore: unnecessary use of fmt.Sprintf
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
2023-09-21 09:38:23 -04:00
Lucas Bajolet
eb9e1a4795 packer: remove implicit required plugins
Since this feature is no longer something we plan to activate later, as
it contradicts with our efforts to remove bundled plugins, and
encouraging users to move to either manually installing plugins, or
managing them through `packer init', we clean-up the code for this
feature.
2023-08-17 16:51:49 -04:00
hashicorp-copywrite[bot]
19055df3ec
[COMPLIANCE] License changes (#12568)
* Updating the license from MPL to Business Source License

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl.

* Update copyright file headers to BUSL-1.1

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-10 15:53:29 -07:00
Wilken Rivera
99c79ecbd6
Add build tags to skip amd64 tests on darwin/arm64 (#12549) 2023-08-02 15:34:06 -04:00
Lucas Bajolet
3512a175a6 command: change wording for init's postitional arg
`packer init' is meant to be invoked on a template file or a directory.
This was described in the command-line help message as
`[template.pkr.hcl|folder]'.

Because this is encapsulated between square brackets, this could be
taken as an option instead of a positional, mandatory argument.

This commit changes the wording to adopt a similar convention as `packer
build', so the two are consistent in how they are invoked, and to avoid
mistaking this argument as optional.
2023-07-25 16:45:32 -04:00
Lucas Bajolet
d0198c8a17 packer: track bundled plugins usage on telemetry 2023-07-25 15:43:47 -04:00
Lucas Bajolet
b522edca36 hcl2_upgrade: add required_plugins in out template
When a legacy JSON template references built-in plugins, we add them to
the resulting template as a `required_plugins' block in HCL2.
2023-07-18 16:04:55 -04:00
Lucas Bajolet
a2930bda4f packer: warn on bundled plugins usage
Since bundled plugins will be removed in an upcoming version of Packer,
this commit adds a new warning message whenever a template uses one such
plugin.

This warning has been implemented on build, validate, console and the
inspect subcommands.

In addition to warning about the upcoming change and potential issue
this will cause, this warning message proposes solutions to the user so
they know what they'll have to do in order not to rely on those bundled
plugins later.
2023-07-18 15:36:12 -04:00
Wilken Rivera
8982d4f168
Migrate external Parallels plugin to Parallels/packer-plugin-parallels (#12476)
* Update external plugin documentation source

The Parallels plugin for Packer is now maintained by the Parallels team, under
their respective GitHub org. This changes updates the source address for
the external plugin that should be used for pulling new plugin
documentation.

* Removed packer-plugin-parallels for list of vendored plugins
2023-07-03 14:13:08 -04:00
Wilken Rivera
d67bacc8d3
Remove community plugins from the vendored plugins list (#12436)
This step removes community plugins from the Packer binary release. These plugins are being maintained and released independently of Packer and have become out of date. To ensure users are using the latest version of the plugins they are being removed in favor of the external plugin installation processes.
2023-05-30 11:25:28 -04:00
Wilken Rivera
06fe087097
Merge pull request #12380 from hashicorp/bump-go-1.20
Bump Go tooling to version 1.20
2023-04-28 13:57:32 -04:00
Wilken Rivera
65f6428fce
Remove external archived provisioner plugins (#12374)
This change removes a set of plugins that have not been updated in a while. These
plugins have been archived for some time now. Users wishing to continue using these plugins
should use the `packer plugins install` or `packer init` commands to install the external plugin.
2023-04-28 13:52:49 -04:00
Wilken Rivera
13a24db0de
Remove IONOS plugins from vendored plugins (#12385)
* Remove profitbricks plugin
* Remove oneandone plugin

The following plugins have been unmaintained for some time now, and their
upstream cloud provider has consolidate the services. These plugins
will continue to be available to Packer via direct installation using
packer init or the packer plugins install command. But they will no longer
be bundled with Packer.
2023-04-28 13:31:09 -04:00
Wilken Rivera
eca75a6847 Run make fmt to fix checks 2023-04-27 15:17:31 -04:00
Wilken Rivera
ddd7ee98b6 Bump go.mod to 1.20
* Fix go vet issue

* Bump Go tooling to version 1.20

* Update workflows to use go-version file
2023-04-27 15:11:48 -04:00
Wilken Rivera
08d1dfe36c
Remove external plugin for Digital Ocean (#12376)
The Digital Ocean plugin is now maintained and released by the Digital Ocean team.
To ensure users are downloading the latest available version the plugin will nolonger
be bundled with Packer.
2023-04-26 14:06:57 -04:00
Lucas Bajolet
31921f0c9f packer: track template type in spans
The template type for a builder, provisioner, post-processor or
datasource was not tracked with telemetry data.

This commit adds the infrastructure to track this, bumping the schema
for non-crashes to `beta/packer/6' at the same time.
2023-04-18 11:19:21 -04:00
Wilken Rivera
e0a5286645
cmd/console: Add config-type flag to command help (#12360)
It is not clear that the console command runs in legacy JSON mode by
default and that users can specify the -config-type flag to toggle HCL2
mode. This change adds the config-type flag to the command's help text
to alert users of the gotcha.

In the next minor Packer release the console command will be updated to
default to HCL2 mode.

Relates to: #12359
Relates to: #10603
2023-04-12 14:27:39 -04:00
Wilken Rivera
f678c06396
Migrate external UCloud plugin to ucloud/packer-plugin-ucloud (#12335)
* Update external plugin documentation source

The UCloud plugin for Packer is now maintained by the UCloud team, under
their respective GitHub org. This changes updates the source address for
the external plugin that should be used for pulling new plugin
documentation.

* Remove packer-plugin-ucloud from vendored plugins.
2023-04-04 20:47:47 -04:00
Wilken Rivera
20c2d48df7
Migrate external Linode plugin to linode/packer-plugin-linode (#12329)
* Update external plugin documentation source

The Linode plugin for Packer is now maintained by the Linode team, under
their respective GitHub org. This changes updates the source address for
the external plugin that should be used for pulling new plugin
documentation.

* Removed packer-plugin-linode for list of vendored plugins

The Linode plugin for Packer is now maintained by the Linode team, under
their respective GitHub org. This changes removes Linode from the vendored plugins
lists.
2023-03-29 12:43:50 -04:00
hashicorp-copywrite[bot]
b7df3ca36f
[COMPLIANCE] Add Copyright and License Headers (#12254)
Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-03-02 15:37:05 -05:00
Wilken Rivera
095959ed6d Fix crash when variables block is undefined
This change fixes a crash that occurs when trying to add undeclared variables into an empty
variables map. The variables block when defined will always be non-nil but in the case
where variables are declared and initialized from a legacy JSON variables file the map
must be initialized first.
2023-02-08 13:40:36 -05:00
Lucas Bajolet
ec1d2e68f5 hcp: generate fingerprints on each new build
Fingerprints are how we link a packer build to an iteration on HCP.
These are computed automatically from the Git SHA in the current state,
and are unique to the bucket/iteration.

The main problem with this approach is that while sound in theory, it
quickly falls apart when users want to run the same build configuration
twice, but expect a new image to be created.

With the current model, this fails, as the iteration with the current
SHA already exists.

While this is solvable through environment variables, or by committing a
change to the repository, we think this is not clear enough, and causes
an extra step to what should otherwise be a simple process.

Therefore, to lower the barrier of entry into HCP, we change this
behaviour with this commit.

Now, fingerprints are randomly generated ULIDs instead of a git SHA, and
a new one is always generated, unless one is already specified in the
environment.

This makes continuation of an existing iteration a conscious choice
rather than something automatic, and virtually eliminates conflicts such
as the ones described above.
2023-01-25 15:29:26 -05:00
Lucas Bajolet
4d559e23b7
hcl2: don't warn on excluded post-processor (#12187)
* hcl2template: use && for chaining conditions

For deciding if we need to run an error provisioner block, we checked
using a nested if that we didn't need to avoid running it.

This is unnecessary, and adds a superfluous level of inbrication to the
code, so we chain both conditions with &&.

* hcl2: don't warn on excluded post-processor

When a post-processor is excluded through the -except command-line
argument for packer build, we used to print a warning on HCL2 templates
if this except statement did not match a build.

However, since we can use the except option to avoid running
post-processors, we should account for this as well when printing out a
warning that there were no matches.

This commit adds this counter to the except checks for the
post-processors as well.
2023-01-11 14:30:02 -05:00
Lucas Bajolet
ca197afe9b hcp: remove superfluous return value on GetBuilds
This commit irons out one of the pain points of the HCP rework by
introducing a HCPPublisher interface, implemented both by the JSON Core,
and the HCL2 PackerConfig, which keeps a map of the build names used by
Packer to the build names pushed on HCP.

This in turn lets us go back to the old implementation of the GetBuilds
function, which returns a list of (filtered) builds, and eventually an
error if something went wrong while processing.
2022-12-22 16:06:34 -05:00
Wilken Rivera
9002ac263f
Update BuildBlock with valid HCL2Ref (#12167)
While looking into #11932 I found that Packer will throw an error when
an unknown source is referenced from within the sources attribute for
a build block. The hcl.Diagnostics error includes a Subject, which
should highlight where in the HCL2 configuration file the unknown source resides.
But when creating the BuildBlock no HCL2Ref data is copied over, thus the
Subject is displayed with with zero value for an hcl.Range type.

This change updates the build creation logic to copy the HCL2Ref data
from the build block at decode time so that it can be properly
referenced downstream.

Closes #11932

Failure due to change in output
```
--- FAIL: TestValidateCommand_ShowLineNumForMissing (0.00s)
    --- FAIL: TestValidateCommand_ShowLineNumForMissing/test-fixtures/validate-invalid/missing_build_block.pkr.hcl (0.00s)
        validate_test.go:377: Unexpected output:   (
                """
                Error: Unknown source file.cho

            -     on  line 0:
            +     on test-fixtures/validate-invalid/missing_build_block.pkr.hcl line 6:
                  (source code not available)

                ... // 4 identical lines
                """
              )
        validate_test.go:379:
FAIL
FAIL    github.com/hashicorp/packer/command     1.002s
```
2022-12-20 15:37:59 -05:00
Wilken Rivera
3b9274aa04
command/validate: Add -evaluate-datasources flag to command help text (#12152)
```
Usage: packer validate [options] TEMPLATE

  Checks the template is valid by parsing the template and also
  checking the configuration with the various builders, provisioners, etc.

  If it is not valid, the errors will be shown and the command will exit
  with a non-zero exit status. If it is valid, it will exit with a zero
  exit status.

Options:

  -syntax-only                  Only check syntax. Do not verify config of the template.
  -except=foo,bar,baz           Validate all builds other than these.
  -only=foo,bar,baz             Validate only these builds.
  -machine-readable             Produce machine-readable output.
  -var 'key=value'              Variable for templates, can be used multiple times.
  -var-file=path                JSON or HCL2 file containing user variables, can be used multiple times.
  -no-warn-undeclared-var       Disable warnings for user variable files containing undeclared variables.
  -evaluate-datasources         Evaluate data sources during validation (HCL2 only, may incur costs); Defaults to false.

```
2022-12-12 13:14:25 -05:00
Wilken Rivera
dbeeab448a
cmd/hcl2_upgrade: Generate variable block for all referenced user input variables (#12136)
Currently the HCL2 upgrade command generates a valid variable block for all variables
within the JSON variables property. However JSON templates in Packer support variable
interpolation for input variables defined within a variable definition file without
it being declared within the variables property. When upgrading a JSON template to HCL2
the user variable reference gets converted to var.<var_name>. The upgraded template ultimately
fails on validation or build execution with undefined variable errors, with this change the upgrade
command will now create a variable block for all input variables referenced within the build template
to ensure all required variables been defined.
2022-11-30 15:25:25 -05:00
Lucas Bajolet
bb2384c56a command/validate: add option to eval datasources
When packer validate is invoked, it does not try to evaluate the
datasources before attempting to decide if the template is valid.

In many cases, this works, but sometimes it will fail as the value is
unknown by the validation code.

Since the validation code for all the elements of a Packer template is
left to be implemented by plugins, we cannot rely on checking for
unknown values everywhere, especially since the unknown references are
replaced automatically by a value of the right type for the
configuration expected.

So, in order for such configurations to be validable, we add an extra
option to packer validate, that will let users evaluate the datasources
from a template.
2022-11-17 09:29:55 -05:00