hashicorp/packer · error
unsupported dependency type %q; locals can only depend on lo
Error message
unsupported dependency type %q; locals can only depend on local, var or data.
What it means
RegisterDependency records an upstream resource (data source, local, or var) as a dependency of a local value so locals can be evaluated in the correct order. Packer throws this error when a dependency of a type other than local, var, or data is registered against a local — the local evaluation graph cannot resolve any other reference root type.
Source
Thrown at hcl2template/types.refstring.go:143
case "data", "local":
ds.Dependencies = append(ds.Dependencies, rs)
// NOOP: vars are always evaluated beforehand for datasources
case "var":
default:
return fmt.Errorf("unsupported dependency type %q; datasources can only depend on local, var or data.", rs.MType)
}
return nil
}
func (loc *LocalBlock) RegisterDependency(rs refString) error {
switch rs.MType {
case "data", "local":
loc.dependencies = append(loc.dependencies, rs)
// NOOP: vars are always evaluated beforehand for locals
case "var":
default:
return fmt.Errorf("unsupported dependency type %q; locals can only depend on local, var or data.", rs.MType)
}
return nil
}
View on GitHub (pinned to eb36e3c3e4)
Solutions
- Find the local expression containing the bad reference and fix the root name to an existing local, var, or data source block
- Check for typos in block labels inside locals (e.g. `${localz.x}` instead of `${local.x}`)
- If a custom plugin or forked code registers dependencies, ensure it only passes refstrings with MType data, local, or var
- Run `packer init` and validate the template with `packer validate` after fixing the reference
Example fix
// before (template with bad root)
locals { name = "${builder.type}-image" }
// after
locals { name = "${local.base_name}-image" } Defensive patterns
Strategy: validation
Validate before calling
var depRoots = map[string]bool{"local": true, "var": true, "data": true}
func validLocalDep(mtype string) bool { return depRoots[mtype] }
// before registering:
// if !validLocalDep(rs.MType) { return fmt.Errorf("cannot register dependency %q for locals", rs.MType) } Type guard
func isSupportedLocalDep(mtype string) bool {
switch mtype {
case "local", "var", "data":
return true
}
return false
} Prevention
- Reference only local, var, and data blocks inside locals expressions
- Run `packer validate` on templates before builds to catch bad roots early
- Watch for typos in block type names (local vs localz)
- Keep local expressions simple and avoid copy-paste from other tools' syntax
When it happens
Trigger: Calling RegisterDependency with a refstring whose MType is not "data", "local", or "var" (e.g. a mis-attributed ref that resolves to a builder or unknown root), during local dependency collection while preparing an HCL2 template.
Common situations: A template references an undefined or mistyped block inside a local expression (e.g. typo'd root like localz.foo or builder.name), or a refactor/parsing bug produces a traversal root the local dependency walker doesn't recognize.
Related errors
- unhandled buildvar type: %T
- no release version found for constraints: %q
- source must be specified when auto_generate is not enabled
- Only one of script or scripts can be specified.
- Must supply an 'elevated_user' if 'elevated_password' provid
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/2af7a6af02cb24a6.
Report an issue: GitHub.