generated from terraform-linters/tflint-ruleset-template
-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathaws_elasticache_cluster_default_parameter_group.go
65 lines (54 loc) · 2.07 KB
/
aws_elasticache_cluster_default_parameter_group.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
package rules
import (
"fmt"
"regexp"
hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
"github.com/terraform-linters/tflint-ruleset-aws/project"
)
// AwsElastiCacheClusterDefaultParameterGroupRule checks whether the cluster use default parameter group
type AwsElastiCacheClusterDefaultParameterGroupRule struct {
resourceType string
attributeName string
}
// NewAwsElastiCacheClusterDefaultParameterGroupRule returns new rule with default attributes
func NewAwsElastiCacheClusterDefaultParameterGroupRule() *AwsElastiCacheClusterDefaultParameterGroupRule {
return &AwsElastiCacheClusterDefaultParameterGroupRule{
resourceType: "aws_elasticache_cluster",
attributeName: "parameter_group_name",
}
}
// Name returns the rule name
func (r *AwsElastiCacheClusterDefaultParameterGroupRule) Name() string {
return "aws_elasticache_cluster_default_parameter_group"
}
// Enabled returns whether the rule is enabled by default
func (r *AwsElastiCacheClusterDefaultParameterGroupRule) Enabled() bool {
return true
}
// Severity returns the rule severity
func (r *AwsElastiCacheClusterDefaultParameterGroupRule) Severity() string {
return tflint.NOTICE
}
// Link returns the rule reference link
func (r *AwsElastiCacheClusterDefaultParameterGroupRule) Link() string {
return project.ReferenceLink(r.Name())
}
var defaultElastiCacheParameterGroupRegexp = regexp.MustCompile("^default")
// Check checks the parameter group name starts with `default`
func (r *AwsElastiCacheClusterDefaultParameterGroupRule) Check(runner tflint.Runner) error {
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
var parameterGroup string
err := runner.EvaluateExpr(attribute.Expr, ¶meterGroup, nil)
return runner.EnsureNoError(err, func() error {
if defaultElastiCacheParameterGroupRegexp.Match([]byte(parameterGroup)) {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf("\"%s\" is default parameter group. You cannot edit it.", parameterGroup),
attribute.Expr,
)
}
return nil
})
})
}