feat(cli): validate Terraform CLI feature versions#237
Conversation
|
Follow-up reference for future feature-specific validation PRs: I added a semi-curated generator in the Generated file: Human-controlled input: Quick usage: canitf generate-cdktn-source \
--features-input data/hcl-feature-input.json \
--generated-features data/features.json \
--out data/cdktn-feature-constraints.tsThe generated output is intended to line up with this PR's Longer context: why this exists and how to use itThe broad changelog-derived table in
Current focused feature set:
Important baseline note: I could not confirm “OpenTofu forked from Terraform 1.7.5”; that appears to be the wrong framing. The local CDK Terrain workspace pins Terraform Example generated shape: export const TERRAFORM_HCL_FEATURE_CONSTRAINTS = {
"s3-native-state-locking": {
featureName: "S3 native state locking",
constraints: {
terraform: ">=1.10.0",
opentofu: ">=1.10.0",
},
category: "backend",
cdktnUseCase: "S3BackendConfig.useLockfile",
sources: [
"https://developer.hashicorp.com/terraform/language/v1.10.x/upgrade-guides#s3-backend",
"https://opentofu.org/docs/intro/whats-new/#native-s3-state-locking",
],
},
} as const;This should make the next PRs easier: update the curated JSON input, regenerate the TS source, then wire the relevant feature key into the specific validation path. |
Summary
Introduce a Terraform-compatible CLI feature/version validator that can be reused by feature PRs whose support depends on both the selected CLI product and its version.
This adds:
parseTerraformCliVersion()to detect Terraform vs OpenTofu from the first line of plainversionoutput:Terraform vX.Y.Z->terraformOpenTofu vX.Y.Z->opentofuValidateTerraformFeatureVersion, a single validation class for the matrix:terraform/opentofu) -> semver constraintversion -json-style output is not used to infer the product, because OpenTofu keeps the Terraform-compatibleterraform_versionkey.Intended downstream use
This is meant to unblock/reduce duplication for the S3
useLockfilework in:useLockfilefield and updatedynamodbTabledeprecated JSDoc #234A follow-up PR can add the backend-specific validation with:
If future features land at different times, the same class can encode different product constraints, for example:
Test plan
yarn jest packages/cdktn/test/validations.test.ts --runInBandyarn lerna run --scope cdktn buildyarn nx test cdktn --runInBand