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

Fix panic when the expression includes invalid references #443

Merged
merged 1 commit into from Sep 18, 2019

Conversation

wata727
Copy link
Member

@wata727 wata727 commented Sep 17, 2019

If an expression includes invalid references, panic and exit instead of returning an error. The following configuration is an example:

resource "aws_s3_bucket" "example" {
  bucket = "example"
  acl    = "private"
  region = invalid // invalid reference
}

Before

Panic: Invalid reference: A reference to a resource type must be followed by at least one attribute access, specifying the resource name.
 -> 0: main.main.func1: /main.go(30)
 -> 1: runtime.gopanic: /panic.go(679)
 -> 2: github.com/wata727/tflint/tflint.isEvaluableExpr: /runner.go(677)
 -> 3: github.com/wata727/tflint/tflint.(*Runner).EvaluateExpr: /runner.go(207)
 -> 4: github.com/wata727/tflint/rules/awsrules.(*AwsS3BucketInvalidRegionRule).Check.func1: /aws_s3_bucket_invalid_region.go(75)
 -> 5: github.com/wata727/tflint/tflint.(*Runner).WalkResourceAttributes: /runner.go(471)
 -> 6: github.com/wata727/tflint/rules/awsrules.(*AwsS3BucketInvalidRegionRule).Check: /aws_s3_bucket_invalid_region.go(73)
 -> 7: github.com/wata727/tflint/cmd.(*CLI).Run: /cli.go(152)
 -> 8: main.main: /main.go(43)
 -> 9: runtime.main: /proc.go(203)
 -> 10: runtime.goexit: /asm_amd64.s(1357)

TFLint crashed... :(
Please attach an output log, describe the situation and version that occurred and post an issue to https://github.com/wata727/tflint/issues

After

Failed to check `aws_s3_bucket_invalid_region` rule. An error occurred:

Error: Failed to parse an expression in s3.tf:4; Invalid reference: A reference to a resource type must be followed by at least one attribute access, specifying the reso
urce name.

key = invalid
}`,
Expected: false,
Error: errors.New("Invalid reference: A reference to a resource type must be followed by at least one attribute access, specifying the resource name."),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Golint] error strings should not be capitalized or end with punctuation or a newline (link)

Since this error is returned from Terraform, there is nothing we can do here.

@wata727 wata727 merged commit d6d47e7 into master Sep 18, 2019
@wata727 wata727 deleted the handle_invalid_references branch September 18, 2019 13:45
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.

None yet

1 participant