mirror of
https://github.com/hashicorp/packer.git
synced 2026-10-12 17:22:01 -04:00
The HCP error messages were sometimes a bit terse in terms of the information it bubbles up to the user. This made them useful for people who already knew what to look for, but newcomers would almost certainly be lost because of the lack of information in those. To improve on this situation, we reword most of those error messages in this commit.
41 lines
1.4 KiB
Go
41 lines
1.4 KiB
Go
package hcl2template
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/hcl/v2"
|
|
packerregistry "github.com/hashicorp/packer/internal/registry"
|
|
)
|
|
|
|
// ConfiguredArtifactMetadataPublisher returns a configured image bucket that can be used for publishing
|
|
// build image artifacts to a configured Packer Registry destination.
|
|
func (cfg *PackerConfig) ConfiguredArtifactMetadataPublisher() (*packerregistry.Bucket, hcl.Diagnostics) {
|
|
// If this was a PAR (HCP Packer registry) build either the env. variables are set, or if there is a hcp_packer_registry block
|
|
// defined we would have a non-nil bucket. So if nil assume we are not in a some sort of PAR mode.
|
|
if cfg.Bucket == nil {
|
|
return nil, hcl.Diagnostics{
|
|
&hcl.Diagnostic{
|
|
Summary: "Publishing build artifacts to HCP Packer Registry not enabled",
|
|
Detail: "No Packer Registry configuration detected; skipping all publishing steps " +
|
|
"See publishing to a Packer registry for Packer configuration details",
|
|
Severity: hcl.DiagWarning,
|
|
},
|
|
}
|
|
}
|
|
|
|
err := cfg.Bucket.Validate()
|
|
if err != nil {
|
|
return nil, hcl.Diagnostics{
|
|
&hcl.Diagnostic{
|
|
Summary: "Invalid HCP Packer configuration",
|
|
Detail: fmt.Sprintf("Packer could not validate the provided "+
|
|
"HCP Packer registry configuration. Check the error message for details "+
|
|
"or contact HCP Packer support for further assistance.\nError: %s", err),
|
|
Severity: hcl.DiagError,
|
|
},
|
|
}
|
|
}
|
|
|
|
return cfg.Bucket, nil
|
|
}
|