github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_cur_report_definition_invalid_s3_region.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 // AwsCurReportDefinitionInvalidS3RegionRule checks the pattern is valid 13 type AwsCurReportDefinitionInvalidS3RegionRule struct { 14 resourceType string 15 attributeName string 16 enum []string 17 } 18 19 // NewAwsCurReportDefinitionInvalidS3RegionRule returns new rule with default attributes 20 func NewAwsCurReportDefinitionInvalidS3RegionRule() *AwsCurReportDefinitionInvalidS3RegionRule { 21 return &AwsCurReportDefinitionInvalidS3RegionRule{ 22 resourceType: "aws_cur_report_definition", 23 attributeName: "s3_region", 24 enum: []string{ 25 "us-east-1", 26 "us-west-1", 27 "us-west-2", 28 "eu-central-1", 29 "eu-west-1", 30 "ap-southeast-1", 31 "ap-southeast-2", 32 "ap-northeast-1", 33 "eu-north-1", 34 "ap-northeast-3", 35 "ap-east-1", 36 }, 37 } 38 } 39 40 // Name returns the rule name 41 func (r *AwsCurReportDefinitionInvalidS3RegionRule) Name() string { 42 return "aws_cur_report_definition_invalid_s3_region" 43 } 44 45 // Enabled returns whether the rule is enabled by default 46 func (r *AwsCurReportDefinitionInvalidS3RegionRule) Enabled() bool { 47 return true 48 } 49 50 // Severity returns the rule severity 51 func (r *AwsCurReportDefinitionInvalidS3RegionRule) Severity() string { 52 return tflint.ERROR 53 } 54 55 // Link returns the rule reference link 56 func (r *AwsCurReportDefinitionInvalidS3RegionRule) Link() string { 57 return "" 58 } 59 60 // Check checks the pattern is valid 61 func (r *AwsCurReportDefinitionInvalidS3RegionRule) Check(runner *tflint.Runner) error { 62 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 63 64 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 65 var val string 66 err := runner.EvaluateExpr(attribute.Expr, &val) 67 68 return runner.EnsureNoError(err, func() error { 69 found := false 70 for _, item := range r.enum { 71 if item == val { 72 found = true 73 } 74 } 75 if !found { 76 runner.EmitIssue( 77 r, 78 `s3_region is not a valid value`, 79 attribute.Expr.Range(), 80 ) 81 } 82 return nil 83 }) 84 }) 85 }