cdktf.json, the Terraform and
OpenTofu versions your project supports. Synth-time validations check features
against that declaration
(cdk-terrain#269).
Later releases added more validations against
targetVersions: function
availability became the default in v0.24, and v0.25 validates moved blocks,
import blocks, terraform_data, and the cloud backend at synth time
instead of probing the installed binary.What changed
New targetVersions field
targetVersions takes an npm semver range
per product, keyed by terraform and opentofu:
- A feature passes validation only if every version in the declared range of every targeted product supports it. If you use a feature that needs a newer version, raise the floor of your declared range.
- If you leave out a product, your project does not target it. If you leave
out
targetVersionsentirely, CDKTN assumes both products, fromterraform >=1.5.7andopentofu >=1.6.0. - CDKTN validates the field when it parses
cdktf.json. Terraform’s~>constraint syntax is rejected, because npm semver would read it with different semantics. cdktn initwrites the default ranges explicitly into new projects.
validateFunctionVersions flag) and
S3-native state locking, which
requires Terraform or OpenTofu 1.10 or later when useLockfile is set.
Synthesis never runs a binary for these checks
Validations againsttargetVersions are declarative. Synthesis behaves the
same in CI, in package builds, and on machines without Terraform or OpenTofu
installed.
Opt-in installed-binary check
Set"validateInstalledBinary": true to have cdktn diff, cdktn deploy,
cdktn destroy, and cdktn output verify the installed binary before they run
it. The command fails if CDKTN can’t tell whether the binary is Terraform or
OpenTofu, if that product isn’t declared in targetVersions, or if its version
is outside the declared range. The default is false.