github.com/terraform-linters/tflint@v0.51.2-0.20240520175844-3750771571b6/plugin/stub-generator/sources/testing/rules/aws_iam_policy_example.go (about) 1 package rules 2 3 import ( 4 "fmt" 5 6 "github.com/terraform-linters/tflint-plugin-sdk/hclext" 7 "github.com/terraform-linters/tflint-plugin-sdk/tflint" 8 ) 9 10 // AwsIAMPolicyExampleRule checks whether ... 11 type AwsIAMPolicyExampleRule struct { 12 tflint.DefaultRule 13 } 14 15 // NewAwsIAMPolicyExampleRule returns a new rule 16 func NewAwsIAMPolicyExampleRule() *AwsIAMPolicyExampleRule { 17 return &AwsIAMPolicyExampleRule{} 18 } 19 20 // Name returns the rule name 21 func (r *AwsIAMPolicyExampleRule) Name() string { 22 return "aws_iam_policy_example" 23 } 24 25 // Enabled returns whether the rule is enabled by default 26 func (r *AwsIAMPolicyExampleRule) Enabled() bool { 27 return true 28 } 29 30 // Severity returns the rule severity 31 func (r *AwsIAMPolicyExampleRule) Severity() tflint.Severity { 32 return tflint.ERROR 33 } 34 35 // Link returns the rule reference link 36 func (r *AwsIAMPolicyExampleRule) Link() string { 37 return "" 38 } 39 40 // Check checks whether ... 41 func (r *AwsIAMPolicyExampleRule) Check(runner tflint.Runner) error { 42 resources, err := runner.GetResourceContent("aws_iam_policy", &hclext.BodySchema{ 43 Attributes: []hclext.AttributeSchema{{Name: "name"}}, 44 }, &tflint.GetModuleContentOption{ 45 ModuleCtx: tflint.SelfModuleCtxType, 46 ExpandMode: tflint.ExpandModeNone, 47 }) 48 if err != nil { 49 return err 50 } 51 52 for _, resource := range resources.Blocks { 53 attribute, exists := resource.Body.Attributes["name"] 54 if !exists { 55 continue 56 } 57 58 err := runner.EvaluateExpr(attribute.Expr, func(name string) error { 59 return runner.EmitIssue( 60 r, 61 fmt.Sprintf("name is %s", name), 62 attribute.Expr.Range(), 63 ) 64 }, nil) 65 if err != nil { 66 return err 67 } 68 } 69 70 return nil 71 }