{"record":{"id":"6517984d4d101e8f","repo":"hashicorp/terraform","slug":"invalid-step-q-with-type-v","errorCode":null,"errorMessage":"invalid step %q with type %#v","messagePattern":"invalid step %q with type %#v","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/hcl2shim/paths.go","lineNumber":136,"sourceCode":"\tif rest == \"\" {\n\t\treturn path, nil\n\t}\n\n\tp, err := pathFromFlatmapKeyValue(rest, ty)\n\tif err != nil {\n\t\treturn path, err\n\t}\n\n\treturn append(path, p...), nil\n}\n\nfunc pathFromFlatmapKeyValue(key string, ty cty.Type) (cty.Path, error) {\n\tvar path cty.Path\n\tvar err error\n\n\tswitch {\n\tcase ty.IsPrimitiveType():\n\t\terr = fmt.Errorf(\"invalid step %q with type %#v\", key, ty)\n\tcase ty.IsObjectType():\n\t\tpath, err = pathFromFlatmapKeyObject(key, ty.AttributeTypes())\n\tcase ty.IsTupleType():\n\t\tpath, err = pathFromFlatmapKeyTuple(key, ty.TupleElementTypes())\n\tcase ty.IsMapType():\n\t\tpath, err = pathFromFlatmapKeyMap(key, ty)\n\tcase ty.IsListType():\n\t\tpath, err = pathFromFlatmapKeyList(key, ty)\n\tcase ty.IsSetType():\n\t\tpath, err = pathFromFlatmapKeySet(key, ty)\n\tdefault:\n\t\terr = fmt.Errorf(\"unrecognized type: %s\", ty.FriendlyName())\n\t}\n\n\tif err != nil {\n\t\treturn path, err\n\t}\n","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/configs/hcl2shim/paths.go#L118-L154","documentation":"Returned by pathFromFlatmapKeyValue when the current type at this position in the path is primitive (string, number, bool) but the flatmap key still has more segments to consume. A primitive has no further navigable structure, so any suffix (e.g. '.foo' or '.0') is invalid — the path is trying to descend into a leaf.","triggerScenarios":"Calling pathFromFlatmapKeyValue (transitively from requiresReplacePath or any flatmap-key-to-cty-path helper) with a key like 'attr.leaf.deeper' where 'attr' resolves to a cty.String. The decoder walked into 'attr', found a primitive type, but still has 'leaf.deeper' left over.","commonSituations":"Diff or RequiresReplace keys built by string concatenation that appended extra segments beyond the leaf; schema change that turned an object-typed attribute into a primitive while old keys still descend into it; misformatted flatmap keys from custom producers.","solutions":["Inspect the full flatmap key — the suffix after the primitive attribute is spurious and should be removed.","If the attribute was supposed to be an object/collection, restore or correct the schema type so descent is valid.","Regenerate the diff/RequiresReplace list against the current schema so keys match the actual type structure.","Validate flatmap keys against the schema before persisting them."],"exampleFix":"// before: flatmap key 'name.first' where 'name' is cty.String\n// after: flatmap key 'name' (no further descent on a primitive)","handlingStrategy":"validation","validationCode":"func flatmapKeyRespectsPrimitiveLeaf(key string, ty cty.Type) bool {\n    // Walk the type tree segment-by-segment; if a primitive is reached and key has remaining segments, fail.\n    return canDescend(key, ty)\n}\nfunc canDescend(key string, ty cty.Type) bool {\n    _, rest := pathSplit(key)\n    if rest == \"\" { return true }\n    if ty.IsPrimitiveType() { return false }\n    // recurse into object/tuple/map/list/set as appropriate\n    return true\n}","typeGuard":"func keyIsValidForType(key string, ty cty.Type) bool {\n    _, rest := pathSplit(key)\n    if rest == \"\" { return true }\n    return !ty.IsPrimitiveType()\n}","tryCatchPattern":null,"preventionTips":["Build flatmap keys from typed path objects rather than string concatenation to avoid over-descending past primitives.","Regenerate diffs/RequiresReplace after changing an attribute from object to primitive type.","Validate flatmap keys against the schema before persisting them."],"tags":["flatmap","hcl2shim","paths","type-mismatch","go"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}