github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/api/aws_launch_configuration_invalid_iam_profile.go (about) 1 // This file generated by `generator/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/terraform-linters/tflint/tflint" 11 ) 12 13 // AwsLaunchConfigurationInvalidIAMProfileRule checks whether attribute value actually exists 14 type AwsLaunchConfigurationInvalidIAMProfileRule struct { 15 resourceType string 16 attributeName string 17 data map[string]bool 18 dataPrepared bool 19 } 20 21 // NewAwsLaunchConfigurationInvalidIAMProfileRule returns new rule with default attributes 22 func NewAwsLaunchConfigurationInvalidIAMProfileRule() *AwsLaunchConfigurationInvalidIAMProfileRule { 23 return &AwsLaunchConfigurationInvalidIAMProfileRule{ 24 resourceType: "aws_launch_configuration", 25 attributeName: "iam_instance_profile", 26 data: map[string]bool{}, 27 dataPrepared: false, 28 } 29 } 30 31 // Name returns the rule name 32 func (r *AwsLaunchConfigurationInvalidIAMProfileRule) Name() string { 33 return "aws_launch_configuration_invalid_iam_profile" 34 } 35 36 // Enabled returns whether the rule is enabled by default 37 func (r *AwsLaunchConfigurationInvalidIAMProfileRule) Enabled() bool { 38 return true 39 } 40 41 // Severity returns the rule severity 42 func (r *AwsLaunchConfigurationInvalidIAMProfileRule) Severity() string { 43 return tflint.ERROR 44 } 45 46 // Link returns the rule reference link 47 func (r *AwsLaunchConfigurationInvalidIAMProfileRule) Link() string { 48 return "" 49 } 50 51 // Check checks whether the attributes are included in the list retrieved by ListInstanceProfiles 52 func (r *AwsLaunchConfigurationInvalidIAMProfileRule) 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 ListInstanceProfiles") 58 var err error 59 r.data, err = runner.AwsClient.ListInstanceProfiles() 60 if err != nil { 61 err := &tflint.Error{ 62 Code: tflint.ExternalAPIError, 63 Level: tflint.ErrorLevel, 64 Message: "An error occurred while invoking ListInstanceProfiles", 65 Cause: err, 66 } 67 log.Printf("[ERROR] %s", err) 68 return err 69 } 70 r.dataPrepared = true 71 } 72 73 var val string 74 err := runner.EvaluateExpr(attribute.Expr, &val) 75 76 return runner.EnsureNoError(err, func() error { 77 if !r.data[val] { 78 runner.EmitIssue( 79 r, 80 fmt.Sprintf(`"%s" is invalid IAM profile name.`, val), 81 attribute.Expr.Range(), 82 ) 83 } 84 return nil 85 }) 86 }) 87 }