hashicorp/packer · error
could not get dependency %q for %q, %q missing in template
Error message
could not get dependency %q for %q, %q missing in template
What it means
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.
Source
Thrown at hcl2template/parser.go:448
}
// Connect the vertices together
//
// Vertices that don't have dependencies will be connected to the
// root vertex of the graph
for _, ds := range cfg.Datasources {
dsName := fmt.Sprintf("data.%s", ds.Name())
source := verticesMap[dsName]
if source == nil {
err = multierror.Append(err, fmt.Errorf("unable to find source vertex %q for dependency analysis, this is likely a Packer bug", dsName))
continue
}
for _, dep := range ds.Dependencies {
target := verticesMap[dep.String()]
if target == nil {
err = multierror.Append(err, fmt.Errorf("could not get dependency %q for %q, %q missing in template", dep.String(), dsName, dep.String()))
continue
}
retGraph.Connect(dag.BasicEdge(source, target))
}
}
for _, loc := range cfg.LocalBlocks {
locName := fmt.Sprintf("local.%s", loc.LocalName)
source := verticesMap[locName]
if source == nil {
err = multierror.Append(err, fmt.Errorf("unable to find source vertex %q for dependency analysis, this is likely a Packer bug", locName))
continue
}
for _, dep := range loc.dependencies {
target := verticesMap[dep.String()]
View on GitHub (pinned to eb36e3c3e4)
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
Example fix
// before: datasource references an undefined sibling
locals { use = data.amazon-ami.ubunut.id } // typo
data "amazon-ami" "ubuntu" { ... }
// after
locals { use = data.amazon-ami.ubuntu.id }
data "amazon-ami" "ubuntu" { ... } Defensive patterns
Strategy: validation
Validate before calling
// Grep the template for data.<type>.<name> references and verify each // has a matching block: // grep -oE 'data\.[a-z0-9_-]+\.[a-z0-9_-]+' *.pkr.hcl | sort -u // then compare against defined: data "<type>" "<name>" blocks. // CI gate: packer validate template.pkr.hcl must pass before build.
Try / catch
if err := multierrFromDAG; err != nil {
for _, e := range err.Errors {
var missing string
if n, _ := fmt.Sscanf(e.Error(), "could not get dependency %q", &missing); n == 1 {
fmt.Printf("define datasource block: data \"<type>\" \"%s\" {{ }}\n", missing)
}
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- unable to find source vertex %q for dependency analysis, thi
- malformed datasource reference %q, data sources must be comp
- failed to get datasource '%s.%s': component unknown
- unsupported dependency type %q; datasources can only depend
- error retrieving version from HCP Packer Registry: %s
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/0fae0da744bc7b5f.
Report an issue: GitHub.