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

terraform_required_version: fix regression with multiple blocks #1452

Merged
merged 2 commits into from Jul 27, 2022

Conversation

bendrucker
Copy link
Member

Fixes a regression where multiple terraform {} blocks results in a false positive issue being emitted. https://github.com/terraform-linters/tflint/pull/1433/files#diff-0ec954b5c7913111444d96417f3325c4a2f5d91507770a89022bcbd4b05319cb, which rewrote chunks of the terraformrules package to eliminate dependencies on Terraform internals, introduced this regression. The new code, which operates on the generic HCL structure rather than the parsed Terraform internal representation has a simple logic error:

for _, block := range body.Blocks {
	if _, exists := block.Body.Attributes["required_version"]; !exists {

This processes every terraform block and emits and error if required_version is unset. Instead, the rule should process all the blocks and emit a single error if none has the attribute set.

Fixes #1451

@bendrucker bendrucker merged commit 10be233 into master Jul 27, 2022
@bendrucker bendrucker deleted the issues/1451 branch July 27, 2022 23:28
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.

terraform_required_version: false positive with multiple terraform blocks
1 participant