How to fix Error: Error in function call - Call to function map failed in Terraform
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- Identify where map() is being used in your configuration
- Replace map() with native map literal syntax
- Update third-party modules if needed
- Verify your Terraform version matches module requirements
grep -r "map(" *.tfError: 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
- 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
- Copying Terraform code from pre-v0.12 examples or documentation
- Module source not pinned to version that supports current Terraform
How to fix "Error: Error in function call - Call to function map failed"
Search your Terraform configuration files for calls to the map() function:
grep -r "map(" *.tfNote the locations where map() appears. This might be in your main configuration or in imported modules.
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:
tags = merge(local.tags, map("Name", "my-resource", "Environment", "prod"))New (correct) syntax:
tags = merge(local.tags, {
"Name" = "my-resource"
"Environment" = "prod"
})For empty maps, use {} instead of map():
Old:
my_map = map()New:
my_map = {}If the error is in an imported module (from Terraform Registry or GitHub), update the module version to one that supports your Terraform version:
module "example" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 5.0" # Update to a recent version
# ... rest of configuration
}Then reinitialize:
terraform init -upgradeCheck the module's documentation or terraform.tf for required_version constraints. Ensure your Terraform version meets the minimum requirement:
terraform versionIf needed, upgrade Terraform to a compatible version that supports the modules you're using.
After updating all map() calls, run a fresh plan to confirm the error is resolved:
rm -rf .terraform
terraform init
terraform planThe plan should now proceed without the 'Call to function map failed' error.
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:
# 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
- ๐Terraform Official Documentation
- ๐
- ๐
- ๐
- ๐