Merge pull request #12849 from hashicorp/backport/hcp_no_support_error_more_accurate/jointly-tough-crane

This pull request was automerged via backport-assistant
pull/12852/head
hc-github-team-packer 2 years ago committed by GitHub
commit 64d7608ba7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -207,7 +207,6 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, cla *BuildArgs) int
}{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.")
@ -270,16 +269,29 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, cla *BuildArgs) int
runArtifacts,
err)
if hcperr != nil {
writeDiags(c.Ui, nil, hcl.Diagnostics{
&hcl.Diagnostic{
Summary: fmt.Sprintf(
"publishing build metadata to HCP Packer for %q failed",
name),
Severity: hcl.DiagError,
Detail: hcperr.Error(),
},
})
hasPossibleIncompatibleHCPIntegration = true
if _, ok := hcperr.(*registry.NotAHCPArtifactError); ok {
writeDiags(c.Ui, nil, hcl.Diagnostics{
&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: fmt.Sprintf("The %q builder produced an artifact that cannot be pushed to HCP Packer", b.Name()),
Detail: fmt.Sprintf(
`%s
Check that you are using an HCP Ready integration before trying again:
%s`,
hcperr, hcpReadyIntegrationURL),
},
})
} else {
writeDiags(c.Ui, nil, hcl.Diagnostics{
&hcl.Diagnostic{
Summary: fmt.Sprintf(
"publishing build metadata to HCP Packer for %q failed",
name),
Severity: hcl.DiagError,
Detail: hcperr.Error(),
},
})
}
}
if err != nil {
@ -391,15 +403,6 @@ 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

@ -595,6 +595,10 @@ func (bucket *Bucket) startBuild(ctx context.Context, buildName string) error {
return nil
}
type NotAHCPArtifactError struct {
error
}
func (bucket *Bucket) completeBuild(
ctx context.Context,
buildName string,
@ -638,12 +642,19 @@ func (bucket *Bucket) completeBuild(
}
state := art.State(packerSDKRegistry.ArtifactStateURI)
if state == nil {
return packerSDKArtifacts, &NotAHCPArtifactError{
fmt.Errorf("The HCP artifact returned by the builder is nil, this is likely because the builder does not support HCP Packer."),
}
}
err = decoder.Decode(state)
if err != nil {
return packerSDKArtifacts, fmt.Errorf(
"failed to obtain HCP Packer compliant artifact: %w",
err)
return packerSDKArtifacts, &NotAHCPArtifactError{
fmt.Errorf("Failed to obtain HCP Packer compliant artifact: %s", err),
}
}
log.Printf("[TRACE] updating artifacts for build %q", buildName)
err = bucket.UpdateArtifactForBuild(buildName, sdkImages...)

Loading…
Cancel
Save