{"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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/lang/funcs/collection.go#L573-L609","documentation":"Thrown by `transpose()` (TransposeFunc) while iterating the inner list of a map value, when an element of that inner list is null. transpose() builds reversed string-keyed lists, so a null element (which would become a key) is rejected. The input map type is map(list(string)), but a null can still appear at runtime.","triggerScenarios":"Calling transpose with a map whose list contains a null, e.g. `transpose({a = [\"x\", null]})`. Data sourced from a nullable nested attribute.","commonSituations":"A nested variable or datasource attribute producing nulls inside the inner lists. Optional inner elements resolving to null.","solutions":["Compact each inner list to drop nulls: `{ for k, v in var.m : k => compact(v) }`.","Filter at the source so inner lists never contain null.","Use `[for s in v : s if s != null]` per inner list."],"exampleFix":"// before\nlocals { t = transpose(var.tags) }   # inner lists contain nulls\n\n// after\nlocals { t = transpose({ for k, v in var.tags : k => compact(v) }) }","handlingStrategy":"validation","validationCode":"# HCL: compact inner lists to remove nulls\nlocals { t = transpose({ for k, v in var.m : k => compact(v) }) }","typeGuard":"# HCL: filter nulls explicitly\nlocals { t = transpose({ for k, v in var.m : k => [for x in v : x if x != null] }) }","tryCatchPattern":null,"preventionTips":["Run compact() on inner lists before transpose().","Constrain inner list element types to string at the variable declaration.","Sanitize datasource output feeding transpose."],"tags":["terraform","hcl","collection-functions","transpose","null-handling"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}