Commit graph

18731 commits

Author SHA1 Message Date
trujillo-adam
b42e78ae1a
Merge pull request #13272 from hashicorp/docs/packer-seo-builders-plugins
Docs/packer seo builders plugins
2025-01-24 14:13:26 -08:00
trujillo-adam
9fd83c155c
Apply suggestions from code review
Co-authored-by: Brian McClain <brianmmcclain@gmail.com>
2025-01-24 14:08:16 -08:00
trujillo-adam
85ff38ff38
Merge pull request #13267 from hashicorp/docs/packer-seo-ds-ref
seo improvements data sources references
2025-01-24 13:55:35 -08:00
trujillo-adam
9cf014fa08
Apply suggestions from code review
Co-authored-by: Brian McClain <brianmmcclain@gmail.com>
2025-01-24 13:50:20 -08:00
trujillo-adam
da35666689 buiders, plugins, and some top-level pages 2025-01-23 16:02:43 -08:00
trujillo-adam
711a38bdd4 intro articles 2025-01-23 11:02:12 -08:00
trujillo-adam
8eb277b122 seo improvements data sources references 2025-01-21 19:30:41 -08:00
Devashish
2e609231b4 website: add docs for the hcp-sbom provisioner 2025-01-21 16:57:50 -05:00
Jenna Goldstrich
8dcd9fe1a5 Ensure org ID is set and move UploadSbom to api package 2025-01-21 16:57:50 -05:00
Jenna Goldstrich
347c57306c hcp: use enum for HCP SBOM upload
Since the protos for uploading an SBOM for a build have been changed to
use an enumeration instead of a plain string with the latest revisions
to the HCP Packer SBOM support feature, we update how we reference those
values for the SBOM format to use that enum instead.
2025-01-21 16:57:50 -05:00
Lucas Bajolet
619c524afb command: exit non-zero if uploading to HCP failed
In the current state, a Packer build that succeeds but fails to push its
metadata to HCP for reasons other than a lack of artifact will always
succeed from the perspective of a user invoking `packer build`.

This can be a bit misleading, as users may expect their artifacts to
appear on HCP Packer if their build succeeded on Packer Core, so this
commit changes this behaviour, instead reporting HCP errors as a real
error if the build failed, so packer returns a non-zero error code if
this happens.
2025-01-21 16:57:50 -05:00
Lucas Bajolet
9b3f29faf9 hcp: wrap completeBuild to mark as failed on error
When a build cannot be completed without errors, the build state was
left as running, unless the build explicitly failed, which meant that
HCP Packer would be responsible for changing the status after the
heartbeats for the build stopped being sent for two 5m periods.

This commit changes this behaviour, by explicitly marking the build as
failed if something did not work while trying to complete a build on HCP
Packer, even if the local Packer core build succeeded before that.
2025-01-21 16:57:50 -05:00
Jenna Goldstrich
362c547211 hcp: integrate SBOM upload to HCP code
Since packer now supports keeping track of SBOMs produced during a
build, we add the code to integrate those changes into the internal/hcp
package, so we do upload them on build completion.
2025-01-21 16:57:50 -05:00
Lucas Bajolet
a8c9467463 packer_test: add integration tests for hcp-sbom 2025-01-21 16:57:50 -05:00
Devashish
a353260f5d packer: add hcp-sbom provisioner
The hcp-sbom provisioner is a provisioner that acts essentially like a
download-only file provisioner, which also verifies the file downloaded
is a SPDX/CycloneDX JSON-encoded SBOM file, and sets up its upload to
HCP Packer later on.
2025-01-21 16:57:50 -05:00
Lucas Bajolet
56400f27cb packer_test: add gob/pb test suite
With the draft to support both gob and protobuf as serialisation formats
for Packer, along with the SDK changes that propel them, we add a series
of tests that make sure the logic that picks which protocol is solid and
functional.

These tests rely on building several versions of the tester plugin, with
and without protobuf support, to then install them in the tests as
needed to test the logic of Packer using packer build with them, and
templates that require multiple plugins.
2025-01-21 16:44:03 -05:00
Lucas Bajolet
9f6f0ba6a2 packer: pick protobuf/gob for serialisation (#13025)
As we're trying to move away from gob for serialising data over the
wire, this commit adds the capability for Packer to pick dynamically
between gob or protobuf for the serialisation format to communicate with
plugins.

As it stands, if all the plugins discovered are compatible with
protobuf, and we have not forced gob usage, protobuf will be the
serialisation format picked.

If any plugin is not compatible with protobuf, gob will be used for
communicating with all the plugins that will be used over the course of
a command.
2025-01-21 16:44:03 -05:00
Lucas Bajolet
9f3e32b9fc hcl2template: add support for raw aws secrets
As the SDK now supports it in the context of legacy templating engine,
we add support in HCL2 for the aws_secretsmanager_raw function, which
gets the raw value of a secret from aws secrets manager.
2025-01-21 14:39:49 -05:00
Jenna Goldstrich
cf6a82fae8 Make error less brittle to fix upcoming error with HCP SDK Go changing how we return 404 error 2025-01-21 11:33:32 -08:00
Lucas Bajolet
dddc1fb356 go.mod: bump Packer plugin SDK to v0.6.0
Since the version 0.6.0 of the plugin SDK was released yesterday, we
bump packer to use this version.
This change adds new functions to use within Packer regarding AWS
secretsmanager, along with changes to how plugins can communicate
over-the-wire (e.g. using protobuf/msgpack for serialising
configurations instead of gob).
2025-01-21 11:29:53 -05:00
Joban
2ff129cd34 fix(example): make UUIDv4 example RFC compliant
# Description

The output of the example on [uuidv4 Function](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/uuid/uuidv4) is not a valid RFC compliant UUIDv4. It indicates the usage of the `uuidv4()` function and outputs `b5ee72a3-54dd-c4b8-551c-4bdc0204cedb` which is not a valid UUIDv4.

I've corrected the example to output a UUIDv4 conforming to the RFC as such `xxxxxxxx-xxxx-4xxx-Nxxx-xxxxxxxxxxxx`, where:

- The 13th character is always `4` (indicating version 4).
- The 17th character must be either `8`, `9`, `a`, or `b` (indicating the first character of the variant).

# Changes

```diff
- b5ee72a3-54dd-c4b8-551c-4bdc0204cedb
+ 9fc99a70-7cd5-482d-bb2b-03af016e4e94
```

Replaces the old UUID output with a valid RFC compliant UUIDv4.

# References

- [RFC 4122](https://datatracker.ietf.org/doc/html/rfc4122)
- [RFC 9562](https://datatracker.ietf.org/doc/html/rfc9562)

# Misc.

To make sure this wasn't an issue with the `uuidv4()` function within Hashicorp's [packer](https://github.com/hashicorp/packer) I tested the function in the following way:

### Command executed:

```ps
> .\packer.exe inspect .\uuid.pkr.hcl
```

### Contents of the _uuid.pkr.hcl_ file:

```hcl
locals {
  uuid_0 = uuidv4()
  uuid_1 = uuidv4()
  uuid_2 = uuidv4()
  uuid_3 = uuidv4()
  uuid_4 = uuidv4()
  uuid_5 = uuidv4()
  uuid_6 = uuidv4()
  uuid_7 = uuidv4()
  uuid_8 = uuidv4()
  uuid_9 = uuidv4()
}
```

### Output:

```ps
Packer Inspect: HCL2 mode

> input-variables:


> local-variables:

local.uuid_0: "90877db8-5519-46ea-ae15-7dfb92594064"
local.uuid_1: "fe6a4649-97d9-4686-b981-3295175f941a"
local.uuid_2: "9944d83d-dab2-4cfb-a1db-572d19271e7a"
local.uuid_3: "547cddb7-c979-4b87-90d0-2bd9b68858b5"
local.uuid_4: "c13dc47a-552c-4dfb-a75d-2f63bb248b41"
local.uuid_5: "3db1ce29-bdde-4642-b010-1a41d47c22a3"
local.uuid_6: "4a020460-edd1-471d-b8a2-5956c0c68257"
local.uuid_7: "1845bf87-6908-4fc0-8f11-b5b4f36c60a7"
local.uuid_8: "f5c7e552-b799-45f3-8172-46162eadfd89"
local.uuid_9: "057c2eaf-6769-4a8d-90c8-775aec80496a"

> builds:
```
2025-01-21 10:13:57 -05:00
Martin Grogan
cb4965d53a hcl2template: add anytrue function
this function add the hcl2 anytrue function which takes a collection and
return true if any of the element is true.
2025-01-21 10:07:10 -05:00
Martin Grogan
476ddc3810 hcl2template: add alltrue function
add an hcl2 function that return true if all the value in a collection
are true, this function was derived from terraform codebase
2025-01-21 10:07:10 -05:00
Gustavo Cruz
7f64ca11f6 fix: packer validate unsupported type error
`packer validate` would output the same error message four times per
unsupported root block type found in a template (e.g., 'src' instead of
'source'). This behavior was due to a function being called four times
for each file on each stage of the parsing.
2025-01-21 10:06:45 -05:00
dependabot[bot]
3826a94758 build(deps): bump golang.org/x/net in /packer_test/common/plugin_tester
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.23.0 to 0.33.0.
- [Commits](https://github.com/golang/net/compare/v0.23.0...v0.33.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-21 09:49:43 -05:00
dependabot[bot]
8b2a3ccdf3 build(deps): bump github.com/hashicorp/hcp-sdk-go
Bumps [github.com/hashicorp/hcp-sdk-go](https://github.com/hashicorp/hcp-sdk-go) from 0.112.0 to 0.131.0.
- [Release notes](https://github.com/hashicorp/hcp-sdk-go/releases)
- [Changelog](https://github.com/hashicorp/hcp-sdk-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/hcp-sdk-go/compare/v0.112.0...v0.131.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/hcp-sdk-go
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-21 09:49:04 -05:00
hashicorp-tsccr[bot]
ea9d02d596 Result of tsccr-helper -log-level=info gha update .github/ 2025-01-20 17:25:44 -05:00
Lucas Bajolet
f24c978d46 go.mod: bump go-git to v5.13.0
Version 5.11.0 of the go-git library is vulnerable to two CVEs as
reported by our scanners.

Both are not impacting Packer since we only use go-git to read values
from a local Git repository, but still we upgrade our version to 5.13.0
so those reports don't apply to us.
2025-01-06 15:48:15 -05:00
Lucas Bajolet
783d5113ba release: ignore AWS SDK vulnerability for release
The reported AWS S3 vulnerability was inherited from the go-getter
module that Packer uses for downloading files from external sources.

This vulnerability only impacts S3 uploads, therefore Packer is not
vulnerable itself as go-getter only downloads such blobs.

Since the change required to fix this advisory would be to bump the AWS
SDK to v2, this being a major change, is not something to do lightly, so
we opted to ignore this advisory for now so it doesn't block upcoming
releases.
2025-01-06 15:12:19 -05:00
Martin Grogan
024bf7259a docs: make TMPDIR clickable
The option is less visible than the other one and by adding the quote,
it creates an anchor that will make it easier to link.
2024-12-23 15:18:33 -05:00
Lucas Bajolet
77bf0282a7 go.mod: bump golang.org/x/net to v0.33.0
The version of golang.org/x/net that we're using (v0.25.0) is vulnerable
to GO-2024-3333, a DoS vulnerability.
Packer is not particularly vulnerable to this, as we are not a hosted
service, but since security scanners report this, and the fix is rather
simple, we address it today.
2024-12-20 13:47:18 -05:00
dependabot[bot]
38f081c9ed build(deps): bump golang.org/x/crypto
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.21.0 to 0.31.0.
- [Commits](https://github.com/golang/crypto/compare/v0.21.0...v0.31.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-12-20 11:11:20 -05:00
Martin Grogan
5940ab6d64 docs: put hcl2 example in first tab 2024-12-20 10:39:32 -05:00
Lucas Bajolet
b6141fd532 command: copy AWS plugin structures for upgrade
The hcl2_upgrade command transforms a JSON template into an HCL2
template for use with Packer.

The command is quite fragile already, but given that this is the last
remaining fragment that causes Packer to depend on the AWS SDK directly,
we can do away with it.

This commit therefore imports the definitions for AWS access config, so
we can extract this information from the JSON template, and include it
in the definition of the output source for AWS, since we manage this one
differently from other sources.

This allows us to not depend on the AWS plugin directly, which in turn
makes Packer not need to link with the AWS plugin when compiling the
executable.
We are still depending on the AWS SDK for now since the SDK exposes a
aws_secretsmanager function that can be used for interpolation (legacy
JSON interpolation to be clear), so this cannot be removed from now, but
we should consider some form of remediation in the future.
2024-12-17 17:42:58 -05:00
Lucas Bajolet
cd009b0f3b go.mod: bump x/crypto to v0.31.0
The crypto experimental module that the SDK depends on was detected
vulnerable on v0.23.0 to an authentication bypass attack through the
ServerConfig for SSH.

This is only used for locally proxying SSH communications, typically for
use with Ansible to provide an SSH server with which to interact, in
order to provision an instance of an OS that uses a communicator other
than SSH, therefore the vulnerability does not necessarily impact us.
However, in order to resolve the automatic report of that vulnerability,
we bump the crypto module's version to 0.31.0, where that problem was
addressed.
2024-12-17 14:06:59 -05:00
Lucas Bajolet
5ff0f146c6 packer_test: introduce global compilation queue
Compiling plugins was originally intended to be an idempotent operation.
This however starts to change as we introduce build customisations,
which have the unfortunate side-effect of changing the state of the
plugin directory, leading to conflicts between concurrent compilation
jobs.

Therefore to mitigate this problem, this commit changes how compilation
jobs are processed, by introducing a global compilation queue, and
processing plugins' compilation one-by-one from this queue.

This however makes such requests asynchronous, so test suites that
require plugins to be compiled will now have to wait on their completion
before they can start their tests.

To this effect, we introduce one more convenience function that
processes those errors, and automatically fails the test should one
compilation job fail for any reason.
2024-12-17 10:45:33 -05:00
Lucas Bajolet
b6b0a081ad packer_test: add build customisation capabilities
When building a plugin, we may want some customisation capabilities
beyond changing the version/pre-release/metadata, and instead run
commands or change files on the filesystem.

To do so, we introduce functions under the BuildCustomisation type,
which have two responsabilities: changing the current state of the
plugin's directory, and cleaning up afterwards.
These customisations are passed as parameters to the BuildSimplePlugin
function, and are called one-by-one, deferring their cleanup after the
build process is finished.

A first implementation of such a customisation is added with this
commit, in order to change the version of a module that the plugin
depends on, which we'll use to change the version of the plugin SDK in
order to test how Packer behaves with different versions of the SDK for
a single plugin.
2024-12-17 10:45:33 -05:00
Lucas Bajolet
11c238b9eb packer_test: add FileGlob checker
When trying to validate that a particular file exists after a run of
Packer in a test suite, we can use the FileExists checker that we
provide as part of the gadgets we added for the acceptance test suites.

This approach works well, but only if we can extract a file name
reliably from the output of Packer core, or if we know what to look for
exactly beforehand. For other cases with a generated name however, the
FileExists checker is not enough, and therefore to accomodate for those
cases, we are introducing a new checker for this purpose: FileGlob.

FileGlob, as its name suggests, runs a glob expression on the
filesystem, and returns an error if no match was found regarding this
glob expression.
2024-12-16 13:49:03 -05:00
Lucas Bajolet
44a94911da packer_test: add FileExists checker
Some tests will create files and directories as part of the execution
path for Packer, and we need a way to check this, so this commit adds a
new file gadget to do those checks after a command executes.
2024-12-16 13:49:03 -05:00
Lucas Bajolet
ac899c44c2 hcl2template: don't error on empty bucket slug
When a user defines a `hcp_packer_registry` block in their `build`
without a `bucket_name`, but they define it in their environment, Packer
should not report the bucket_name being wrong.
2024-12-12 11:29:01 -05:00
Judith Malnick
5fa87f148c let education also edit the docs side navigation 2024-12-10 13:47:13 -05:00
Judith Malnick
618a48b029 add ipl education and web presence ability to merge PRs to relavent website files 2024-12-09 11:39:47 -05:00
Martin Grogan
35682265c4 docs: add strcontains function doc 2024-12-05 16:04:00 -05:00
Martin Grogan
0ddcbaf18f hcl2template: add strcontains function
The strcontains function check if a sub string is a indeed a subset of a
given string.

hcl2template: add strcontains function

The strcontains function check if a sub string is a indeed a subset of a
given string.
2024-11-26 16:27:41 -05:00
Nikolay Edigaryev
c6427d2257 build: ensure that LC_UUID is generated for Darwin binaries 2024-11-22 13:29:35 -05:00
Lucas Bajolet
35d14902b0 datasource/http: change Outputs->ExpectedOutputs
The acceptance tests for the HTTP datasource had a `Outputs` attribute
for checking the output of the command for a specific regexp pattern.
As pointed out, given the expectative nature of the attribute, naming it
`Outputs` did not make the intent clear, so we rename it to
`ExpectedOutputs` with this commit.
2024-11-04 15:15:30 -05:00
Lucas Bajolet
c470395b7a datasource: fix test for invalid method
Since the expected error to look for in the output is compiled to a
regexp, the `[]` from the error message were interpreted as a set of
characters, which made the regexp not match the expected output from the
command.
So to avoid this problem, we escape them so they are expected verbatim
in the command output.
2024-11-04 15:15:30 -05:00
Henrik Gerdes
6c40bfb0cd feat: allow additional methods in http datasource
This adds support for additional http methods for the http datasource.
Fixes #13169

Signed-off-by: Henrik Gerdes <hegerdes@outlook.de>
2024-10-29 16:27:26 -04:00
huochexizhan
6e417bb883 fix: fix slice init length 2024-10-29 16:22:50 -04:00
Lucas Bajolet
9076c7b24a internal/dag: remove unused code
Since the DAG package was lifted from Terraform, its contents are more
than what we need for now, so this commit cleans-up the package to keep
only the currently needed parts of code.
If we need to support more in the future, we can revert this commit, or
pickup the changes again from Terraform.
2024-10-29 16:10:29 -04:00