github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_elastictranscoder_preset_invalid_container.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 "regexp" 8 9 hcl "github.com/hashicorp/hcl/v2" 10 "github.com/wata727/tflint/tflint" 11 ) 12 13 // AwsElastictranscoderPresetInvalidContainerRule checks the pattern is valid 14 type AwsElastictranscoderPresetInvalidContainerRule struct { 15 resourceType string 16 attributeName string 17 pattern *regexp.Regexp 18 } 19 20 // NewAwsElastictranscoderPresetInvalidContainerRule returns new rule with default attributes 21 func NewAwsElastictranscoderPresetInvalidContainerRule() *AwsElastictranscoderPresetInvalidContainerRule { 22 return &AwsElastictranscoderPresetInvalidContainerRule{ 23 resourceType: "aws_elastictranscoder_preset", 24 attributeName: "container", 25 pattern: regexp.MustCompile(`^(^mp4$)|(^ts$)|(^webm$)|(^mp3$)|(^flac$)|(^oga$)|(^ogg$)|(^fmp4$)|(^mpg$)|(^flv$)|(^gif$)|(^mxf$)|(^wav$)|(^mp2$)$`), 26 } 27 } 28 29 // Name returns the rule name 30 func (r *AwsElastictranscoderPresetInvalidContainerRule) Name() string { 31 return "aws_elastictranscoder_preset_invalid_container" 32 } 33 34 // Enabled returns whether the rule is enabled by default 35 func (r *AwsElastictranscoderPresetInvalidContainerRule) Enabled() bool { 36 return true 37 } 38 39 // Severity returns the rule severity 40 func (r *AwsElastictranscoderPresetInvalidContainerRule) Severity() string { 41 return tflint.ERROR 42 } 43 44 // Link returns the rule reference link 45 func (r *AwsElastictranscoderPresetInvalidContainerRule) Link() string { 46 return "" 47 } 48 49 // Check checks the pattern is valid 50 func (r *AwsElastictranscoderPresetInvalidContainerRule) Check(runner *tflint.Runner) error { 51 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 52 53 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 54 var val string 55 err := runner.EvaluateExpr(attribute.Expr, &val) 56 57 return runner.EnsureNoError(err, func() error { 58 if !r.pattern.MatchString(val) { 59 runner.EmitIssue( 60 r, 61 `container does not match valid pattern ^(^mp4$)|(^ts$)|(^webm$)|(^mp3$)|(^flac$)|(^oga$)|(^ogg$)|(^fmp4$)|(^mpg$)|(^flv$)|(^gif$)|(^mxf$)|(^wav$)|(^mp2$)$`, 62 attribute.Expr.Range(), 63 ) 64 } 65 return nil 66 }) 67 }) 68 }