github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_ec2_capacity_reservation_invalid_instance_platform.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 // AwsEc2CapacityReservationInvalidInstancePlatformRule checks the pattern is valid 13 type AwsEc2CapacityReservationInvalidInstancePlatformRule struct { 14 resourceType string 15 attributeName string 16 enum []string 17 } 18 19 // NewAwsEc2CapacityReservationInvalidInstancePlatformRule returns new rule with default attributes 20 func NewAwsEc2CapacityReservationInvalidInstancePlatformRule() *AwsEc2CapacityReservationInvalidInstancePlatformRule { 21 return &AwsEc2CapacityReservationInvalidInstancePlatformRule{ 22 resourceType: "aws_ec2_capacity_reservation", 23 attributeName: "instance_platform", 24 enum: []string{ 25 "Linux/UNIX", 26 "Red Hat Enterprise Linux", 27 "SUSE Linux", 28 "Windows", 29 "Windows with SQL Server", 30 "Windows with SQL Server Enterprise", 31 "Windows with SQL Server Standard", 32 "Windows with SQL Server Web", 33 "Linux with SQL Server Standard", 34 "Linux with SQL Server Web", 35 "Linux with SQL Server Enterprise", 36 }, 37 } 38 } 39 40 // Name returns the rule name 41 func (r *AwsEc2CapacityReservationInvalidInstancePlatformRule) Name() string { 42 return "aws_ec2_capacity_reservation_invalid_instance_platform" 43 } 44 45 // Enabled returns whether the rule is enabled by default 46 func (r *AwsEc2CapacityReservationInvalidInstancePlatformRule) Enabled() bool { 47 return true 48 } 49 50 // Severity returns the rule severity 51 func (r *AwsEc2CapacityReservationInvalidInstancePlatformRule) Severity() string { 52 return tflint.ERROR 53 } 54 55 // Link returns the rule reference link 56 func (r *AwsEc2CapacityReservationInvalidInstancePlatformRule) Link() string { 57 return "" 58 } 59 60 // Check checks the pattern is valid 61 func (r *AwsEc2CapacityReservationInvalidInstancePlatformRule) 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 `instance_platform is not a valid value`, 79 attribute.Expr.Range(), 80 ) 81 } 82 return nil 83 }) 84 }) 85 }