Skip to content
DevOps AI ToolKit
Newsletter
All guides
AI for OpenTofu By James Joyner IV · · 8 min read Last reviewed Jul 2026

OpenTofu Error: 'Call to unknown function' in an Expression

Quick answer

Fix OpenTofu's 'Call to unknown function' error: diagnose typos, renamed built-ins, and provider-defined functions so tofu validate and plan succeed.

  • #opentofu
  • #terraform
  • #iac
  • #troubleshooting
  • #errors
Free toolkit

Stuck on this OpenTofu error? Get the free incident triage checklist

A one-page PDF — the exact steps to isolate, fix, and verify a production error like this one. No spam, unsubscribe anytime.

Exact Error Message


│ Error: Call to unknown function

│   on main.tf line 14, in locals:
│   14:   name = tolower(trimspace(var.project)) + "-prod"

│ There is no function named "trimspace". Did you mean "trim"?

The message points at the exact expression, names the unknown function, and often suggests the closest real function name.

What It Means

OpenTofu’s configuration language only lets you call functions it knows about: its built-in library (lower, trimspace, cidrsubnet, jsondecode, and so on) and, since the provider-defined functions feature, functions namespaced as provider::<name>::<func>. When you call a name that is not in either set, the parser stops before planning and reports Call to unknown function.

This is a static configuration error, not a runtime failure. Nothing has been created or refreshed yet, so the fix is always in the HCL, not in your cloud provider or state.

Common Causes

  • A simple typo in the function name (tolwer instead of lower, trimspace where the actual name applies).
  • Assuming a function exists that OpenTofu does not provide (there is no strlen; use length).
  • Using a name from another language or tool (JavaScript’s parseInt, Python’s str, shell’s basename).
  • Calling a provider-defined function without the full provider:: namespace, or before the provider is installed.
  • Copying HCL that relied on a newer OpenTofu version whose function is not available in the version you run.

Diagnostic Commands

Run validate to surface every unknown-function error at once, without touching any backend:

tofu validate

Confirm which OpenTofu version you are actually running, since the function set grows between releases:

tofu version

Test whether a name is a real function interactively in the console:

echo 'trim("  hi  ", " ")' | tofu console

If the call is a provider-defined function, make sure the provider is installed first:

tofu init

Step-by-Step Resolution

  1. Read the error’s suggestion. OpenTofu computes the nearest known function name (“Did you mean …?”) and it is usually correct.

  2. Fix the name in the expression. For the example above, trimspace is real but + is not string concatenation in HCL — replace it with interpolation:

locals {
  name = "${lower(trimspace(var.project))}-prod"
}
  1. If you invented a function that does not exist, map it to the real built-in. Common swaps: strlen to length, substr-style slicing to substr(string, offset, length), str to tostring, int to tonumber.

  2. For a provider-defined function, use the full three-part namespace and require the provider:

terraform {
  required_providers {
    example = {
      source = "registry.opentofu.org/example/example"
    }
  }
}

output "decoded" {
  value = provider::example::parse(var.raw)
}
  1. Re-run validate, then plan, to confirm the expression resolves:
tofu validate && tofu plan
Success! The configuration is valid.

If you are unsure which built-in does what you need, a quick prompt against the OpenTofu function library prompts can map your intent to the correct call.

Prevention

  • Keep an editor with OpenTofu/Terraform language server support so unknown functions are flagged as you type.
  • Run tofu validate in CI on every pull request to catch these before they reach an apply.
  • Remember HCL has no + for strings, no ternary functions like if(), and no imperative helpers; reach for interpolation and the conditional ? : operator instead.
  • Pin required_version in the terraform block so a function that exists locally is guaranteed to exist wherever the config runs.
  • When using provider-defined functions, always run tofu init first and reference them with the full provider:: prefix.
  • Invalid function argument — the function exists but you passed the wrong type or count of arguments.
  • Call to unknown function for provider::... — the provider is not installed or not required; run tofu init.
  • Unsupported attribute — a valid function returned an object, but you indexed a field it does not have.
  • Invalid template interpolation value — the function result is a complex type interpolated into a string.

Frequently Asked Questions

Why does OpenTofu suggest a function name I did not type? OpenTofu compares your unknown name against its built-in library and offers the closest match by edit distance, which is usually the function you meant.

Does OpenTofu support the same functions as Terraform? The core built-in library is broadly compatible, but versions drift and OpenTofu adds its own; always check tofu console or the docs for the version reported by tofu version.

Why does my provider function still say unknown after I added it? You must run tofu init to install the provider and call the function with its full provider::<name>::<func> namespace; a bare name will not resolve.

Can I define my own functions? Not in core configuration; you either use built-ins, provider-defined functions, or precompute values elsewhere and pass them in as variables. For more function and expression fixes, see the OpenTofu guides.

Free download · 368-page PDF

Fixed it? Get 500 OpenTofu & DevOps AI prompts — free

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.

Did this fix your issue?

Free download · 368-page PDF

Get 500 Battle-Tested DevOps AI Prompts — Free

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.