{"record":{"id":"0fae0da744bc7b5f","repo":"hashicorp/packer","slug":"could-not-get-dependency-q-for-q-q-missing-in","errorCode":null,"errorMessage":"could not get dependency %q for %q, %q missing in template","messagePattern":"could not get dependency %q for %q, %q missing in template","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hcl2template/parser.go","lineNumber":448,"sourceCode":"\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 {\n\t\t\terr = multierror.Append(err, fmt.Errorf(\"unable to find source vertex %q for dependency analysis, this is likely a Packer bug\", locName))\n\t\t\tcontinue\n\t\t}\n\n\t\tfor _, dep := range loc.dependencies {\n\t\t\ttarget := verticesMap[dep.String()]\n","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/hcl2template/parser.go#L430-L466","documentation":"While connecting datasource dependency edges in buildPrereqsDAG, Packer looks up each dependency reference (ds.Dependencies) in the vertex map. The dependency refString (e.g. \"data.type.name\") resolved from the datasource's interpolation does not correspond to any datasource block defined in the template, so no graph edge can be created and this error is appended. It means a datasource references another datasource that is missing from the template.","triggerScenarios":"A datasource block's arguments interpolate `data.<type>.<name>` where the referenced datasource block does not exist (or its type/name labels don't match exactly) in the same template context; raised during evaluateBuildPrereqs via buildPrereqsDAG before prerequisite evaluation.","commonSituations":"Typo in the datasource name in an interpolation (e.g. data.amazon-ami.ubuntu vs. defined data.amazon-ami.ubunut); referencing a datasource defined in a different template/file not imported; renaming a datasource block without updating references; case-sensitivity mismatches in names.","solutions":["Add the referenced datasource block to the template: define `data \"<type>\" \"<name>\" { ... }` for the missing name shown in the error","Fix typos/mismatches in the reference so it exactly matches the datasource block's type and name labels","Check the datasource is defined in the same source file / template scope that Packer parses for this build","Run `packer init` and `packer validate` to catch undefined references earlier with better diagnostics"],"exampleFix":"// before: datasource references an undefined sibling\nlocals { use = data.amazon-ami.ubunut.id }  // typo\ndata \"amazon-ami\" \"ubuntu\" { ... }\n// after\nlocals { use = data.amazon-ami.ubuntu.id }\ndata \"amazon-ami\" \"ubuntu\" { ... }","handlingStrategy":"validation","validationCode":"// Grep the template for data.<type>.<name> references and verify each\n// has a matching block:\n//   grep -oE 'data\\.[a-z0-9_-]+\\.[a-z0-9_-]+' *.pkr.hcl | sort -u\n// then compare against defined: data \"<type>\" \"<name>\" blocks.\n// CI gate: packer validate template.pkr.hcl must pass before build.","typeGuard":null,"tryCatchPattern":"if err := multierrFromDAG; err != nil {\n    for _, e := range err.Errors {\n        var missing string\n        if n, _ := fmt.Sscanf(e.Error(), \"could not get dependency %q\", &missing); n == 1 {\n            fmt.Printf(\"define datasource block: data \\\"<type>\\\" \\\"%s\\\" {{ }}\\n\", missing)\n        }\n    }\n}","preventionTips":["Always define a datasource block for every data.<type>.<name> reference","Copy exact names instead of retyping them; names are case-sensitive","Run `packer validate` in CI before `packer build`","When renaming a datasource, grep for all data.<type>.<name> usages first"],"tags":["hcl2template","datasource","missing-reference","dependency-graph"],"backgroundTag":"undefined-reference","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"}