website/docs/language/functions/index.mdx
The OpenTofu language includes a number of built-in functions that you can call from within expressions to transform and combine values. The general syntax for function calls is a function name followed by comma-separated arguments in parentheses:
max(5, 12, 9)
For more details on syntax, see Function Calls in the Expressions section.
You can experiment with the behavior of OpenTofu's built-in functions from
the OpenTofu expression console, by running
the tofu console command:
> max(5, 12, 9)
12
The examples in the documentation for each function use console output to illustrate the result of calling the function with different parameters.
As of OpenTofu 1.7.0, providers may define their own functions to be available during execution.
OpenTofu iterates through the required_providers block
and queries the specified providers for any functions they wish to register. Functions are
added to the current module's context under provider::<provider_name>::<function_name>. Provider
aliases are also supported under provider::<provider_name>::<provider_alias>::<function_name>.
Functions are scoped to the module that requires the provider and are not inherited by child modules.
terraform {
required_providers {
myhelper = {
# yantrio/helpers registers a function named "echo"
source = "yantrio/helpers"
}
}
}
locals {
myval = provider::myhelper::echo("Hello Functions!")
}
OpenTofu has a built-in provider terraform.io/builtin/terraform which provides additional functions that can be used in OpenTofu configurations.
GetProviderSchema() is used to initially query the functions available in a given provider.GetFunctions(). See the experimental Lua and Go providers for implementation examples.