github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/plugin/stub-generator/sources/example/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 hcl "github.com/hashicorp/hcl/v2" 7 "github.com/terraform-linters/tflint-plugin-sdk/plugin" 8 "github.com/terraform-linters/tflint-plugin-sdk/tflint" 9 ) 10 11 func main() { 12 plugin.Serve(&plugin.ServeOpts{ 13 RuleSet: tflint.RuleSet{ 14 Name: "example", 15 Version: "0.1.0", 16 Rules: []tflint.Rule{ 17 NewAwsInstanceExampleTypeRule(), 18 }, 19 }, 20 }) 21 } 22 23 // AwsInstanceExampleTypeRule checks whether ... 24 type AwsInstanceExampleTypeRule struct{} 25 26 // NewAwsInstanceExampleTypeRule returns a new rule 27 func NewAwsInstanceExampleTypeRule() *AwsInstanceExampleTypeRule { 28 return &AwsInstanceExampleTypeRule{} 29 } 30 31 // Name returns the rule name 32 func (r *AwsInstanceExampleTypeRule) Name() string { 33 return "aws_instance_example_type" 34 } 35 36 // Enabled returns whether the rule is enabled by default 37 func (r *AwsInstanceExampleTypeRule) Enabled() bool { 38 return true 39 } 40 41 // Severity returns the rule severity 42 func (r *AwsInstanceExampleTypeRule) Severity() string { 43 return tflint.ERROR 44 } 45 46 // Link returns the rule reference link 47 func (r *AwsInstanceExampleTypeRule) Link() string { 48 return "" 49 } 50 51 // Check checks whether ... 52 func (r *AwsInstanceExampleTypeRule) Check(runner tflint.Runner) error { 53 return runner.WalkResourceAttributes("aws_instance", "instance_type", func(attribute *hcl.Attribute) error { 54 var instanceType string 55 err := runner.EvaluateExpr(attribute.Expr, &instanceType) 56 57 return runner.EnsureNoError(err, func() error { 58 return runner.EmitIssueOnExpr( 59 r, 60 fmt.Sprintf("instance type is %s", instanceType), 61 attribute.Expr, 62 ) 63 }) 64 }) 65 }