{"record":{"id":"8f01654081f86d0a","repo":"hashicorp/terraform","slug":"input-list-must-not-contain-null-string","errorCode":null,"errorMessage":"input list must not contain null string","messagePattern":"input list must not contain null string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/lang/funcs/collection.go","lineNumber":591,"sourceCode":"\tRefineResult: refineNotNull,\n\tImpl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {\n\t\tinputMap := args[0]\n\t\tif !inputMap.IsWhollyKnown() {\n\t\t\treturn cty.UnknownVal(retType), nil\n\t\t}\n\n\t\toutputMap := make(map[string]cty.Value)\n\t\ttmpMap := make(map[string][]string)\n\n\t\tfor it := inputMap.ElementIterator(); it.Next(); {\n\t\t\tinKey, inVal := it.Element()\n\t\t\tif inVal.IsNull() {\n\t\t\t\treturn cty.MapValEmpty(cty.List(cty.String)), errors.New(\"input must not contain null list\")\n\t\t\t}\n\t\t\tfor iter := inVal.ElementIterator(); iter.Next(); {\n\t\t\t\t_, val := iter.Element()\n\t\t\t\tif val.IsNull() {\n\t\t\t\t\treturn cty.MapValEmpty(cty.List(cty.String)), errors.New(\"input list must not contain null string\")\n\t\t\t\t}\n\t\t\t\tif !val.Type().Equals(cty.String) {\n\t\t\t\t\treturn cty.MapValEmpty(cty.List(cty.String)), errors.New(\"input must be a map of lists of strings\")\n\t\t\t\t}\n\n\t\t\t\toutKey := val.AsString()\n\t\t\t\tif _, ok := tmpMap[outKey]; !ok {\n\t\t\t\t\ttmpMap[outKey] = make([]string, 0)\n\t\t\t\t}\n\t\t\t\toutVal := tmpMap[outKey]\n\t\t\t\toutVal = append(outVal, inKey.AsString())\n\t\t\t\tsort.Strings(outVal)\n\t\t\t\ttmpMap[outKey] = outVal\n\t\t\t}\n\t\t}\n\n\t\tfor outKey, outVal := range tmpMap {\n\t\t\tvalues := make([]cty.Value, 0)","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/lang/funcs/collection.go#L573-L609","documentation":"Thrown by TransposeFunc.Impl when an element inside one of the inner lists is null. transpose() expects every inner element to be a string; a null element cannot become an output key.","triggerScenarios":"transpose({a = [\"x\", null], b = [\"y\"]}); a list of strings containing a null because an upstream expression produced one.","commonSituations":"compact() not applied to a list that may contain nulls; optional object attributes yielding null strings; mixed data with gaps.","solutions":["Run each inner list through compact() to strip nulls before transpose().","Filter nulls in a for expression: [for s in list : s if s != null].","Fix the upstream producer so it never emits null strings."],"exampleFix":"# before\nlocals { t = transpose(var.deps) }   # inner lists contain nulls\n# after\nlocals {\n  clean = { for k, v in var.deps : k => compact(v) }\n  t     = transpose(local.clean)\n}","handlingStrategy":"validation","validationCode":"# remove null elements from inner lists with compact()\nlocals {\n  clean = { for k, v in var.deps : k => compact(v) }\n  t     = transpose(local.clean)\n}","typeGuard":"locals {\n  clean = { for k, v in var.deps : k => [for s in v : s if s != null] }\n  t     = transpose(local.clean)\n}","tryCatchPattern":"locals { t = try(transpose({ for k, v in var.deps : k => compact(v) }), {}) }","preventionTips":["Apply compact() to lists that may contain nulls.","Type inner lists as list(string) and avoid optional null defaults.","Sanitize upstream data sources (JSON) that can yield nulls."],"tags":["hcl","function","transpose","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}