{"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/c9def3e214014c1188faabfc4a5bde5095139765/internal/lang/funcs/collection.go#L568-L604","documentation":"Thrown by TransposeFunc.Impl (the HCL transpose() builtin) when iterating the input map of lists and finding that a value (which should be a list of strings) is null. transpose() cannot place a null list, so it errors.","triggerScenarios":"transpose({a = null, b = [\"x\"]}) where one map entry's list is null; a map where an optional key resolved to null.","commonSituations":"An optional variable defaulting to null for one key; a for-expression that emits null for some entries; data source returning null for a list attribute.","solutions":["Coalesce null entries to an empty list: { for k,v in var.m : k => coalesce(v, []) }.","Drop null-valued keys with an if guard before transpose().","Ensure every map value is a non-null list at the source."],"exampleFix":"# before\nlocals { t = transpose(var.deps) }   # some values null\n# after\nlocals {\n  clean = { for k, v in var.deps : k => v if v != null }\n  t     = transpose(local.clean)\n}","handlingStrategy":"validation","validationCode":"# strip null-valued entries before transpose\nlocals {\n  clean = { for k, v in var.deps : k => v if v != null }\n  t     = transpose(local.clean)\n}","typeGuard":"locals {\n  clean = { for k, v in var.deps : k => coalesce(v, []) }\n  t     = transpose(local.clean)\n}","tryCatchPattern":"locals { t = try(transpose({ for k, v in var.deps : k => v if v != null }), {}) }","preventionTips":["Default map values to [] instead of null.","Filter null entries with an `if v != null` guard in the for expression.","Type the variable as map(list(string)) so null lists surface earlier."],"tags":["hcl","function","transpose","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}