From 5e86b25b9745b5ed6b4e2c28b6b9ded4848596a0 Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Thu, 25 Jan 2024 10:13:06 -0500 Subject: [PATCH] Update error messaging for HCP incompatible plugin builds --- command/build.go | 18 +++++++++++++++++- internal/hcp/registry/types.bucket.go | 2 +- internal/hcp/registry/types.version.go | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/command/build.go b/command/build.go index 7d231a5b7b3..86215619bcd 100644 --- a/command/build.go +++ b/command/build.go @@ -25,6 +25,10 @@ import ( "github.com/posener/complete" ) +const ( + hcpReadyIntegrationURL = "https://developer.hashicorp.com/packer/integrations?flags=hcp-ready" +) + type BuildCommand struct { Meta } @@ -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.") @@ -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 { @@ -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 is 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 diff --git a/internal/hcp/registry/types.bucket.go b/internal/hcp/registry/types.bucket.go index b8f62a7b2f6..00b40e34568 100644 --- a/internal/hcp/registry/types.bucket.go +++ b/internal/hcp/registry/types.bucket.go @@ -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) diff --git a/internal/hcp/registry/types.version.go b/internal/hcp/registry/types.version.go index 391717cc0c7..ae8edb86931 100644 --- a/internal/hcp/registry/types.version.go +++ b/internal/hcp/registry/types.version.go @@ -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))