Exclude expression context from marked for_each
diagnostics
#2256
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thefor_each
is not iterable (it is not iterable if marked), a diagnostic containing the expression context of thefor_each
is created and written to stderr by theDiagnosticTextWriter
.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 blockstflint/terraform/tfhcl/expand_spec.go
Lines 48 to 49 in 0fd691f
tflint/terraform/tfhcl/expand_spec.go
Line 200 in 0fd691f
count
in meta-argumentstflint/terraform/tfhcl/expand_spec.go
Line 265 in 0fd691f