github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/api/aws_elb_invalid_subnet.go (about) 1 // This file generated by `tools/api-rule-gen/main.go`. DO NOT EDIT 2 3 package api 4 5 import ( 6 "fmt" 7 "log" 8 9 hcl "github.com/hashicorp/hcl/v2" 10 "github.com/wata727/tflint/tflint" 11 ) 12 13 // AwsELBInvalidSubnetRule checks whether attribute value actually exists 14 type AwsELBInvalidSubnetRule struct { 15 resourceType string 16 attributeName string 17 data map[string]bool 18 dataPrepared bool 19 } 20 21 // NewAwsELBInvalidSubnetRule returns new rule with default attributes 22 func NewAwsELBInvalidSubnetRule() *AwsELBInvalidSubnetRule { 23 return &AwsELBInvalidSubnetRule{ 24 resourceType: "aws_elb", 25 attributeName: "subnets", 26 data: map[string]bool{}, 27 dataPrepared: false, 28 } 29 } 30 31 // Name returns the rule name 32 func (r *AwsELBInvalidSubnetRule) Name() string { 33 return "aws_elb_invalid_subnet" 34 } 35 36 // Enabled returns whether the rule is enabled by default 37 func (r *AwsELBInvalidSubnetRule) Enabled() bool { 38 return true 39 } 40 41 // Severity returns the rule severity 42 func (r *AwsELBInvalidSubnetRule) Severity() string { 43 return tflint.ERROR 44 } 45 46 // Link returns the rule reference link 47 func (r *AwsELBInvalidSubnetRule) Link() string { 48 return "" 49 } 50 51 // Check checks whether the attributes are included in the list retrieved by DescribeSubnets 52 func (r *AwsELBInvalidSubnetRule) Check(runner *tflint.Runner) error { 53 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 54 55 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 56 if !r.dataPrepared { 57 log.Print("[DEBUG] invoking DescribeSubnets") 58 var err error 59 r.data, err = runner.AwsClient.DescribeSubnets() 60 if err != nil { 61 err := &tflint.Error{ 62 Code: tflint.ExternalAPIError, 63 Level: tflint.ErrorLevel, 64 Message: "An error occurred while invoking DescribeSubnets", 65 Cause: err, 66 } 67 log.Printf("[ERROR] %s", err) 68 return err 69 } 70 r.dataPrepared = true 71 } 72 73 return runner.EachStringSliceExprs(attribute.Expr, func(val string, expr hcl.Expression) { 74 if !r.data[val] { 75 runner.EmitIssue( 76 r, 77 fmt.Sprintf(`"%s" is invalid subnet ID.`, val), 78 expr.Range(), 79 ) 80 } 81 }) 82 }) 83 }