Skip to content

cdktn: gate cross-object variable validation conditions on targetVersions (terraform/opentofu >=1.9) #451

Description

@so0k

Description

Since Terraform 1.9.0 and OpenTofu 1.9.0, a variable validation.condition may reference other objects (other variables, locals, data sources, resources) in addition to the variable itself. On older versions such a condition is a hard error.

CDKTN lets users build exactly that (Op.or(Op.neq(env.stringValue, "prod"), Fn.contains([...], size.stringValue)) inside size.addValidation(...)) and synthesizes it without complaint, although the default targetVersions floor is terraform >=1.5.7 / opentofu >=1.6.0.

Proposal

Register the existing ValidateFeatureTargetSupport (precedent: S3Backend.useLockfile, backends/s3-backend.ts:20-26) with { terraform: ">=1.9.0", opentofu: ">=1.9.0" } when a variable's resolved validation condition (or error message) references anything other than var.<own id>. Usage is only known at resolve time, so this likely wants the gated / resolve-discovered idiom from TerraformElement._registerProviderFeature() (GatedFeatureValidation).

Validation must stay declared-target based (no probing of the installed binary) — see #275.

References

cdktn-planning RFC 09 (terraform test support); #269 / #296 (targetVersions machinery).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions