{"record":{"id":"8573dbeeaa86c84a","repo":"hashicorp/packer","slug":"unable-to-find-source-vertex-q-for-dependency-ana","errorCode":null,"errorMessage":"unable to find source vertex %q for dependency analysis, this is likely a Packer bug","messagePattern":"unable to find source vertex %q for dependency analysis, this is likely a Packer bug","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hcl2template/parser.go","lineNumber":441,"sourceCode":"\t\tverticesMap[fmt.Sprintf(\"data.%s\", ds.Name())] = v\n\t}\n\t// Note: locals being references to the objects already, we can safely\n\t// use the reference returned by the local loop.\n\tfor _, local := range cfg.LocalBlocks {\n\t\tv := retGraph.Add(local)\n\t\tverticesMap[fmt.Sprintf(\"local.%s\", local.LocalName)] = v\n\t}\n\n\t// Connect the vertices together\n\t//\n\t// Vertices that don't have dependencies will be connected to the\n\t// root vertex of the graph\n\tfor _, ds := range cfg.Datasources {\n\t\tdsName := fmt.Sprintf(\"data.%s\", ds.Name())\n\n\t\tsource := verticesMap[dsName]\n\t\tif source == nil {\n\t\t\terr = multierror.Append(err, fmt.Errorf(\"unable to find source vertex %q for dependency analysis, this is likely a Packer bug\", dsName))\n\t\t\tcontinue\n\t\t}\n\n\t\tfor _, dep := range ds.Dependencies {\n\t\t\ttarget := verticesMap[dep.String()]\n\t\t\tif target == nil {\n\t\t\t\terr = multierror.Append(err, fmt.Errorf(\"could not get dependency %q for %q, %q missing in template\", dep.String(), dsName, dep.String()))\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tretGraph.Connect(dag.BasicEdge(source, target))\n\t\t}\n\t}\n\tfor _, loc := range cfg.LocalBlocks {\n\t\tlocName := fmt.Sprintf(\"local.%s\", loc.LocalName)\n\n\t\tsource := verticesMap[locName]\n\t\tif source == nil {","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/hcl2template/parser.go#L423-L459","documentation":"During buildPrereqsDAG, Packer builds a dependency graph of datasources and locals before evaluating build prerequisites. Each datasource block is supposed to have been added as a graph vertex in the first pass; if the vertex keyed by \"data.<name>\" is absent from verticesMap, this internal-consistency error is raised and the block is skipped. As the message says, this almost always indicates a Packer bug or corrupted in-memory config state rather than a template authoring mistake.","triggerScenarios":"cfg.Datasources contains a datasource whose ds.Name() key was not registered in verticesMap during the first vertex pass (e.g. duplicate/odd datasource names colliding, or a block whose name changes between the first and second passes). Called via evaluateBuildPrereqs when Packer starts evaluating build prerequisites (packer build / validate of an HCL2 template with datasource blocks).","commonSituations":"Packer core regressions after upgrades, plugin SDK versions where datasource Name() behaves unexpectedly, custom forks or embedded use of PackerConfig where cfg.Datasources is mutated between passes. Rarely triggered by pure template content.","solutions":["Upgrade Packer to the latest patch release — this is flagged as a bug; check the changelog for dependency-graph fixes","File a bug report (hashicorp/packer) including the template's datasource blocks and `packer version`","As a workaround, simplify/rename the datasource blocks (avoid duplicated or unusual names) and rebuild the cache to force fresh parsing","If embedding Packer programmatically, ensure cfg.Datasources is not mutated between config parsing and evaluateBuildPrereqs"],"exampleFix":"// No template fix applies; this is internal state.\n// Workaround in a template: rename a possibly colliding datasource\n// before\ndata \"amazon-ami\" \"foo\" { ... }\ndata \"amazon-ami\" \"foo\" { ... }  // duplicate name can corrupt vertex keys\n// after\ndata \"amazon-ami\" \"foo\" { ... }\ndata \"amazon-ami\" \"bar\" { ... }","handlingStrategy":"validation","validationCode":"// Before building, ensure every datasource parses and resolves:\n//   packer validate template.pkr.hcl\n// Programmatic check: iterate cfg.Datasources and confirm unique names\nnames := map[string]bool{}\nfor _, ds := range cfg.Datasources {\n    n := fmt.Sprintf(\"data.%s\", ds.Name())\n    if names[n] { /* duplicate datasource name — vertex key collision risk */ }\n    names[n] = true\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    // treat as internal bug: include `packer version`, template, and retry with a clean parse cache\n    return fmt.Errorf(\"dependency analysis failed (possible Packer bug): %w\", err)\n}","preventionTips":["Keep Packer up to date; this error class is a bug indicator, not a config problem","Give datasource blocks unique names across all parsed files","Re-run from a clean state (no stale parse cache) after upgrading Packer","Validate templates with `packer validate` in CI to surface config issues before graph building"],"tags":["hcl2template","dependency-graph","internal-bug","datasource"],"backgroundTag":"missing-dependency-node","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"}