Skip to content

Commit

Permalink
Update error messaging for HCP incompatible plugin builds (#12800)
Browse files Browse the repository at this point in the history
* Update error messaging for HCP incompatible plugin builds

* Update command/build.go

Co-authored-by: Lucas Bajolet <[email protected]>

---------

Co-authored-by: Lucas Bajolet <[email protected]>
  • Loading branch information
Wilken Rivera and lbajolet-hashicorp authored Jan 25, 2024
1 parent 3fa637c commit 12b8c88
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion command/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import (
"github.com/posener/complete"
)

const (
hcpReadyIntegrationURL = "https://developer.hashicorp.com/packer/integrations?flags=hcp-ready"
)

type BuildCommand struct {
Meta
}
Expand Down Expand Up @@ -202,6 +206,8 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, cla *BuildArgs) int
m map[string]error
}{m: make(map[string]error)}
limitParallel := semaphore.NewWeighted(cla.ParallelBuilds)

var hasPossibleIncompatibleHCPIntegration bool
for i := range builds {
if err := buildCtx.Err(); err != nil {
log.Println("Interrupted, not going to start any more builds.")
Expand Down Expand Up @@ -267,12 +273,13 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, cla *BuildArgs) int
writeDiags(c.Ui, nil, hcl.Diagnostics{
&hcl.Diagnostic{
Summary: fmt.Sprintf(
"failed to complete HCP-enabled build %q",
"publishing build metadata to HCP Packer for %q failed",
name),
Severity: hcl.DiagError,
Detail: hcperr.Error(),
},
})
hasPossibleIncompatibleHCPIntegration = true
}

if err != nil {
Expand Down Expand Up @@ -384,6 +391,15 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, cla *BuildArgs) int
c.Ui.Say("\n==> Builds finished but no artifacts were created.")
}

if hasPossibleIncompatibleHCPIntegration {
msg := fmt.Sprintf(`
It looks like one or more plugins in your build may be incompatible with HCP Packer.
Check that you are using an HCP Ready integration before trying again:
%s`, hcpReadyIntegrationURL)

c.Ui.Error(msg)
}

if len(errs.m) > 0 {
// If any errors occurred, exit with a non-zero exit status
ret = 1
Expand Down
2 changes: 1 addition & 1 deletion internal/hcp/registry/types.bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ func (bucket *Bucket) completeBuild(
err = decoder.Decode(state)
if err != nil {
return packerSDKArtifacts, fmt.Errorf(
"failed to obtain HCP Packer artifact from post-processor artifact: %w",
"failed to obtain HCP Packer compliant artifact: %w",
err)
}
log.Printf("[TRACE] updating artifacts for build %q", buildName)
Expand Down
2 changes: 1 addition & 1 deletion internal/hcp/registry/types.version.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (version *Version) statusSummary(ui sdkpacker.Ui) {
buf := &strings.Builder{}

buf.WriteString(fmt.Sprintf(
"\nVersion %q is not complete, the following builds are not done:\n\n",
"\nVersion %q is incomplete, the following builds are missing artifact metadata:\n\n",
version.Fingerprint))
for _, b := range rem {
buf.WriteString(fmt.Sprintf("* %q: %s\n", b.ComponentType, b.Status))
Expand Down

0 comments on commit 12b8c88

Please sign in to comment.