Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude expression context from marked for_each diagnostics #2256

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wata727
Copy link
Member

@wata727 wata727 commented Mar 7, 2025

Fixes #2243
See also hashicorp/hcl#737

The hcl.DiagnosticTextWriter has an issue where it will panic when writing out a diagnostic that has an expression containing a marked value.

TFLint can run into this issue when expanding the for_each meta-argument with a sensitive value. If the for_each is not iterable (it is not iterable if marked), a diagnostic containing the expression context of the for_each is created and written to stderr by the DiagnosticTextWriter.

Hopefully this will be fixed in upstream, but here's a workaround to prevent the panic by excluding expression context from the diagnostic when the for_each is marked.

By the way, other cases that include expression context in diagnostics do not have the same issue, so no action is required.

Fixes #2243
See also hashicorp/hcl#737

The `hcl.DiagnosticTextWriter` has an issue where it will panic
when writing out a diagnostic that has an expression containing
a marked value.

TFLint can run into this issue when expanding the `for_each`
meta-argument with a sensitive value. If the `for_each` is not
iterable (it is not iterable if marked), a diagnostic containing
the expression context of the `for_each` is created and written
to stderr by the `DiagnosticTextWriter`.

Hopefully this will be fixed in upstream, but here's a workaround
to prevent the panic by excluding expression context from the
diagnostic when the `for_each` is marked.

By the way, other cases that include expression context in
diagnostics do not have the same issue, so no action is required.

- `for_each` is marked in dynamic blocks
  - The value is always unmarked, and non-iterable cases are rarer than those in meta-arguments
- dynamic block labels
  - Dynamic block labels are rarely used in Terraform
- `count` in meta-arguments
  - The value is always unmarked
@wata727 wata727 force-pushed the exclude_marked_expr_context_from_diags branch from 155f764 to 0fd691f Compare March 10, 2025 07:00
@wata727 wata727 changed the title Exclude expr context from marked for_each diags Exclude expression context from marked for_each diagnostics Mar 10, 2025
@wata727 wata727 marked this pull request as ready for review March 10, 2025 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Panic on invalid for_each with sensitive variable references
2 participants