{"record":{"id":"ad1ef6e32901b274","repo":"hashicorp/terraform","slug":"index-s-out-of-range-in-v","errorCode":null,"errorMessage":"index %s out of range in %#v","messagePattern":"index (.+?) out of range in %#v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/hcl2shim/paths.go","lineNumber":177,"sourceCode":"\tvar path cty.Path\n\tvar err error\n\n\tk, rest := pathSplit(key)\n\n\t// we don't need to convert the index keys to paths\n\tif k == \"#\" {\n\t\treturn path, nil\n\t}\n\n\tidx, err := strconv.Atoi(k)\n\tif err != nil {\n\t\treturn path, err\n\t}\n\n\tpath = cty.Path{cty.IndexStep{Key: cty.NumberIntVal(int64(idx))}}\n\n\tif idx >= len(etys) {\n\t\treturn path, fmt.Errorf(\"index %s out of range in %#v\", key, etys)\n\t}\n\n\tif rest == \"\" {\n\t\treturn path, nil\n\t}\n\n\tty := etys[idx]\n\n\tp, err := pathFromFlatmapKeyValue(rest, ty.ElementType())\n\tif err != nil {\n\t\treturn path, err\n\t}\n\n\treturn append(path, p...), nil\n}\n\nfunc pathFromFlatmapKeyMap(key string, ty cty.Type) (cty.Path, error) {\n\tvar path cty.Path","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/hcl2shim/paths.go#L159-L195","documentation":"Returned by pathFromFlatmapKeyTuple (paths.go:177) when an index parsed from a flatmap key segment is greater than or equal to the number of element types in the tuple schema (idx >= len(etys)). Tuples are fixed-length and positionally typed, so an index beyond the declared arity has no corresponding element type.","triggerScenarios":"Navigating a flatmap key like 'config.5.value' when the tuple schema only declares, say, 3 element types. The strconv.Atoi succeeds but the bounds check `idx >= len(etys)` fails.","commonSituations":"The tuple schema's arity was reduced (elements removed) while state still references higher indices. State written by a provider version with a larger tuple. Manually edited state introducing out-of-range index keys.","solutions":["Compare the index in the message against the tuple's declared arity; remove the out-of-range element key or extend the schema.","If you intentionally shrank the tuple, write a state migration to drop the extra indexed entries and update the count.","Pin the provider version matching the state, or re-import to regenerate a consistent flatmap.","Audit the diff source to ensure it does not emit indices beyond the schema arity."],"exampleFix":"// before — schema: cty.Tuple([string, number])  (arity 2)\n// state key: \"config.2.value\"  (index 2 out of range)\n\n// after — keep indices within arity\n\"config.0\": \"web\"\n\"config.1\": \"8080\"","handlingStrategy":"validation","validationCode":"// Ensure a tuple index is within the schema arity before navigation\nfunc indexInRange(idx int, etys []cty.Type) bool {\n    return idx >= 0 && idx < len(etys)\n}","typeGuard":"func indexInRange(idx int, etys []cty.Type) bool {\n    return idx >= 0 && idx < len(etys)\n}","tryCatchPattern":null,"preventionTips":["When shrinking a tuple schema's arity, migrate state to drop out-of-range element keys.","Keep flatmap tuple indices within [0, arity).","Pin provider versions across structural schema changes."],"tags":["hcl2shim","paths","tuple","index-out-of-range","schema-drift"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}