github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/aws_appautoscaling_target_invalid_service_namespace.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 // AwsAppautoscalingTargetInvalidServiceNamespaceRule checks the pattern is valid 14 type AwsAppautoscalingTargetInvalidServiceNamespaceRule struct { 15 resourceType string 16 attributeName string 17 enum []string 18 } 19 20 // NewAwsAppautoscalingTargetInvalidServiceNamespaceRule returns new rule with default attributes 21 func NewAwsAppautoscalingTargetInvalidServiceNamespaceRule() *AwsAppautoscalingTargetInvalidServiceNamespaceRule { 22 return &AwsAppautoscalingTargetInvalidServiceNamespaceRule{ 23 resourceType: "aws_appautoscaling_target", 24 attributeName: "service_namespace", 25 enum: []string{ 26 "ecs", 27 "elasticmapreduce", 28 "ec2", 29 "appstream", 30 "dynamodb", 31 "rds", 32 "sagemaker", 33 "custom-resource", 34 "comprehend", 35 "lambda", 36 "cassandra", 37 }, 38 } 39 } 40 41 // Name returns the rule name 42 func (r *AwsAppautoscalingTargetInvalidServiceNamespaceRule) Name() string { 43 return "aws_appautoscaling_target_invalid_service_namespace" 44 } 45 46 // Enabled returns whether the rule is enabled by default 47 func (r *AwsAppautoscalingTargetInvalidServiceNamespaceRule) Enabled() bool { 48 return true 49 } 50 51 // Severity returns the rule severity 52 func (r *AwsAppautoscalingTargetInvalidServiceNamespaceRule) Severity() string { 53 return tflint.ERROR 54 } 55 56 // Link returns the rule reference link 57 func (r *AwsAppautoscalingTargetInvalidServiceNamespaceRule) Link() string { 58 return "" 59 } 60 61 // Check checks the pattern is valid 62 func (r *AwsAppautoscalingTargetInvalidServiceNamespaceRule) Check(runner *tflint.Runner) error { 63 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 64 65 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 66 var val string 67 err := runner.EvaluateExpr(attribute.Expr, &val) 68 69 return runner.EnsureNoError(err, func() error { 70 found := false 71 for _, item := range r.enum { 72 if item == val { 73 found = true 74 } 75 } 76 if !found { 77 runner.EmitIssue( 78 r, 79 fmt.Sprintf(`"%s" is an invalid value as service_namespace`, truncateLongMessage(val)), 80 attribute.Expr.Range(), 81 ) 82 } 83 return nil 84 }) 85 }) 86 }