{"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":"exception","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/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/hcl2shim/paths.go#L118-L154","documentation":"Returned by pathFromFlatmapKeyValue (paths.go:136) when the declared type for the current path segment is a primitive (string/number/bool) but there is still a remaining key segment to navigate into. You cannot descend into a primitive — there are no sub-attributes — so any further path step is invalid.","triggerScenarios":"Navigating a flatmap key like 'name.0' where the schema declares 'name' as a primitive cty.String. pathFromFlatmapKeyValue sees a non-empty rest segment while ty.IsPrimitiveType() is true, hitting the first case branch that returns this error.","commonSituations":"Schema changed a primitive attribute to a collection (or vice versa) so the flatmap key depth no longer matches. A diff/state key has extra dot-segments that imply nesting the schema doesn't support. Manually edited state introducing spurious sub-keys on a scalar.","solutions":["Compare the flatmap key depth against the schema: a primitive attribute must be a leaf — remove any extra '.N' or '.sub' segments on it.","If the attribute legitimately became a collection, update the schema type and migrate the state key shape together.","If the extra segment is spurious, clean the state file or re-apply to regenerate the diff.","Pin the provider version matching the state if a schema type change caused the mismatch."],"exampleFix":"// before — schema: name = cty.String\n// state key: \"name.0\"  (cannot index into a string)\n\n// after — keep scalar keys flat\n\"name\": \"my-instance\"","handlingStrategy":"validation","validationCode":"// Ensure primitive attributes are not given nested sub-keys\nfunc noNestedPrimitiveKeys(keys []string, ty cty.Type) error {\n    for name, aty := range ty.AttributeTypes() {\n        if !aty.IsPrimitiveType() {\n            continue\n        }\n        for _, k := range keys {\n            if strings.HasPrefix(k, name+\".\") {\n                return fmt.Errorf(\"primitive attribute %s cannot have sub-key in %s\", name, k)\n            }\n        }\n    }\n    return nil\n}","typeGuard":"func isLeafKey(key, attrName string, ty cty.Type) bool {\n    aty, ok := ty.AttributeTypes()[attrName]\n    if !ok {\n        return false\n    }\n    return aty.IsPrimitiveType() && !strings.Contains(strings.TrimPrefix(key, attrName+\".\"), \".\")\n}","tryCatchPattern":null,"preventionTips":["When changing an attribute from primitive to collection (or back), migrate state key shapes together.","Avoid manual edits that introduce spurious dot-segments on scalar attributes.","Keep provider schemas and state version-aligned."],"tags":["hcl2shim","paths","primitive","schema-mismatch"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}