How to fix Error: Error in function call - Call to function map failed in Terraform

TerraformBEGINNERMEDIUMUpdated Dec 30, 2025ยท 145 views

The map() function has been deprecated in Terraform v0.12 and removed in later versions. This error occurs when you use the legacy map() function syntax, which is no longer available. Replace deprecated map() calls with native map literal syntax using curly braces {}.

Quick fix

Fixes Error: Error in function call - Call to function map failed

grep -r "map(" *.tf
  1. Identify where map() is being used in your configuration
  2. Replace map() with native map literal syntax
  3. Update third-party modules if needed
  4. Verify your Terraform version matches module requirements
terraform โ€” error
grep -r "map(" *.tf
Error: Error in function call - Call to function map failed

What this error means

The map() function was a legacy way to create maps in Terraform before v0.12 introduced native map literal syntax. When Terraform encounters a call to map(), it fails because the function no longer exists in the standard function library. This typically happens when using older Terraform code or outdated third-party modules that haven't been updated to use modern syntax. The error is a sign that your configuration or imported modules need to be updated to match current Terraform version requirements.

Typical symptoms

  • Terraform plan fails with 'Call to function map failed' error
  • Error appears during terraform init or terraform plan execution
  • Using third-party modules or legacy Terraform configurations
  • Issue only occurs with Terraform v0.15 or later
  • Affected code uses map() function to create maps or assign values

Common causes

  1. Using deprecated map() function syntax from Terraform < v0.12
  2. Third-party modules or templates not updated for Terraform v0.12+
  3. Terraform version upgraded without updating legacy code
  4. Copying Terraform code from pre-v0.12 examples or documentation
  5. Module source not pinned to version that supports current Terraform

How to fix "Error: Error in function call - Call to function map failed"

1Identify where map() is being used in your configuration

Search your Terraform configuration files for calls to the map() function:

bash
grep -r "map(" *.tf

Note the locations where map() appears. This might be in your main configuration or in imported modules.

2Replace map() with native map literal syntax

Convert all map() calls to use native map syntax with curly braces. The map() function was used to create maps from key-value pairs:

Old (deprecated) syntax:

hcl
tags = merge(local.tags, map("Name", "my-resource", "Environment", "prod"))

New (correct) syntax:

hcl
tags = merge(local.tags, {
  "Name"        = "my-resource"
  "Environment" = "prod"
})

For empty maps, use {} instead of map():

Old:

hcl
my_map = map()

New:

hcl
my_map = {}
3Update third-party modules if needed

If the error is in an imported module (from Terraform Registry or GitHub), update the module version to one that supports your Terraform version:

hcl
module "example" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "~> 5.0"  # Update to a recent version
  # ... rest of configuration
}

Then reinitialize:

bash
terraform init -upgrade
4Verify your Terraform version matches module requirements

Check the module's documentation or terraform.tf for required_version constraints. Ensure your Terraform version meets the minimum requirement:

bash
terraform version

If needed, upgrade Terraform to a compatible version that supports the modules you're using.

5Run terraform plan to verify the fix

After updating all map() calls, run a fresh plan to confirm the error is resolved:

bash
rm -rf .terraform
terraform init
terraform plan

The plan should now proceed without the 'Call to function map failed' error.

6Review other deprecated functions in your code

While fixing map(), check for other deprecated functions that may also fail in modern Terraform versions:

- lookup() with 2 arguments: Update to use 3-argument form with default value
- matchkeys(): Use setproduct() and contains() instead
- transpose(): Manually restructure data if needed

See the Terraform language functions documentation to verify your code uses only supported functions.

Advanced notes

Function Deprecation History: The map() function was removed entirely in Terraform v0.15.0 as part of the deprecation cycle that began in v0.12.0. If you need to support both old and new Terraform versions, you must maintain separate branches of your code.

Migration Guide: For complex map() usage with dynamic key-value pairs, use the native syntax with conditional expressions:

hcl
# Dynamic map creation
tags = merge(
  { "Common" = "tag" },
  var.environment != null ? { "Environment" = var.environment } : {}
)

Module Compatibility: When upgrading modules, check the module's CHANGELOG.md for the minimum Terraform version required. Most community modules now require Terraform 1.0+.

Testing in CI/CD: After updating, ensure your CI/CD pipeline runs terraform validate and terraform plan to catch any remaining syntax issues before applying changes.

Frequently asked questions

What does "Error: Error in function call - Call to function map failed" mean?
12 introduced native map literal syntax. When Terraform encounters a call to map(), it fails because the function no longer exists in the standard function library. This typically happens when using older Terraform code or outdated third-party modules that haven't been updated to use modern syntax.
How do I fix "Error: Error in function call - Call to function map failed"?
The map() function has been deprecated in Terraform v0.12 and removed in later versions. This error occurs when you use the legacy map() function syntax, which is no longer available. Replace deprecated map() calls with native map literal syntax using curly braces {}.
What causes "Error: Error in function call - Call to function map failed"?
Using deprecated map() function syntax from Terraform < v0.12 Third-party modules or templates not updated for Terraform v0.12+ Terraform version upgraded without updating legacy code
Is the "Error: Error in function call - Call to function map failed" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading