{"record":{"id":"e32e0c3c9379ffa0","repo":"hashicorp/packer","slug":"this-version-was-initially-created-with-a-2-s-te","errorCode":null,"errorMessage":"This version was initially created with a %[2]s template. Changing from %[2]s to %[1]s is not supported","messagePattern":"This version was initially created with a %\\[2\\]s template\\. Changing from %\\[2\\]s to %\\[1\\]s is not supported","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hcp/registry/types.bucket.go","lineNumber":491,"sourceCode":"\t// load existing version using fingerprint.\n\tversion, err := bucket.client.GetVersion(ctx, bucket.Name, bucket.Version.Fingerprint)\n\tif hcpPackerAPI.CheckErrorCode(err, codes.Aborted) {\n\t\t// probably means Version doesn't exist need a way to check the error\n\t\tversion, err = bucket.createVersion(templateType)\n\t}\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to initialize version for fingerprint %s: %s\", bucket.Version.Fingerprint, err)\n\t}\n\n\tif version == nil {\n\t\treturn fmt.Errorf(\"failed to initialize version details for Bucket %s with error: %w\", bucket.Name, err)\n\t}\n\n\tif version.TemplateType != nil &&\n\t\t*version.TemplateType != hcpPackerModels.HashicorpCloudPacker20230101TemplateTypeTEMPLATETYPEUNSET &&\n\t\t*version.TemplateType != templateType {\n\t\treturn fmt.Errorf(\n\t\t\t\"This version was initially created with a %[2]s template. \"+\n\t\t\t\t\"Changing from %[2]s to %[1]s is not supported\",\n\t\t\ttemplateType, *version.TemplateType,\n\t\t)\n\t}\n\n\tlog.Println(\n\t\t\"[TRACE] a valid version was retrieved with the id\", version.ID,\n\t)\n\tbucket.Version.ID = version.ID\n\n\t// If the version is completed and there are no new builds to add, Packer\n\t// should exit and inform the user that artifacts already exists for the\n\t// fingerprint associated with the version.\n\tif bucket.client.IsVersionComplete(version) {\n\t\treturn fmt.Errorf(\n\t\t\t\"The version associated to the fingerprint %v is complete. If you wish to add a new build to \"+\n\t\t\t\t\"this bucket a new version must be created by changing the fingerprint.\",","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/hcp/registry/types.bucket.go#L473-L509","documentation":"Each HCP Packer bucket version records the template type (HCL2 vs legacy JSON) it was first created with. When a Packer run reuses a fingerprint whose version was created with a different template type than the current run, initializeVersion rejects the run because switching a version's template type mid-way is unsupported and would corrupt registry metadata.","triggerScenarios":"Running packer build against the same bucket+fingerprint that was previously registered by a run using the other template format (e.g. first run with a JSON template, later run with an HCL2 template, or vice versa), with version.TemplateType set and != TEMPLATETYPEUNSET.","commonSituations":"Migrating templates from legacy JSON to HCL2 while reusing the same fingerprint inputs (identical builds); team members mixing template formats for the same bucket; CI configs updated to HCL2 but reusing an old fingerprinting scheme.","solutions":["Change something that affects the fingerprint (e.g. use a different bucket name or alter build content) so a new version is created","Delete the existing version in HCP Packer (or the whole bucket) and re-run with the current template type","Run all runs for this bucket consistently with one template format (pick HCL2 or JSON and stick to it)"],"exampleFix":"// before: reusing old fingerprint created from JSON template\npacker build legacy.json # bucket=my-bucket, fingerprint=abc123\npacker build template.pkr.hcl # same fingerprint -> error\n// after: use a distinct bucket per template type\npacker build template.pkr.hcl # bucket=my-bucket-hcl\n","handlingStrategy":"validation","validationCode":"// Before running, check the existing version's template type via the HCP API\n// resp := client.GetVersion(ctx, bucketName, fingerprint)\n// if resp != nil && resp.TemplateType != nil &&\n//    *resp.TemplateType != currentTemplateType {\n//     // change fingerprint/bucket or migrate the template before building\n// }","typeGuard":null,"tryCatchPattern":"// Go\nif err := bucket.Initialize(ctx); err != nil {\n\tif strings.Contains(err.Error(), \"Changing from\") {\n\t\t// template-type conflict: switch template format or use a new bucket/fingerprint\n\t\treturn fmt.Errorf(\"use a different fingerprint or matching template type: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Standardize on one template format (HCL2) per bucket","Never reuse fingerprints across JSON and HCL2 versions of a template","When migrating to HCL2, point builds at a new bucket or force a new fingerprint","Document the template format used per bucket in your team's CI config"],"tags":["hcp-packer","template-type","hcl2","config-conflict"],"backgroundTag":"template-type-mismatch","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}