github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_s3_bucket_object_invalid_storage_class.go (about) 1 // This file generated by `tools/model-rule-gen/main.go`. DO NOT EDIT 2 3 package models 4 5 import ( 6 "log" 7 8 hcl "github.com/hashicorp/hcl/v2" 9 "github.com/wata727/tflint/tflint" 10 ) 11 12 // AwsS3BucketObjectInvalidStorageClassRule checks the pattern is valid 13 type AwsS3BucketObjectInvalidStorageClassRule struct { 14 resourceType string 15 attributeName string 16 enum []string 17 } 18 19 // NewAwsS3BucketObjectInvalidStorageClassRule returns new rule with default attributes 20 func NewAwsS3BucketObjectInvalidStorageClassRule() *AwsS3BucketObjectInvalidStorageClassRule { 21 return &AwsS3BucketObjectInvalidStorageClassRule{ 22 resourceType: "aws_s3_bucket_object", 23 attributeName: "storage_class", 24 enum: []string{ 25 "STANDARD", 26 "REDUCED_REDUNDANCY", 27 "STANDARD_IA", 28 "ONEZONE_IA", 29 "INTELLIGENT_TIERING", 30 "GLACIER", 31 "DEEP_ARCHIVE", 32 }, 33 } 34 } 35 36 // Name returns the rule name 37 func (r *AwsS3BucketObjectInvalidStorageClassRule) Name() string { 38 return "aws_s3_bucket_object_invalid_storage_class" 39 } 40 41 // Enabled returns whether the rule is enabled by default 42 func (r *AwsS3BucketObjectInvalidStorageClassRule) Enabled() bool { 43 return true 44 } 45 46 // Severity returns the rule severity 47 func (r *AwsS3BucketObjectInvalidStorageClassRule) Severity() string { 48 return tflint.ERROR 49 } 50 51 // Link returns the rule reference link 52 func (r *AwsS3BucketObjectInvalidStorageClassRule) Link() string { 53 return "" 54 } 55 56 // Check checks the pattern is valid 57 func (r *AwsS3BucketObjectInvalidStorageClassRule) Check(runner *tflint.Runner) error { 58 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 59 60 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 61 var val string 62 err := runner.EvaluateExpr(attribute.Expr, &val) 63 64 return runner.EnsureNoError(err, func() error { 65 found := false 66 for _, item := range r.enum { 67 if item == val { 68 found = true 69 } 70 } 71 if !found { 72 runner.EmitIssue( 73 r, 74 `storage_class is not a valid value`, 75 attribute.Expr.Range(), 76 ) 77 } 78 return nil 79 }) 80 }) 81 }