Skip to content

fix(provider-generator): handle inline comments with brackets in variable type parsing - #60

Closed
josh-hook wants to merge 1 commit into
open-constructs:mainfrom
josh-hook:fix/cli/cdktf-get-inline-comment-with-bracket
Closed

josh-hook wants to merge 1 commit into
open-constructs:mainfrom
josh-hook:fix/cli/cdktf-get-inline-comment-with-bracket

Conversation

@josh-hook

@josh-hook josh-hook commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Related issue

Fixes #39

Description

This PR fixed cdktn get command failing to generate code from downstream Terraform that contains a variable with type including a closing bracket in the comments.

Example offending Terraform:

variable "iam_policy_statements" {
  description = "A list of IAM policy statements"
  type = list(object({  # TODO - change to map(object({...})) in next major version
    sid       = optional(string)
    actions   = optional(list(string))
    effect    = optional(string)
    resources = optional(list(string))
  }))
  default = null
}

(currently present in the Karpenter Terraform module)

The code generation fails due to the transformVariables CDKTN function that's parsing the variable type definition. Since the regex does not match newlines, it ends up matching to the commented-out } character, causing the resulting type to be parsed as list(object({ # TODO - change to map(object({..., which then later can't be parsed to an expression.

Previous approach: match everything on the first line which is wrapped in ${...}, everything else is an any.
Proposed fix: If it's a single-line type then grab everything between the starting ${ and ending }, else it's an any.

This PR also fixes the hcl2json/hcl-tools prebuild.sh script as in later versions of Go the wasm directory has changed from misc to lib.

Checklist

  • I have updated the PR title to match CDKTN's style guide
  • I have run the linter on my code locally
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation if applicable
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works if applicable
  • New and existing unit tests pass locally with my changes

@josh-hook
josh-hook requested a review from a team as a code owner March 18, 2026 11:16
@so0k

so0k commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Unknown scope "provider-schema" found in pull request title "fix(provider-schema): handle inline comments with brackets in variable type parsing". Scope must match one of: lib, cli, hcl2json, hcl2cdk, provider-generator, tests, examples, readme, docs, release, deps.

@jsteinich - should we add provider-schema or scope this under provider-generator ?

@jsteinich

Copy link
Copy Markdown
Contributor

Unknown scope "provider-schema" found in pull request title "fix(provider-schema): handle inline comments with brackets in variable type parsing". Scope must match one of: lib, cli, hcl2json, hcl2cdk, provider-generator, tests, examples, readme, docs, release, deps.

@jsteinich - should we add provider-schema or scope this under provider-generator ?

I would go with provider-generator as it impacts code generation

@so0k

so0k commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

also I identify a failed check is due to the conditions, it fails on skipped jobs, so I’ll push a fix to main for that - will let you know when to rebase

@so0k so0k changed the title fix(provider-schema): handle inline comments with brackets in variable type parsing fix(provider-generator): handle inline comments with brackets in variable type parsing Mar 20, 2026
@so0k

so0k commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

also I identify a failed check is due to the conditions, it fails on skipped jobs, so I’ll push a fix to main for that - will let you know when to rebase

After careful analysis:

The provider integration result job is passing on the latest run (23242067738). The earlier run (23242236580) was cancelled due to concurrency and correctly superseded.

The cancelled check in the result job condition is working as intended — keeping it red for a cancelled run is correct because the new concurrent run will pass and update the commit status.

Actual PR #60 failures (8 checks)

  1. Missing test snapshot — new test added without committing snapshot (user already commented on PR) ⏳
  2. Lint — PR title uses scope provider-schema which isn't in the allowed scopes list ✅

No workflow changes required.

@so0k
so0k force-pushed the fix/cli/cdktf-get-inline-comment-with-bracket branch from b15b98a to 2c033e8 Compare March 20, 2026 03:18
so0k added a commit that referenced this pull request Mar 20, 2026
…able type parsing (#61)

## Summary
- Includes the fix from #60 by @josh-hook to handle inline comments with
brackets in Terraform variable type constraints during schema parsing
- Adds the missing test snapshot that was not committed in the original
PR

Closes #60

## Test plan
- [x] Snapshot generated locally with `yarn test:update` in
`packages/@cdktn/provider-schema`
- [ ] CI unit tests pass with the new snapshot

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Josh Hook <joshhook@live.co.uk>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@so0k so0k closed this in #61 Mar 20, 2026
@so0k

so0k commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor

don't know why it says closed.. I rebased your branch through the GH UI - then branched off the rebase and kept the same commit sha - I never understand why GH UI doesn't show these as merged instead of closed :/

anyway - @josh-hook - we should have this in the next release - thanks for the fix

@github-actions

Copy link
Copy Markdown
Contributor

I'm going to lock this pull request because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cdktn-cli: 'get' subcommand fails when HCL has an in-line comment containing closing bracket

3 participants