Terraform
Built-in Functions
Hands-on: Try the Perform Dynamic Operations with Functions tutorial.
The Terraform 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.
Provider-defined Functions
You cannot define your own functions in the Terraform configuration language, but you can develop your own providers that expose functions. Refer to Provider-defined functions for information about defining functions in custom providers.
When using a provider-specific function, add the provider::<local-name>::
where
<local-name>
corresponds with an entry in the required_providers
block.
The following example calls the encoode_tvfars
function in the terraform
provider:
provider::terraform::encode_tfvars({
example = "Hello!"
})
The documentation covers the built-in functions and built-in provider-defined functions only.
Functions defined by external providers are documented by those providers in the Terraform Registry.
Experimenting with Functions
You can experiment with the behavior of Terraform's built-in functions from
the Terraform expression console, by running
the terraform 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.