How to fix There is no function named setsubtract in Terraform

TerraformBEGINNERMEDIUMUpdated Dec 30, 2025ยท 91 views

The setsubtract function is not available in your Terraform version. This function computes the relative complement of two sets and was introduced in Terraform 0.12.20. Upgrading Terraform or using an older module version will resolve this error.

Quick fix

Fixes There is no function named setsubtract

terraform version
# Check current version

# For Linux/macOS using Homebrew:
brew upgrade terraform

# For Windows using Scoop:
scoop update terraform

# Or download directly from https://www.terraform.io/downloads
  1. Upgrade Terraform to 0.12.20 or later
  2. If unable to upgrade, downgrade the module version
  3. Verify the function works after upgrade
terraform โ€” error
terraform version
# Check current version
# For Linux/macOS using Homebrew:
brew upgrade terraform
# For Windows using Scoop:
scoop update terraform
# Or download directly from https://www.terraform.io/downloads
There is no function named setsubtract

What this error means

Terraform has a built-in function called `setsubtract` that was added in version 0.12.20 (released in early 2020). This error occurs when you use `setsubtract()` in your configuration but are running a version of Terraform released before this function was available. The `setsubtract` function returns a new set containing elements from the first set that are not present in the second set (a relative complement operation). If Terraform reports this function doesn't exist, your installed version predates its introduction.

Typical symptoms

  • Error: Call to unknown function on [file path]: There is no function named 'setsubtract'
  • Module fails to load when using terraform-aws-vpc 2.60 or later
  • Terraform plan or apply fails during parsing
  • CI/CD pipeline fails with unknown function error

Common causes

  1. Running Terraform version older than 0.12.20
  2. Using a Terraform module (like terraform-aws-vpc) that requires setsubtract with an incompatible Terraform version
  3. Not updating Terraform CLI after upgrading a module that uses setsubtract

How to fix "There is no function named setsubtract"

1Upgrade Terraform to 0.12.20 or later

The primary solution is to upgrade to a Terraform version that includes the setsubtract function.

bash
terraform version
# Check current version

# For Linux/macOS using Homebrew:
brew upgrade terraform

# For Windows using Scoop:
scoop update terraform

# Or download directly from https://www.terraform.io/downloads

Verify the upgrade:

bash
terraform version
# Should be 0.12.20 or later (ideally 1.x)
2If unable to upgrade, downgrade the module version

If you cannot upgrade Terraform immediately, downgrade the affected module to a version that doesn't use setsubtract.

hcl
module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "2.59"  # Use 2.59 instead of 2.60+
  # ... rest of configuration
}

Run terraform init to fetch the older version:

bash
terraform init -upgrade

Note: This is a temporary workaround. Plan to upgrade Terraform as soon as possible.

3Verify the function works after upgrade

Once upgraded, test that setsubtract is available:

bash
terraform console

Then in the console:

hcl
setsubtract(["a", "b", "c"], ["a", "c"])
# Output: [
#   "b",
# ]

Exit the console with exit or Ctrl+D.

Advanced notes

The setsubtract function is part of Terraform's set operations family, also including setunion and setintersection. These functions were added to provide better support for complex data transformations on sets of values. If you are using community modules that depend on these functions, always check the module's documented Terraform version requirements before upgrading the module. The error message will consistently mention the function name, making it easy to identify which function is missing. For modules like terraform-aws-vpc, release notes typically indicate when new Terraform version requirements are introduced.

Frequently asked questions

What does "There is no function named setsubtract" mean?
20 (released in early 2020). This error occurs when you use setsubtract() in your configuration but are running a version of Terraform released before this function was available. The setsubtract function returns a new set containing elements from the first set that are not present in the second set (a relative complement operation).
How do I fix "There is no function named setsubtract"?
The setsubtract function is not available in your Terraform version. This function computes the relative complement of two sets and was introduced in Terraform 0.12.20. Upgrading Terraform or using an older module version will resolve this error.
What causes "There is no function named setsubtract"?
Running Terraform version older than 0.12.20 Using a Terraform module (like terraform-aws-vpc) that requires setsubtract with an incompatible Terraform version Not updating Terraform CLI after upgrading a module that uses setsubtract
Is the "There is no function named setsubtract" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading