terraform config_error ai_generated true

Error: Unsupported argument: An argument named "validation" is not expected here. Did you mean "validation"?

ID: terraform/unsupported-argument-in-variable

Also available as: JSON · Markdown · 中文
88%Fix Rate
85%Confidence
1Evidence
2023-06-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Terraform v0.12 active
Terraform v0.13 active
Terraform v1.0 active

Root Cause

A variable block contains a nested block or argument that is not valid for that variable type, often due to Terraform version differences where variable validation was introduced in v0.13.

generic

中文

变量块包含对该变量类型无效的嵌套块或参数,通常是由于 Terraform 版本差异导致,其中变量验证是在 v0.13 中引入的。

Official Documentation

https://developer.hashicorp.com/terraform/language/values/variables#custom-validation-rules

Workarounds

  1. 95% success Update the required_version in terraform block: `terraform { required_version = ">= 0.13" }` then rerun `terraform init` to use a compatible Terraform version.
    Update the required_version in terraform block: `terraform { required_version = ">= 0.13" }` then rerun `terraform init` to use a compatible Terraform version.
  2. 80% success Remove the unsupported argument (e.g., validation block) and implement validation using a separate data source or condition in a local value.
    Remove the unsupported argument (e.g., validation block) and implement validation using a separate data source or condition in a local value.
  3. 90% success If using Terraform v0.12, upgrade to v0.13+ using the official upgrade guide: https://developer.hashicorp.com/terraform/upgrade-guides/0-13.
    If using Terraform v0.12, upgrade to v0.13+ using the official upgrade guide: https://developer.hashicorp.com/terraform/upgrade-guides/0-13.

中文步骤

  1. Update the required_version in terraform block: `terraform { required_version = ">= 0.13" }` then rerun `terraform init` to use a compatible Terraform version.
  2. Remove the unsupported argument (e.g., validation block) and implement validation using a separate data source or condition in a local value.
  3. If using Terraform v0.12, upgrade to v0.13+ using the official upgrade guide: https://developer.hashicorp.com/terraform/upgrade-guides/0-13.

Dead Ends

Common approaches that don't work:

  1. Renaming the argument to the suggested name without checking the Terraform version 90% fail

    The error often occurs because the feature (e.g., variable validation) doesn't exist in older versions; renaming won't help if the underlying feature is unsupported.

  2. Moving the argument to a different block like locals or outputs 70% fail

    Validation logic belongs to variable declarations; moving it elsewhere won't enforce input constraints and may cause runtime errors.

  3. Adding a required_providers block with a newer version but not updating the Terraform version constraint 85% fail

    Variable validation is a language feature, not provider-specific; the Terraform core version must be >=0.13 for validation blocks to work.