-
Notifications
You must be signed in to change notification settings - Fork 349
/
runner.go
78 lines (70 loc) · 1.66 KB
/
runner.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package custom
import (
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)
type Runner struct {
tflint.Runner
CustomConfig *Config
}
func NewRunner(runner tflint.Runner, config *Config) (*Runner, error) {
providers, err := runner.GetModuleContent(
&hclext.BodySchema{
Blocks: []hclext.BlockSchema{
{
Type: "provider",
LabelNames: []string{"name"},
Body: &hclext.BodySchema{
Attributes: []hclext.AttributeSchema{
{Name: "zone"},
},
Blocks: []hclext.BlockSchema{
{
Type: "annotation",
Body: &hclext.BodySchema{
Attributes: []hclext.AttributeSchema{
{Name: "value"},
},
},
},
},
},
},
},
},
&tflint.GetModuleContentOption{ModuleCtx: tflint.RootModuleCtxType},
)
if err != nil {
return nil, err
}
for _, provider := range providers.Blocks {
if provider.Labels[0] != "custom" {
continue
}
opts := &tflint.EvaluateExprOption{ModuleCtx: tflint.RootModuleCtxType}
if attr, exists := provider.Body.Attributes["zone"]; exists {
err := runner.EvaluateExpr(attr.Expr, func(zone string) error {
config.Zone = zone
return nil
}, opts)
if err != nil {
return nil, err
}
}
for _, annotation := range provider.Body.Blocks {
if attr, exists := annotation.Body.Attributes["value"]; exists {
err := runner.EvaluateExpr(attr.Expr, func(val string) error {
config.Annotation = val
return nil
}, opts)
if err != nil {
return nil, err
}
}
}
}
return &Runner{
Runner: runner,
CustomConfig: config,
}, nil
}