Skip to content

fix: handle required_version in CDKTF terraform_json parser#7467

Open
raajheshkannaa wants to merge 1 commit intobridgecrewio:mainfrom
raajheshkannaa:fix/cdktf-required-version-crash
Open

fix: handle required_version in CDKTF terraform_json parser#7467
raajheshkannaa wants to merge 1 commit intobridgecrewio:mainfrom
raajheshkannaa:fix/cdktf-required-version-crash

Conversation

@raajheshkannaa
Copy link
Copy Markdown

Closes #7454

Summary

  • Fixed crash in terraform_json parser when CDKTF-generated cdk.tf.json contains required_version as a plain string
  • hclify() expects a dict, but required_version is a string. Added type check to route simple types through _clean_simple_type_list() instead
  • Also handles int, float, bool, None, and lists of simple types

Root cause

In handle_block_type(), all config values are passed to hclify(), which raises Exception: this method receives only dicts for non-dict values like required_version: ">= 1.5.0".

Test plan

  • Unit test: prepare_definition() with mixed dict/string values in terraform block
  • E2E test: full CDKTF fixture file with required_version loads without crash
  • All 12 existing terraform_json tests pass

The terraform_json parser crashed on CDKTF-generated cdk.tf.json files
that contain terraform.required_version as a string value. The
handle_block_type function assumed all values would be dicts, but
required_version is a simple string like ">= 1.5.0".

Skip hclify() for simple-type values and wrap them as list values
instead, consistent with how HCL attributes are represented elsewhere.

Fixes bridgecrewio#7454
@raajheshkannaa
Copy link
Copy Markdown
Author

Hi, could a maintainer approve the CI workflow run? The security scan check appears to be waiting for approval since this is an external contributor PR. Thanks!

@raajheshkannaa
Copy link
Copy Markdown
Author

Friendly bump. CI workflow has been waiting for maintainer approval since March 17. Could someone approve the workflow run so CI can validate this? Happy to address any feedback once tests run.

@raajheshkannaa
Copy link
Copy Markdown
Author

Friendly bump. CI workflow approval is still pending. Could a maintainer approve the workflow run? Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: terraform_json parser crashes on CDKTF-generated cdk.tf.json with required_version

1 participant