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 {}.
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.
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.
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.
Error: Error rendering template: template not found
How to fix "template not found" error in Terraform
Error: Error generating private key
How to fix 'Error generating private key' in Terraform
Error creating Kubernetes Service: field is immutable
How to fix "field is immutable" errors in Terraform
Error: Error creating local file: open: permission denied
How to fix "Error creating local file: permission denied" in Terraform
Error: line endings have changed from CRLF to LF
Line endings have changed from CRLF to LF in Terraform