{"record":{"id":"13fc22fb738ad8ea","repo":"hashicorp/terraform","slug":"item-not-found","errorCode":null,"errorMessage":"item not found","messagePattern":"item not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/lang/funcs/collection.go","lineNumber":217,"sourceCode":"\n\t\tif args[0].LengthInt() == 0 { // Easy path\n\t\t\treturn cty.NilVal, errors.New(\"cannot search an empty list\")\n\t\t}\n\n\t\tfor it := args[0].ElementIterator(); it.Next(); {\n\t\t\ti, v := it.Element()\n\t\t\teq, err := stdlib.Equal(v, args[1])\n\t\t\tif err != nil {\n\t\t\t\treturn cty.NilVal, err\n\t\t\t}\n\t\t\tif !eq.IsKnown() {\n\t\t\t\treturn cty.UnknownVal(cty.Number), nil\n\t\t\t}\n\t\t\tif eq.True() {\n\t\t\t\treturn i, nil\n\t\t\t}\n\t\t}\n\t\treturn cty.NilVal, errors.New(\"item not found\")\n\n\t},\n})\n\n// LookupFunc constructs a function that performs dynamic lookups of map types.\nvar LookupFunc = function.New(&function.Spec{\n\tParams: []function.Parameter{\n\t\t{\n\t\t\tName:         \"inputMap\",\n\t\t\tType:         cty.DynamicPseudoType,\n\t\t\tAllowMarked:  true,\n\t\t\tAllowUnknown: true,\n\t\t},\n\t\t{\n\t\t\tName:         \"key\",\n\t\t\tType:         cty.String,\n\t\t\tAllowMarked:  true,\n\t\t\tAllowUnknown: true,","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/lang/funcs/collection.go#L199-L235","documentation":"Thrown by IndexFunc.Impl after iterating the entire list without an Equal match. The requested value simply is not present, so index() cannot return a position.","triggerScenarios":"index(var.list, \"missing\") where 'missing' never occurs; case mismatch (index(list, \"Prod\") when entries are 'prod'); searching for a number that exists only as a string.","commonSituations":"Typo or casing in the search value; value genuinely absent; type mismatch between the list element type and the search value.","solutions":["Verify the exact value and casing exist in the list.","Use contains(list, value) to pre-check before index().","Wrap in try() with a sentinel (e.g., -1) when absence is acceptable."],"exampleFix":"# before\nlocals { i = index(var.envs, var.target_env) }   # target_env not present -> error\n# after\nlocals {\n  i = contains(var.envs, var.target_env) ? index(var.envs, var.target_env) : -1\n}","handlingStrategy":"validation","validationCode":"# pre-check presence to avoid the not-found error\nlocals {\n  i = contains(var.list, var.target) ? index(var.list, var.target) : -1\n}","typeGuard":"locals {\n  present = contains(var.list, var.target)\n  i       = local.present ? index(var.list, var.target) : -1\n}","tryCatchPattern":"locals { i = try(index(var.list, var.target), -1) }","preventionTips":["Use contains() to test membership before index().","Normalize casing (lower()) on both the list and the search value.","Match types exactly (tostring()) to avoid silent mismatches."],"tags":["hcl","function","index","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}