How to Use the Terraform AWS Provider's Defined Functions

Terraform announced the general availability of provider-defined functions for AWS in Terraform v1.8.0.

This post will provide examples of Terraform’s existing built-in functions and why Terraform started to allow provider specific functions.

The post borrows heavily from https://www.hashicorp.com/blog/terraform-1-8-adds-provider-functions-for-aws-google-cloud-and-kubernetes

Dependencies

What is a Terraform Built-In Function?

The Terraform configuration language originally had limited built-in functions for tasks like calculations and validations.

Examples of existing built-in functions provided by Terraform include

Why Allow Provider Defined Functions?

To address the need for more capabilities, Terraform 1.8 introduced the ability for providers to create custom functions.

These functions can be called from within the Terraform configuration and are defined using the Terraform provider plugin framework.

Providers are declared in the terraform block. I typically use the AWS provider. See below for an example

terraform {
  required_version = ">= 1.8"

  required_providers {
    aws = {
        source  = "hashicorp/aws"
        version = ">= 5.40.0"
    }
  }
}

Where Can I find Documentation for the the Current AWS Provider Functions?

They are listed under Functions  in the left-rail of the Terraform AWS Provider documentation.

As of 4/11/2024, the AWS provider has three functions.

Next Steps

Be on the lookout for more AWS provider functions.

If you are interested in the existing functions, consider upgrading your terraform modules to use Terraform v1.8 and Terraform AWS Provider v5.40.0.