How to fix There is no function named defaults in Terraform

TerraformINTERMEDIATEMEDIUMUpdated Dec 30, 2025ยท 94 views

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(" .
  1. Identify which variables use optional attributes
  2. Update variable definitions with inline defaults
  3. Remove defaults() function calls from locals blocks
  4. Update module calls that use defaults()
terraform โ€” error
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

  1. Using Terraform 1.3.0 or later where the defaults() function was removed
  2. Referencing a module that still uses the deprecated defaults() function
  3. Code written for Terraform 0.15.x or early 1.x versions before stabilization
  4. Not updating module versions after Terraform 1.3 upgrade

How to fix "There is no function named defaults"

1Identify which variables use optional attributes

Find all variable definitions that use optional() type constraints:

bash
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.

2Update variable definitions with inline defaults

Instead of using defaults() in a locals block, specify defaults directly in the variable type definition:

Before (Terraform < 1.3):

hcl
variable "settings" {
  type = object({
    name    = string
    enabled = optional(bool)
  })
}

locals {
  settings = defaults(var.settings, {
    enabled = true
  })
}

After (Terraform >= 1.3):

hcl
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.

3Remove defaults() function calls from locals blocks

Delete any locals blocks that use the defaults() function entirely, since the defaults are now in the variable definition:

Remove this:

hcl
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.

4Update module calls that use defaults()

If using third-party modules that still have defaults() calls, you have two options:

Option 1: Update the module to a newer version

hcl
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

5Test with terraform validate

Verify your changes are syntactically correct:

bash
terraform validate

This will catch any remaining issues with the function calls or syntax. If you get other errors, review the variable definitions for consistency.

6Run terraform plan and apply with updated code

Once validation passes, test your configuration:

bash
# Reinitialize if module versions changed
terraform init -upgrade

# Plan the changes
terraform plan

# Apply if plan looks correct
terraform apply

The 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:

hcl
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:

hcl
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