{"record":{"id":"b44dfa728e4cfbd7","repo":"hashicorp/terraform","slug":"input-must-not-contain-null-list","errorCode":null,"errorMessage":"input must not contain null list","messagePattern":"input must not contain null list","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/lang/funcs/collection.go","lineNumber":586,"sourceCode":"\t\t\tName: \"values\",\n\t\t\tType: cty.Map(cty.List(cty.String)),\n\t\t},\n\t},\n\tType:         function.StaticReturnType(cty.Map(cty.List(cty.String))),\n\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","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/lang/funcs/collection.go#L568-L604","documentation":"Thrown by the `transpose()` function (TransposeFunc) when a value in the input map is null. transpose() expects a map of lists of strings; a null list at any key cannot be transposed, so it aborts with this message. It returns an empty map-shaped value alongside the error.","triggerScenarios":"Calling `transpose({a = null})` or a map variable where some value list is null, e.g. `{ roles = null }`.","commonSituations":"A map variable with optional keys whose unset values resolve to null. Conditional construction that produces null lists for some keys.","solutions":["Filter out null values before transpose: `{ for k, v in var.m : k => v if v != null }`.","Provide `[]` as the default instead of null for empty cases: `coalesce(v, [])`.","Declare the variable type with non-optional list elements and defaults."],"exampleFix":"// before\nlocals { t = transpose(var.groups) }   # some values null\n\n// after\nlocals { t = transpose({ for k, v in var.groups : k => coalesce(v, []) }) }","handlingStrategy":"validation","validationCode":"# HCL: drop null lists before transpose\nlocals { t = transpose({ for k, v in var.m : k => v if v != null }) }","typeGuard":"# HCL: coalesce nulls to empty lists\nlocals { t = transpose({ for k, v in var.m : k => coalesce(v, []) }) }","tryCatchPattern":null,"preventionTips":["Filter nulls out of the map before transpose().","Default optional inner lists to [] rather than null.","Validate map shape in CI."],"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"}