This error occurs when Terraform encounters a function name it doesn't recognize. Common causes include version mismatches, deprecated functions, or using Terragrunt functions in Terraform code.
Terraform and Terragrunt have built-in functions that can be used in HCL expressions. When you reference a function that doesn't exist in your current version of Terraform or Terragrunt, this error is raised. This typically happens in three scenarios: 1. **Version Mismatch**: You're using a newer function in an older version of Terraform that doesn't support it yet. 2. **Deprecated Functions**: You're using a function that existed in an older version but was removed or renamed (e.g., `defaults` was removed in Terraform 1.3). 3. **Tool Mismatch**: You're using a Terragrunt-specific function in Terraform code, or vice versa. The error message will specify which function is unknown, making it easier to troubleshoot.
Run the following command to see which version of Terraform you have installed:
terraform versionNote the version number. Most commonly, this error occurs when your installed Terraform version is older than what your configuration requires.
Look for a terraform block in your configuration (usually in main.tf or a separate version file):
terraform {
required_version = ">= 1.3"
}If the required version is higher than what you have installed, that's your issue. Also check for required_providers blocks that might have version constraints.
If your installed version is older than required, upgrade Terraform:
On macOS (with Homebrew):
brew upgrade terraformOn Linux or manual installation:
1. Visit https://www.terraform.io/downloads.html
2. Download the appropriate binary for your system
3. Extract and move it to your PATH (e.g., /usr/local/bin)
Verify the upgrade:
terraform versionIf you're upgrading Terraform, check the release notes for function changes. For example, in Terraform 1.3, the defaults function was removed.
Common deprecated functions:
- defaults() - removed in Terraform 1.3, use optional() with default values instead
- get_parent_tfvars_dir() - renamed to get_parent_terragrunt_dir() in Terragrunt 0.19+
Search your configuration for any functions matching the error message and check the Terraform documentation at https://developer.hashicorp.com/terraform/language/functions for the correct function name and syntax.
If you're using both Terraform and Terragrunt:
In regular Terraform files (.tf), use only Terraform built-in functions like:
- file(), filebase64(), jsonencode(), merge(), concat(), etc.
In Terragrunt files (terragrunt.hcl), you can use both Terraform functions AND Terragrunt-specific functions like:
- get_terragrunt_dir(), get_parent_terragrunt_dir(), path_relative_to_include(), etc.
If you're getting an unknown function error in a .tf file, make sure you're not using Terragrunt-specific functions there.
After upgrading or fixing function references, reinitialize Terraform:
# Remove the .terraform directory
rm -rf .terraform/
# Reinitialize Terraform
terraform initThen retry your terraform plan or terraform apply command.
Terragrunt vs Terraform Functions: Terragrunt wraps Terraform and adds its own HCL functions. In Terraform 0.15.3+, Terragrunt's custom functions are managed separately from Terraform's built-in functions. When you reference a function in Terragrunt configuration, it looks in Terragrunt's function set first.
Version Constraints: You can use Terragrunt's hcl() function to conditionally execute code based on Terraform version:
dynamic "feature" {
for_each = strcontains(local.tf_version, "1.3") ? [1] : []
content {
# Use v1.3+ functions here
}
}Provider Functions: Starting with Terraform 1.8, cloud providers can define custom functions (e.g., AWS provider functions). These are called with the syntax provider::<PROVIDER>::<FUNCTION>(). Ensure you have the correct provider version installed to use these functions.
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