1
0
mirror of https://github.com/hashicorp/packer.git synced 2026-02-05 12:45:10 +01:00

95 Commits

Author SHA1 Message Date
Tanmay Jain
46b216b203 Merge pull request #13545 from hashicorp/compliance/update-headers-batch-2
[IND-4226] [COMPLIANCE] Update Copyright Headers (Batch 2 of 5)
2025-12-22 15:35:05 +05:30
Tanmay Jain
00c9a6d7f7 Merge pull request #13540 from hashicorp/compliance/update-headers
[IND-4226] [COMPLIANCE] Update Copyright Headers
2025-12-22 15:34:39 +05:30
Devashish
651ea426be Verbiage change 2025-12-12 13:20:11 -05:00
hashicorp-copywrite[bot]
219421c08c [COMPLIANCE] Update Copyright and License Headers (Batch 2 of 5) 2025-12-11 07:02:15 +00:00
Tanmay Jain
aa2b628319 Adding ui object support in Bucket for Logs 2025-12-08 16:08:49 +05:30
hashicorp-copywrite[bot]
6af0b29558 [COMPLIANCE] Update Copyright and License Headers 2025-11-30 18:32:15 +00:00
Tanmay Jain
52448da979 Added Test Cases for Channel Assignment 2025-11-21 14:35:51 +05:30
Tanmay Jain
0e354e503b FEAT: Adds support for updating HCP Packer registry channels
Enables specifying channels in the build configuration to automatically update existing HCP Packer registry channels to point to the new build version upon completion. Improves workflow automation and reduces manual channel management for users.
2025-11-21 12:43:46 +05:30
Anurag Sharma
543123ac17 bump golang.org/x/crypto to 0.43.0 (#13518)
* bump golang.org/x/crypto to 0.43.0
CVE-2025-47913 GO-2025-4116

* fixed go.sum

* fixed multiple warnings that prevented test runs

* make generate

* fix lint errors, update linter version

* fix go vet issues
2025-11-18 15:49:03 +05:30
Tanmay Jain
daa421e5ca FEAT: Added Jenkins CICD Metadata Support for HCP 2025-11-04 11:40:47 +05:30
Anurag Sharma
3f9b1e358c add bitbucket pipelines metadata (#13513) 2025-11-04 09:53:04 +05:30
Jenna Goldstrich
40bea58c92 Fix incorrect Credential file default path in docs (#13447)
should be ~/.config/hcp/cred_file.json
2025-08-13 15:26:45 +05:30
Jenna Goldstrich
8a376a8845 HCP Certificate Authentication Support (#13435)
* Add support for using a certificate file instead of HCP Client Credentials to authenticate to HashiCorp Cloud Platform

* Docs

* Change certificate auth warnings to print to stdio

* rough draft docs

* Update comments

* Parse home directory correctly, default directory certs don't work before this

* cred-file => cred_file, and add unit test

* Fix invalid log, and use full path in log messages and error messages

* Fix original file not being reset in unit test

* Move test statements around to validate Windows behavior

* Use a 'windows friendly' path

* The issue here was the path error'd on mac and linux, but not Windows, when I swapped to the different path then nothing error'd causing everything to fail, I think this should fix it on 3 platforms

* 1.14.1 => 1.14.2
2025-08-12 10:40:55 +05:30
Martin Grogan
b1417b7f5c hcp: use GetHCPPackerRegistryBlock in the hcl module 2025-03-11 14:49:59 -04:00
Martin Grogan
cc610bc006 hcp: give a proper error when using conflicting build name
It was possible to put the same source 2 times in the build and when
using HCP, it would error eventually since they are considered the same
build from HCP side
2025-03-03 15:44:29 -05:00
Lucas Bajolet
62befd70bf hcp: replace packersdk.Build by *CoreBuild
As the rest of the build process was updated to remove references to the
Build interface exposed by the SDK, we change the usage of such types in
the hcp internal package, so they are typed with *CoreBuild too.
2025-02-13 16:06:02 -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
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
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
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
Lucas Bajolet
09774aaeb8 internal/dag: adapt Validate to not check for Root
The implementation of the DAG as extracted from Terraform relied on a
Root vertex being injected into the graph as the last node to visit.

This is used as a sanity check for Terraform, but doesn't apply to our
use-case for now, as we are always executing everything and have no need
for this root node.

Instead, we change how Validate operates so it does not error in case
there is no valid root node for the graph, but enables us calling it to
check for self-referencing edges, and circular dependencies.
2024-10-29 16:10:29 -04:00
Lucas Bajolet
673c13ebe7 internal: add dag package
The dag package is a port over from Terraform to Packer, changing what
little there was to fit our current dependency ecosystem.
Most of the changes are on the type of diagnostics returned, as
Terraform has its own type for them, while we rely on hcl's Diagnostics.

Other than that, the functionality is essentially equivalent, and the
code was barely touched.
2024-10-29 16:10:29 -04:00
Lucas Bajolet
69ec781ee2 hcp: don't continue if HEAD doesn't exist
In HCP's metadata package, especially the VCS/git parts, we keep the
current HEAD for a repository, along with the state it is in, in order
to report it to HCP Packer when the build completes.

However, when a build is run on a template from an empty Git repository,
and HCP Packer is enabled, the code would crash when trying to get the
information on the current HEAD, as it doesn't exist.

The git library we use returns an error in such a case, but this was
ignored, leading to a crash when attempting to get the hash to this
reference later on.

This commit fixes the problem by NOT ignoring the error to get the head,
and immediately stop processing the git data as it doesn't yet exist.
2024-09-13 10:46:25 -04:00
Devashish
265dfe105a Remove suffix from CICD platform type (#13121) 2024-07-25 18:15:56 +05:30
Devashish
aa6c5f8405 feat: Phase 2 Extension of Build Metadata (#13092) 2024-07-22 23:08:14 +05:30
Jenna Goldstrich
078ad45860 HCP Packer Buckets: Change UpsertBucket to call GetBucket (#13059)
* Update UpsertBucket to first call GetBucket, this will allow bucket level role based authentication, as CreateBucket uses project level auth

* Fix one incorrect test failure message
2024-06-21 08:28:09 -07:00
Devashish
f19b9b7369 Remove GetMetadata from StartBuild and add to CompleteBuild for HCL (#12926) 2024-04-15 17:13:09 -04:00
Devashish
70d2efec4d Report metadata only when the build completes (#12923) 2024-04-15 15:02:10 -04:00
Devashish
edc8a4dc0d Use latest version of hcp-sdk-go
Remove loggers and move AddMetadataToBuild method to Version
2024-04-11 12:55:04 -04:00
Devashish
8e92027546 HPR-1537: Packer Core sends metadata to HCP Packer in UpdateBuild API (#12891) 2024-04-11 12:55:04 -04:00
Devashish
595b45e67c Packer tracks Version and Plugins Metadata (#12860) 2024-04-11 12:55:04 -04:00
Lucas Bajolet
32f89015fe hcp: fix hcp artifact extraction method
With Packer 1.10.1 we started warning when a build failed to complete
because of a potential incompatibility with the builder being used.

This led to cases in which the build failed for other reasons, and
Packer would still warn of potential incompatibilities, even if the
builder was in effect HCP compatible.

We attempted to fix this issue by introducing a new error type, and
checks when we read the artifacts linked to a build, however this loop
would fail when any one of the artifacts is not compatible with HCP
Packer, leading to false failures.

To avoid this problem, we log incompatibilities to the verbose logger,
and only signal the problem if all the artifacts could not be used to
upload data to HCP Packer, in which case it's almost certain that if the
build succeeded and no artifacts are registered to the build, that all
the components used are not compatible with HCP, and should be reported
as such to users.
2024-02-27 11:39:21 -05:00
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
Devashish
91ce35f439 Expose versionFingerprint instead of versionId from packer template 2024-01-26 14:31:04 -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
Wilken Rivera
c245b1fb7c deps: Bump github.com/hashicorp/hcp-sdk-go to v0.73.0
* Updates cloud-resource-management API to use sable
* Removes duplicate imports of the same SDK packages
2023-11-15 10:27:51 -05: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
60c66fdf9f Add additional validation for manually set project ids
When setting a project id via the HCP_PROJECT_ID env the client will try to validate the project
by checking that it has an associated registry. If the project is invalid or not a valid UUID an error
will be displayed to the user

* Add comment to clarify usage of SDK loaded env. variables
2023-07-25 11:31:39 -04:00
Wilken Rivera
38101a64c9 hcp: Add support for project level service principals
HCP supports two types of service principals: Organization-level and project-level.
When a user tries to publish to an active HCP Packer registry using a plsp the client
fails when configuring the client due to a API permission error; namely plsp do not have
the permissions to query an org for a list of projects. Setting the HCP_PROJECT_ID does
not resolve the issue because the call to ListProjects is still executed.

This changes updates the client configuration params to obtain both the HCP Organization and
Project IDs that will be used for connecting to the HCP Packer registry. With this change
if a user provides a project Id via the HCP_PROJECT_ID environment variable no call to ListProjects will
be made. Instead the value will be take as is and used to create the connection. A user connecting with
a project level service principals must provide a valid HCP_PROJECT_ID in order to connect.
2023-07-25 11:31:39 -04:00
hashicorp-copywrite[bot]
d563a3c623 [COMPLIANCE] Add Copyright and License Headers 2023-06-05 13:39:28 -04:00
Lucas Bajolet
925cb5e541 hcp: support HCP_PROJECT_ID environment variable
With HCP supporting multi-projects now, Packer needs to take it into
account when picking a project from an organisation.

This commit adds two cases:

1. multiple projects are defined, none is supplied through
   HCP_PROJECT_ID: in this case we will default to the oldest project
   defined for the organisation.

2. we supply HCP_PROJECT_ID: in this case, we pick the project with the
   corresponding ID, and use it for publishing metadata.
2023-06-01 14:39:09 -04:00
Wilken Rivera
eca75a6847 Run make fmt to fix checks 2023-04-27 15:17:31 -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
d880d1bca7 Update ReadFromHCLBuildBlock to use the hcp_packer_registry.Description
In packer v1.8.5, the bucket's description was not properly set in the
bucket object we use for HCP, therefore all the buckets created by
Packer did not have their description updated.

Before the change
```
--- FAIL: TestReadFromHCLBuildBlock (0.00s)
    --- FAIL: TestReadFromHCLBuildBlock/configure_bucket_using_only_hcp_packer_registry_block (0.00s)
        types.bucket_test.go:380: expected the build to to have contents of hcp_packer_registry block but it does not:   &registry.Bucket{
                Slug:         "hcp_packer_registry-block-test",
            -   Description:  "",
            +   Description:  "description from hcp_packer_registry block",
                Destination:  "",
                BucketLabels: {"org": "test"},
                ... // 5 identical fields
              }
FAIL
FAIL    github.com/hashicorp/packer/internal/hcp/registry       1.072s
FAIL
```

After Change
```
~>  go test ./...
?       github.com/hashicorp/packer/internal/hcp/api    [no test files]
ok      github.com/hashicorp/packer/internal/hcp/env    (cached)
ok      github.com/hashicorp/packer/internal/hcp/registry       1.130s

```
2023-01-30 16:18:11 -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
73482bb636 internal: remove unused Labels on Iteration
The iteration structure that we use for linking a packer build to an
iteration on HCP defines a `Labels' attribute, which is never set nor
read from at any point.

Since it is unused, we remove it in this commit.
2023-01-25 15:29:26 -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