hashicorp/terraform · error
attribute not found
Error message
attribute %q not found
What it means
Returned by pathFromFlatmapKeyObject when the leading path segment (the attribute name extracted by pathSplit) does not exist as a key in the object's attribute-types map. The decoder has built a GetAttrStep for it but cannot continue because the type of the (non-existent) attribute is unknown. This is the most common root cause surfaced through the [852] wrapper.
Solutions
- Match the attribute name in the error against the current schema; rename the reference or restore the attribute.
- If the attribute was legitimately removed, drop it from RequiresReplace and recompute the plan.
- Pin the provider version so the schema and the persisted diff/RequiresReplace list stay in sync.
- Add a schema-state compatibility test that decodes a known RequiresReplace key set against the current schema.
Example fix
// before: flatmap key 'legacy_field.nested' but schema has no 'legacy_field'
// after: either rename to the current attribute, or remove the entry
// RequiresReplace: []cty.Path{{cty.GetAttrStep{Name: "current_field"}}} Defensive patterns
Strategy: validation
Validate before calling
func flatmapKeyRefersToDeclaredAttr(key string, atys map[string]cty.Type) bool {
head, _ := pathSplit(key)
_, ok := atys[head]
return ok
} Type guard
func flatmapKeyRefersToDeclaredAttr(key string, atys map[string]cty.Type) bool {
head, _ := pathSplit(key)
_, ok := atys[head]
return ok
} Prevention
- When renaming or removing an attribute, update every RequiresReplace list that references it.
- Pin provider version during refactors that rename schema attributes.
- Cross-validate RequiresReplace against the schema in provider tests.
When it happens
Trigger: Translating a flatmap key whose first dotted segment names an attribute that is not declared in the object type's AttributeTypes(). Triggered when RequiresReplace or a diff key references an attribute that the schema no longer (or never did) declare.
Common situations: Schema rename or removal of an attribute that remains referenced by RequiresReplace, a stored diff, or an old plan; merging diffs from different provider versions; custom providers that emit RequiresReplace keys without matching them to declared attributes.
Related errors
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/766a5f5bd88f1f69.
Report an issue: GitHub.
Appendix: source
Thrown at internal/configs/hcl2shim/paths.go:115
func pathSplit(p string) (string, string) {
parts := strings.SplitN(p, ".", 2)
head := parts[0]
rest := ""
if len(parts) > 1 {
rest = parts[1]
}
return head, rest
}
func pathFromFlatmapKeyObject(key string, atys map[string]cty.Type) (cty.Path, error) {
k, rest := pathSplit(key)
path := cty.Path{cty.GetAttrStep{Name: k}}
ty, ok := atys[k]
if !ok {
return path, fmt.Errorf("attribute %q not found", k)
}
if rest == "" {
return path, nil
}
p, err := pathFromFlatmapKeyValue(rest, ty)
if err != nil {
return path, err
}
return append(path, p...), nil
}
func pathFromFlatmapKeyValue(key string, ty cty.Type) (cty.Path, error) {
var path cty.Path
var err error
View on GitHub (pinned to d32a084675)