github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/aws_s3_bucket_object_invalid_acl.go (about) 1 // This file generated by `generator/`. DO NOT EDIT 2 3 package models 4 5 import ( 6 "fmt" 7 "log" 8 9 hcl "github.com/hashicorp/hcl/v2" 10 "github.com/terraform-linters/tflint/tflint" 11 ) 12 13 // AwsS3BucketObjectInvalidACLRule checks the pattern is valid 14 type AwsS3BucketObjectInvalidACLRule struct { 15 resourceType string 16 attributeName string 17 enum []string 18 } 19 20 // NewAwsS3BucketObjectInvalidACLRule returns new rule with default attributes 21 func NewAwsS3BucketObjectInvalidACLRule() *AwsS3BucketObjectInvalidACLRule { 22 return &AwsS3BucketObjectInvalidACLRule{ 23 resourceType: "aws_s3_bucket_object", 24 attributeName: "acl", 25 enum: []string{ 26 "private", 27 "public-read", 28 "public-read-write", 29 "authenticated-read", 30 "aws-exec-read", 31 "bucket-owner-read", 32 "bucket-owner-full-control", 33 }, 34 } 35 } 36 37 // Name returns the rule name 38 func (r *AwsS3BucketObjectInvalidACLRule) Name() string { 39 return "aws_s3_bucket_object_invalid_acl" 40 } 41 42 // Enabled returns whether the rule is enabled by default 43 func (r *AwsS3BucketObjectInvalidACLRule) Enabled() bool { 44 return true 45 } 46 47 // Severity returns the rule severity 48 func (r *AwsS3BucketObjectInvalidACLRule) Severity() string { 49 return tflint.ERROR 50 } 51 52 // Link returns the rule reference link 53 func (r *AwsS3BucketObjectInvalidACLRule) Link() string { 54 return "" 55 } 56 57 // Check checks the pattern is valid 58 func (r *AwsS3BucketObjectInvalidACLRule) Check(runner *tflint.Runner) error { 59 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 60 61 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 62 var val string 63 err := runner.EvaluateExpr(attribute.Expr, &val) 64 65 return runner.EnsureNoError(err, func() error { 66 found := false 67 for _, item := range r.enum { 68 if item == val { 69 found = true 70 } 71 } 72 if !found { 73 runner.EmitIssue( 74 r, 75 fmt.Sprintf(`"%s" is an invalid value as acl`, truncateLongMessage(val)), 76 attribute.Expr.Range(), 77 ) 78 } 79 return nil 80 }) 81 }) 82 }