{
  "schemaVersion": "ebb.rule.v1",
  "id": "terraform.function.list-map",
  "ecosystem": "terraform",
  "purl": "pkg:generic/terraform",
  "affectedVersions": "vers:semver/>=0.15.0",
  "event": "removed",
  "severity": "high",
  "title": "The list() and map() functions were removed in Terraform 0.15",
  "summary": "Terraform v0.12 replaced the list() and map() functions with first-class [ ... ] and { ... } syntax, and the v0.15 upgrade guide states that the deprecated functions were removed in v0.15. Replace list(a, b) with tolist([a, b]) and map(k, v) with tomap({ k = v }); because Terraform can usually infer the type from context, the bare [ ... ] and { ... } forms often work without the conversion. The list(string) and map(string) type constraints are different and remain valid.",
  "replacement": "tolist([ ... ]) for list(), tomap({ ... }) for map()",
  "sources": [
    {
      "title": "Terraform 0.15 upgrade guide: legacy configuration language features",
      "url": "https://developer.hashicorp.com/terraform/language/v1.1.x/upgrade-guides/0-15",
      "accessedAt": "2026-10-31"
    },
    {
      "title": "Terraform tolist function",
      "url": "https://developer.hashicorp.com/terraform/language/functions/tolist",
      "accessedAt": "2026-10-31"
    },
    {
      "title": "Terraform tomap function",
      "url": "https://developer.hashicorp.com/terraform/language/functions/tomap",
      "accessedAt": "2026-10-31"
    }
  ],
  "provenance": {
    "observedAt": "2026-10-31",
    "reviewedAt": "2026-10-31",
    "reviewer": "arminazimi"
  },
  "migration": {
    "constraints": [
      "Do not rewrite a type constraint: `type = list(string)` and `type = map(object({...}))` are type constructors that still exist in Terraform 0.15 and later.",
      "Rewrite a call only when every argument is on one line and the argument count is meaningful: list() needs at least one value, and map() needs an even number of key/value arguments.",
      "In a map() call, write each key as an identifier or a quoted string; a bare expression key does not have the same meaning in an object constructor."
    ],
    "steps": [
      {
        "id": "replace-list-map-calls",
        "title": "Replace the removed calls",
        "instructions": "Change `list(a, b)` to `tolist([a, b])` and `map(\"k\", v)` to `tomap({ k = v })`. When the surrounding context already fixes the type, the bare `[a, b]` and `{ k = v }` forms are also correct.",
        "targets": "declaration"
      },
      {
        "id": "align-other-calls",
        "title": "Find the calls left in other files",
        "instructions": "Search *.tf for `list(` and `map(` outside variable type constraints, and rewrite the value calls the same way. Leave `list(string)`, `map(string)`, and other type constructors unchanged.",
        "targets": "all"
      }
    ],
    "verification": [
      {
        "command": "terraform init -backend=false && terraform validate",
        "purpose": "Initialize without touching remote state and check that no removed function is left."
      },
      {
        "command": "terraform plan",
        "purpose": "Confirm the collection types and values are unchanged apart from the rewrite."
      }
    ]
  }
}
