Terraform Built-in Functions

Search Terraform built-in functions by name, category and signature.

Interactive Terraform function reference covering string, collection, encoding, filesystem, numeric, network and crypto functions — each with its signature, a clear description and a worked example.

How do I look up a value in a map with a fallback in Terraform?

Use lookup(map, key, default), which returns the value at the key or the default if the key is missing. For chaining several possible values, coalesce(a, b, c) returns the first non-null, non-empty argument.

Every Terraform function, searchable

Terraform’s configuration language (HCL) ships with a large library of built-in functions for transforming strings, collections, numbers, files, IP ranges and more. This reference lists each function with its signature, a description and a concrete example. Filter by category or search by name.

How it works

Terraform functions are pure: given the same inputs they always return the same output, and they run during plan/apply to compute values for locals, resource arguments and outputs. There are no user-defined functions — you compose the built-ins.

Functions are grouped by purpose. String functions (format, replace, substr) manipulate text. Collection functions (merge, flatten, lookup, distinct) reshape lists, sets and maps. Encoding functions (jsonencode, base64encode, yamlencode) serialise values for policies and APIs. Network functions (cidrsubnet, cidrhost) do subnet math. Filesystem functions (file, templatefile) read content from disk. The category filter in this tool mirrors these groups.

Read each entry as name(arguments) with the example showing a representative input and the resulting value. Combine functions freely, for example join(",", distinct(flatten(var.lists))).

Tips and examples

  • Provide safe defaults instead of failing a plan:
locals {
  region = coalesce(var.region, "eu-west-1")
  tag    = lookup(var.tags, "env", "dev")
}
  • Build subnets programmatically across availability zones:
cidrsubnet("10.0.0.0/16", 8, count.index)
  • Use try(...) to gracefully handle expressions that might error, and jsonencode to emit IAM or other JSON policy documents from native HCL objects.
  • Test any expression quickly in terraform console before wiring it into your configuration.