Skip to content

7 files changed

+307
-0
lines changed

docs/rules/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ These rules enforce best practices and naming conventions:
570570
|aws_elastic_beanstalk_environment_invalid_template_name||
571571
|aws_elastic_beanstalk_environment_invalid_version_label||
572572
|aws_elasticache_cluster_invalid_az_mode||
573+
|aws_elasticache_user_group_invalid_engine||
574+
|aws_elasticache_user_invalid_access_string||
575+
|aws_elasticache_user_invalid_engine||
576+
|aws_elasticache_user_invalid_user_id||
573577
|aws_elasticsearch_domain_invalid_domain_name||
574578
|aws_elasticsearch_domain_invalid_elasticsearch_version||
575579
|aws_elasticsearch_domain_policy_invalid_domain_name||
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"fmt"
7+
"log"
8+
"regexp"
9+
10+
hcl "github.com/hashicorp/hcl/v2"
11+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
12+
)
13+
14+
// AwsElastiCacheUserGroupInvalidEngineRule checks the pattern is valid
15+
type AwsElastiCacheUserGroupInvalidEngineRule struct {
16+
resourceType string
17+
attributeName string
18+
pattern *regexp.Regexp
19+
}
20+
21+
// NewAwsElastiCacheUserGroupInvalidEngineRule returns new rule with default attributes
22+
func NewAwsElastiCacheUserGroupInvalidEngineRule() *AwsElastiCacheUserGroupInvalidEngineRule {
23+
return &AwsElastiCacheUserGroupInvalidEngineRule{
24+
resourceType: "aws_elasticache_user_group",
25+
attributeName: "engine",
26+
pattern: regexp.MustCompile(`^[a-zA-Z]*$`),
27+
}
28+
}
29+
30+
// Name returns the rule name
31+
func (r *AwsElastiCacheUserGroupInvalidEngineRule) Name() string {
32+
return "aws_elasticache_user_group_invalid_engine"
33+
}
34+
35+
// Enabled returns whether the rule is enabled by default
36+
func (r *AwsElastiCacheUserGroupInvalidEngineRule) Enabled() bool {
37+
return true
38+
}
39+
40+
// Severity returns the rule severity
41+
func (r *AwsElastiCacheUserGroupInvalidEngineRule) Severity() string {
42+
return tflint.ERROR
43+
}
44+
45+
// Link returns the rule reference link
46+
func (r *AwsElastiCacheUserGroupInvalidEngineRule) Link() string {
47+
return ""
48+
}
49+
50+
// Check checks the pattern is valid
51+
func (r *AwsElastiCacheUserGroupInvalidEngineRule) Check(runner tflint.Runner) error {
52+
log.Printf("[TRACE] Check `%s` rule", r.Name())
53+
54+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
55+
var val string
56+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
57+
58+
return runner.EnsureNoError(err, func() error {
59+
if !r.pattern.MatchString(val) {
60+
runner.EmitIssueOnExpr(
61+
r,
62+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z]*$`),
63+
attribute.Expr,
64+
)
65+
}
66+
return nil
67+
})
68+
})
69+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"fmt"
7+
"log"
8+
"regexp"
9+
10+
hcl "github.com/hashicorp/hcl/v2"
11+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
12+
)
13+
14+
// AwsElastiCacheUserInvalidAccessStringRule checks the pattern is valid
15+
type AwsElastiCacheUserInvalidAccessStringRule struct {
16+
resourceType string
17+
attributeName string
18+
pattern *regexp.Regexp
19+
}
20+
21+
// NewAwsElastiCacheUserInvalidAccessStringRule returns new rule with default attributes
22+
func NewAwsElastiCacheUserInvalidAccessStringRule() *AwsElastiCacheUserInvalidAccessStringRule {
23+
return &AwsElastiCacheUserInvalidAccessStringRule{
24+
resourceType: "aws_elasticache_user",
25+
attributeName: "access_string",
26+
pattern: regexp.MustCompile(`^.*\S.*$`),
27+
}
28+
}
29+
30+
// Name returns the rule name
31+
func (r *AwsElastiCacheUserInvalidAccessStringRule) Name() string {
32+
return "aws_elasticache_user_invalid_access_string"
33+
}
34+
35+
// Enabled returns whether the rule is enabled by default
36+
func (r *AwsElastiCacheUserInvalidAccessStringRule) Enabled() bool {
37+
return true
38+
}
39+
40+
// Severity returns the rule severity
41+
func (r *AwsElastiCacheUserInvalidAccessStringRule) Severity() string {
42+
return tflint.ERROR
43+
}
44+
45+
// Link returns the rule reference link
46+
func (r *AwsElastiCacheUserInvalidAccessStringRule) Link() string {
47+
return ""
48+
}
49+
50+
// Check checks the pattern is valid
51+
func (r *AwsElastiCacheUserInvalidAccessStringRule) Check(runner tflint.Runner) error {
52+
log.Printf("[TRACE] Check `%s` rule", r.Name())
53+
54+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
55+
var val string
56+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
57+
58+
return runner.EnsureNoError(err, func() error {
59+
if !r.pattern.MatchString(val) {
60+
runner.EmitIssueOnExpr(
61+
r,
62+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^.*\S.*$`),
63+
attribute.Expr,
64+
)
65+
}
66+
return nil
67+
})
68+
})
69+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"fmt"
7+
"log"
8+
"regexp"
9+
10+
hcl "github.com/hashicorp/hcl/v2"
11+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
12+
)
13+
14+
// AwsElastiCacheUserInvalidEngineRule checks the pattern is valid
15+
type AwsElastiCacheUserInvalidEngineRule struct {
16+
resourceType string
17+
attributeName string
18+
pattern *regexp.Regexp
19+
}
20+
21+
// NewAwsElastiCacheUserInvalidEngineRule returns new rule with default attributes
22+
func NewAwsElastiCacheUserInvalidEngineRule() *AwsElastiCacheUserInvalidEngineRule {
23+
return &AwsElastiCacheUserInvalidEngineRule{
24+
resourceType: "aws_elasticache_user",
25+
attributeName: "engine",
26+
pattern: regexp.MustCompile(`^[a-zA-Z]*$`),
27+
}
28+
}
29+
30+
// Name returns the rule name
31+
func (r *AwsElastiCacheUserInvalidEngineRule) Name() string {
32+
return "aws_elasticache_user_invalid_engine"
33+
}
34+
35+
// Enabled returns whether the rule is enabled by default
36+
func (r *AwsElastiCacheUserInvalidEngineRule) Enabled() bool {
37+
return true
38+
}
39+
40+
// Severity returns the rule severity
41+
func (r *AwsElastiCacheUserInvalidEngineRule) Severity() string {
42+
return tflint.ERROR
43+
}
44+
45+
// Link returns the rule reference link
46+
func (r *AwsElastiCacheUserInvalidEngineRule) Link() string {
47+
return ""
48+
}
49+
50+
// Check checks the pattern is valid
51+
func (r *AwsElastiCacheUserInvalidEngineRule) Check(runner tflint.Runner) error {
52+
log.Printf("[TRACE] Check `%s` rule", r.Name())
53+
54+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
55+
var val string
56+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
57+
58+
return runner.EnsureNoError(err, func() error {
59+
if !r.pattern.MatchString(val) {
60+
runner.EmitIssueOnExpr(
61+
r,
62+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z]*$`),
63+
attribute.Expr,
64+
)
65+
}
66+
return nil
67+
})
68+
})
69+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"fmt"
7+
"log"
8+
"regexp"
9+
10+
hcl "github.com/hashicorp/hcl/v2"
11+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
12+
)
13+
14+
// AwsElastiCacheUserInvalidUserIDRule checks the pattern is valid
15+
type AwsElastiCacheUserInvalidUserIDRule struct {
16+
resourceType string
17+
attributeName string
18+
min int
19+
pattern *regexp.Regexp
20+
}
21+
22+
// NewAwsElastiCacheUserInvalidUserIDRule returns new rule with default attributes
23+
func NewAwsElastiCacheUserInvalidUserIDRule() *AwsElastiCacheUserInvalidUserIDRule {
24+
return &AwsElastiCacheUserInvalidUserIDRule{
25+
resourceType: "aws_elasticache_user",
26+
attributeName: "user_id",
27+
min: 1,
28+
pattern: regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9\-]*$`),
29+
}
30+
}
31+
32+
// Name returns the rule name
33+
func (r *AwsElastiCacheUserInvalidUserIDRule) Name() string {
34+
return "aws_elasticache_user_invalid_user_id"
35+
}
36+
37+
// Enabled returns whether the rule is enabled by default
38+
func (r *AwsElastiCacheUserInvalidUserIDRule) Enabled() bool {
39+
return true
40+
}
41+
42+
// Severity returns the rule severity
43+
func (r *AwsElastiCacheUserInvalidUserIDRule) Severity() string {
44+
return tflint.ERROR
45+
}
46+
47+
// Link returns the rule reference link
48+
func (r *AwsElastiCacheUserInvalidUserIDRule) Link() string {
49+
return ""
50+
}
51+
52+
// Check checks the pattern is valid
53+
func (r *AwsElastiCacheUserInvalidUserIDRule) Check(runner tflint.Runner) error {
54+
log.Printf("[TRACE] Check `%s` rule", r.Name())
55+
56+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
57+
var val string
58+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
59+
60+
return runner.EnsureNoError(err, func() error {
61+
if len(val) < r.min {
62+
runner.EmitIssueOnExpr(
63+
r,
64+
"user_id must be 1 characters or higher",
65+
attribute.Expr,
66+
)
67+
}
68+
if !r.pattern.MatchString(val) {
69+
runner.EmitIssueOnExpr(
70+
r,
71+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z][a-zA-Z0-9\-]*$`),
72+
attribute.Expr,
73+
)
74+
}
75+
return nil
76+
})
77+
})
78+
}

rules/models/mappings/elasticache.hcl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ mapping "aws_elasticache_subnet_group" {
7272
subnet_ids = SubnetIdentifierList
7373
}
7474

75+
mapping "aws_elasticache_user" {
76+
access_string = AccessString
77+
engine = EngineType
78+
user_id = UserId
79+
user_name = UserName
80+
passwords = PasswordListInput
81+
tags = TagList
82+
}
83+
84+
mapping "aws_elasticache_user_group" {
85+
engine = EngineType
86+
user_ids = UserIdListInput
87+
}
88+
7589
test "aws_elasticache_cluster" "az_mode" {
7690
ok = "cross-az"
7791
ng = "multi-az"

rules/models/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ var Rules = []tflint.Rule{
498498
NewAwsElasticBeanstalkEnvironmentInvalidTemplateNameRule(),
499499
NewAwsElasticBeanstalkEnvironmentInvalidVersionLabelRule(),
500500
NewAwsElastiCacheClusterInvalidAzModeRule(),
501+
NewAwsElastiCacheUserGroupInvalidEngineRule(),
502+
NewAwsElastiCacheUserInvalidAccessStringRule(),
503+
NewAwsElastiCacheUserInvalidEngineRule(),
504+
NewAwsElastiCacheUserInvalidUserIDRule(),
501505
NewAwsElasticsearchDomainInvalidDomainNameRule(),
502506
NewAwsElasticsearchDomainInvalidElasticsearchVersionRule(),
503507
NewAwsElasticsearchDomainPolicyInvalidDomainNameRule(),

0 commit comments

Comments
 (0)