hashicorp/packer · error

NewBuildFromCloudPackerBuild

Error message

NewBuildFromCloudPackerBuild: %w

What it means

Wraps a Build.AddArtifacts validation failure that occurs while converting a HashicorpCloudPacker20230101Build (fetched from HCP) into the local registry Build type. An artifact on the remote build record failed Image validation during conversion.

Solutions

  1. Check the offending build's artifacts in HCP Packer for empty ExternalIdentifier/Region values and fix or remove them
  2. Inspect the wrapped error (%w) to see which artifact field failed validation
  3. Delete and re-create the malformed build record in HCP Packer if it cannot be corrected
  4. Ensure the plugin version writing artifacts publishes valid identifiers
Defensive patterns

Strategy: validation

Validate before calling

// Validate the cloud build record before conversion
for _, a := range src.Artifacts {
    if a.ExternalIdentifier == "" {
        return fmt.Errorf("artifact on build %s has empty ExternalIdentifier", src.ID)
    }
}

Type guard

func validCloudArtifacts(src *models.HashicorpCloudPacker20230101Build) bool {
    for _, a := range src.Artifacts {
        if a.ExternalIdentifier == "" || a.Region == "" { return false }
    }
    return true
}

Prevention

When it happens

Trigger: Called by CreateInitialBuildForVersion and populateVersion; for each artifact on the cloud build record, NewBuildFromCloudPackerBuild calls build.AddArtifacts with an Image built from artifact.ExternalIdentifier/Region — if Image.Validate fails (e.g. empty ImageID), the error is wrapped with this prefix.

Common situations: Remote HCP build records containing artifacts with empty external identifiers; malformed data in an existing bucket/version being populated; SDK/model changes leaving fields unset.

Related errors


AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05). Data as JSON: /api/errors/ac349688152307cd. Report an issue: GitHub.

Appendix: source

Thrown at internal/hcp/registry/types.builds.go:52

	build := Build{
		ID:            src.ID,
		ComponentType: src.ComponentType,
		Platform:      src.Platform,
		RunUUID:       src.PackerRunUUID,
		Status:        *src.Status,
		Labels:        src.Labels,
	}

	var err error
	for _, artifact := range src.Artifacts {
		err = build.AddArtifacts(packerSDKRegistry.Image{
			ImageID:        artifact.ExternalIdentifier,
			ProviderName:   build.Platform,
			ProviderRegion: artifact.Region,
		})

		if err != nil {
			return nil, fmt.Errorf("NewBuildFromCloudPackerBuild: %w", err)
		}
	}

	return &build, nil
}

// MergeLabels merges the contents of data to the labels associated with the build.
// Duplicate keys will be updated to reflect the new value.
func (build *Build) MergeLabels(data map[string]string) {
	if data == nil {
		return
	}

	if build.Labels == nil {
		build.Labels = make(map[string]string)
	}

	for k, v := range data {

View on GitHub (pinned to eb36e3c3e4)