{"record":{"id":"a8329468f31c6e12","repo":"hashicorp/packer","slug":"failed-to-write-amazon-ami-data-source-v","errorCode":null,"errorMessage":"Failed to write amazon-ami data source: %v","messagePattern":"Failed to write amazon-ami data source: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/hcl2_upgrade.go","lineNumber":1127,"sourceCode":"type AmazonAmiDatasourceParser struct {\n\tBuilders        []*template.Builder\n\tWithAnnotations bool\n\tout             []byte\n}\n\nfunc (p *AmazonAmiDatasourceParser) Parse(_ *template.Template) error {\n\tif p.out == nil {\n\t\tp.out = []byte{}\n\t}\n\n\tamazonAmiFilters := []map[string]interface{}{}\n\ti := 1\n\tfor _, builder := range p.Builders {\n\t\tif strings.HasPrefix(builder.Type, \"amazon-\") {\n\t\t\tif sourceAmiFilter, ok := builder.Config[\"source_ami_filter\"]; ok {\n\t\t\t\tsourceAmiFilterCfg := map[string]interface{}{}\n\t\t\t\tif err := mapstructure.Decode(sourceAmiFilter, &sourceAmiFilterCfg); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"Failed to write amazon-ami data source: %v\", err)\n\t\t\t\t}\n\n\t\t\t\tsourceAmiFilterCfg, err := copyAWSAccessConfig(sourceAmiFilterCfg, builder.Config)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\n\t\t\t\tduplicate := false\n\t\t\t\tdataSourceName := fmt.Sprintf(\"autogenerated_%d\", i)\n\t\t\t\tfor j, filter := range amazonAmiFilters {\n\t\t\t\t\tif reflect.DeepEqual(filter, sourceAmiFilterCfg) {\n\t\t\t\t\t\tduplicate = true\n\t\t\t\t\t\tdataSourceName = fmt.Sprintf(\"autogenerated_%d\", j+1)\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// This is a hack...","sourceCodeStart":1109,"sourceCodeEnd":1145,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/command/hcl2_upgrade.go#L1109-L1145","documentation":"Error while converting a legacy JSON template to HCL2 (AmazonAmiDatasourceParser.Parse): a builder with a source_ami_filter could not be decoded into a data source block, so the amazon-ami filter configuration cannot be transposed.","triggerScenarios":"Thrown at command/hcl2_upgrade.go:1127 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check that source_ami_filter in the JSON template is a plain map of strings/arrays without unexpected nesting","Fix or hand-write the equivalent data \"amazon-ami\" block in the upgraded HCL2 file"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}