How to fix There is no function named defaults in Terraform
The "defaults" function was removed in Terraform 1.3.0 as part of the optional attributes feature stabilization. This error occurs when using the deprecated function with newer Terraform versions. Replace it with native default value syntax in variable type definitions.
Quick fix
Fixes There is no function named defaults
grep -r "optional(" .- Identify which variables use optional attributes
- Update variable definitions with inline defaults
- Remove defaults() function calls from locals blocks
- Update module calls that use defaults()
grep -r "optional(" .There is no function named defaults
What this error means
Terraform 1.3.0 de-experimentalized the optional attributes feature and removed the `defaults()` helper function. This function was used to apply default values to optional object attributes, but it's no longer available. The error indicates your Terraform code is using a function that no longer exists in the current version.
Typical symptoms
- Error message: 'Call to unknown function... There is no function named defaults'
- Terraform fails during plan or apply phases
- Issue occurs after upgrading to Terraform 1.3.0 or later
- Code contains calls like `defaults(var.config, {...})` in locals or outputs
- Modules from older versions (like AWS EKS Blueprints) fail to parse
Common causes
- Using Terraform 1.3.0 or later where the defaults() function was removed
- Referencing a module that still uses the deprecated defaults() function
- Code written for Terraform 0.15.x or early 1.x versions before stabilization
- Not updating module versions after Terraform 1.3 upgrade
How to fix "There is no function named defaults"
Find all variable definitions that use optional() type constraints:
grep -r "optional(" .This will show you where optional attributes are declared. The defaults() function was typically used to provide default values for these optional fields.
Instead of using defaults() in a locals block, specify defaults directly in the variable type definition:
Before (Terraform < 1.3):
variable "settings" {
type = object({
name = string
enabled = optional(bool)
})
}
locals {
settings = defaults(var.settings, {
enabled = true
})
}After (Terraform >= 1.3):
variable "settings" {
type = object({
name = string
enabled = optional(bool, true) # Default value here
})
default = null
}Now the default value is specified inline with the optional attribute.
Delete any locals blocks that use the defaults() function entirely, since the defaults are now in the variable definition:
Remove this:
locals {
# Delete this entire block - no longer needed!
irsa_config = defaults(var.irsa_config, {
create_kubernetes_namespace = true
namespace_name = "karpenter"
})
}The defaults are now applied automatically when the variable is declared with inline defaults.
If using third-party modules that still have defaults() calls, you have two options:
Option 1: Update the module to a newer version
module "eks_blueprints" {
source = "aws-ia/eks-blueprints/aws"
version = ">= 5.0" # Use latest version without defaults()
}Option 2: Fork and fix the module yourself
- Download the module source
- Update all defaults() calls to inline defaults
- Point your module source to your fork
- Submit upstream PR to help others
Verify your changes are syntactically correct:
terraform validateThis will catch any remaining issues with the function calls or syntax. If you get other errors, review the variable definitions for consistency.
Once validation passes, test your configuration:
# Reinitialize if module versions changed
terraform init -upgrade
# Plan the changes
terraform plan
# Apply if plan looks correct
terraform applyThe configuration should now work with Terraform 1.3.0+.
Advanced notes
Terraform version compatibility:
- Terraform 0.15.x - 1.2.x: defaults() function available
- Terraform 1.3.0+: defaults() function removed (breaking change)
Multiple default values in nested objects:
For complex nested optional objects, you can provide defaults for multiple levels:
variable "config" {
type = object({
database = optional(object({
name = optional(string, "mydb")
port = optional(number, 5432)
enabled = optional(bool, true)
}))
})
}Using merge() as alternative:
If you have complex merging logic, use merge() function instead:
locals {
defaults = {
tag_env = "dev"
tag_team = "platform"
}
tags = merge(local.defaults, var.additional_tags)
}Migration checklist for modules:
- [ ] Update module source version in terraform configuration
- [ ] Run terraform get -update to download new versions
- [ ] Review any breaking changes in module changelog
- [ ] Test in development environment first
- [ ] Update documentation for your team
Frequently asked questions
- What does "There is no function named defaults" mean?
- 0 de-experimentalized the optional attributes feature and removed the defaults() helper function. This function was used to apply default values to optional object attributes, but it's no longer available. The error indicates your Terraform code is using a function that no longer exists in the current version.
- How do I fix "There is no function named defaults"?
- The "defaults" function was removed in Terraform 1.3.0 as part of the optional attributes feature stabilization. This error occurs when using the deprecated function with newer Terraform versions. Replace it with native default value syntax in variable type definitions.
- What causes "There is no function named defaults"?
- Using Terraform 1.3.0 or later where the defaults() function was removed Referencing a module that still uses the deprecated defaults() function Code written for Terraform 0.15.x or early 1.x versions before stabilization
- Is the "There is no function named defaults" 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
- ๐Terraform Documentation: Optional object type attributes(Official Docs)
- ๐Terraform Plugin Development: Deprecations and removals(Official Docs)
- ๐