generated from terraform-linters/tflint-ruleset-template
-
Notifications
You must be signed in to change notification settings - Fork 24
/
azurerm_route_invalid_next_hop_type.go
78 lines (67 loc) · 2 KB
/
azurerm_route_invalid_next_hop_type.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
// This file generated by `tools/apispec-rule-gen/main.go`. DO NOT EDIT
package apispec
import (
"fmt"
hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
"github.com/terraform-linters/tflint-ruleset-azurerm/project"
)
// AzurermRouteInvalidNextHopTypeRule checks the pattern is valid
type AzurermRouteInvalidNextHopTypeRule struct {
resourceType string
attributeName string
enum []string
}
// NewAzurermRouteInvalidNextHopTypeRule returns new rule with default attributes
func NewAzurermRouteInvalidNextHopTypeRule() *AzurermRouteInvalidNextHopTypeRule {
return &AzurermRouteInvalidNextHopTypeRule{
resourceType: "azurerm_route",
attributeName: "next_hop_type",
enum: []string{
"VirtualNetworkGateway",
"VnetLocal",
"Internet",
"VirtualAppliance",
"None",
},
}
}
// Name returns the rule name
func (r *AzurermRouteInvalidNextHopTypeRule) Name() string {
return "azurerm_route_invalid_next_hop_type"
}
// Enabled returns whether the rule is enabled by default
func (r *AzurermRouteInvalidNextHopTypeRule) Enabled() bool {
return true
}
// Severity returns the rule severity
func (r *AzurermRouteInvalidNextHopTypeRule) Severity() string {
return tflint.ERROR
}
// Link returns the rule reference link
func (r *AzurermRouteInvalidNextHopTypeRule) Link() string {
return project.ReferenceLink(r.Name())
}
// Check checks the pattern is valid
func (r *AzurermRouteInvalidNextHopTypeRule) Check(runner tflint.Runner) error {
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
var val string
err := runner.EvaluateExpr(attribute.Expr, &val)
return runner.EnsureNoError(err, func() error {
found := false
for _, item := range r.enum {
if item == val {
found = true
}
}
if !found {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" is an invalid value as next_hop_type`, truncateLongMessage(val)),
attribute.Expr,
)
}
return nil
})
})
}