generated from terraform-linters/tflint-ruleset-template
/
ruleset.go
47 lines (39 loc) · 1.11 KB
/
ruleset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package aws
import (
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)
// RuleSet is the custom ruleset for the AWS provider plugin.
type RuleSet struct {
tflint.BuiltinRuleSet
config *Config
}
func (r *RuleSet) ConfigSchema() *hclext.BodySchema {
r.config = &Config{}
return hclext.ImpliedBodySchema(r.config)
}
// ApplyConfig reflects the plugin configuration to the ruleset.
func (r *RuleSet) ApplyConfig(body *hclext.BodyContent) error {
diags := hclext.DecodeBody(body, nil, r.config)
if diags.HasErrors() {
return diags
}
if r.config.DeepCheck {
return nil
}
// Disable deep checking rules
enabledRules := []tflint.Rule{}
for _, rule := range r.EnabledRules {
meta := rule.Metadata()
// Deep checking rules must have metadata like `map[string]bool{"deep": true}``
if meta == nil {
enabledRules = append(enabledRules, rule)
}
}
r.EnabledRules = enabledRules
return nil
}
// NewRunner injects a custom AWS runner
func (r *RuleSet) NewRunner(runner tflint.Runner) (tflint.Runner, error) {
return NewRunner(runner, r.config)
}