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.
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.
The primary solution is to upgrade to a Terraform version that includes the setsubtract function.
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/downloadsVerify the upgrade:
terraform version
# Should be 0.12.20 or later (ideally 1.x)If you cannot upgrade Terraform immediately, downgrade the affected module to a version that doesn't use setsubtract.
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:
terraform init -upgradeNote: This is a temporary workaround. Plan to upgrade Terraform as soon as possible.
Once upgraded, test that setsubtract is available:
terraform consoleThen in the console:
setsubtract(["a", "b", "c"], ["a", "c"])
# Output: [
# "b",
# ]Exit the console with exit or Ctrl+D.
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.
Error: Error rendering template: template not found
How to fix "template not found" error in Terraform
Error: Error generating private key
How to fix 'Error generating private key' in Terraform
Error creating Kubernetes Service: field is immutable
How to fix "field is immutable" errors in Terraform
Error: Error creating local file: open: permission denied
How to fix "Error creating local file: permission denied" in Terraform
Error: line endings have changed from CRLF to LF
Line endings have changed from CRLF to LF in Terraform