Skip to content

7 files changed

+353
-0
lines changed

docs/rules/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@ These rules enforce best practices and naming conventions:
455455
|aws_datasync_task_invalid_destination_location_arn||
456456
|aws_datasync_task_invalid_name||
457457
|aws_datasync_task_invalid_source_location_arn||
458+
|aws_db_proxy_endpoint_invalid_db_proxy_endpoint_name||
459+
|aws_db_proxy_endpoint_invalid_db_proxy_name||
460+
|aws_db_proxy_endpoint_invalid_target_role||
461+
|aws_db_proxy_invalid_engine_family||
458462
|aws_devicefarm_project_invalid_name||
459463
|aws_directory_service_conditional_forwarder_invalid_directory_id||
460464
|aws_directory_service_conditional_forwarder_invalid_remote_domain_name||
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
// AwsDBProxyEndpointInvalidDBProxyEndpointNameRule checks the pattern is valid
15+
type AwsDBProxyEndpointInvalidDBProxyEndpointNameRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
min int
20+
pattern *regexp.Regexp
21+
}
22+
23+
// NewAwsDBProxyEndpointInvalidDBProxyEndpointNameRule returns new rule with default attributes
24+
func NewAwsDBProxyEndpointInvalidDBProxyEndpointNameRule() *AwsDBProxyEndpointInvalidDBProxyEndpointNameRule {
25+
return &AwsDBProxyEndpointInvalidDBProxyEndpointNameRule{
26+
resourceType: "aws_db_proxy_endpoint",
27+
attributeName: "db_proxy_endpoint_name",
28+
max: 63,
29+
min: 1,
30+
pattern: regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*$`),
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsDBProxyEndpointInvalidDBProxyEndpointNameRule) Name() string {
36+
return "aws_db_proxy_endpoint_invalid_db_proxy_endpoint_name"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsDBProxyEndpointInvalidDBProxyEndpointNameRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsDBProxyEndpointInvalidDBProxyEndpointNameRule) Severity() string {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsDBProxyEndpointInvalidDBProxyEndpointNameRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsDBProxyEndpointInvalidDBProxyEndpointNameRule) Check(runner tflint.Runner) error {
56+
log.Printf("[TRACE] Check `%s` rule", r.Name())
57+
58+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
59+
var val string
60+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
61+
62+
return runner.EnsureNoError(err, func() error {
63+
if len(val) > r.max {
64+
runner.EmitIssueOnExpr(
65+
r,
66+
"db_proxy_endpoint_name must be 63 characters or less",
67+
attribute.Expr,
68+
)
69+
}
70+
if len(val) < r.min {
71+
runner.EmitIssueOnExpr(
72+
r,
73+
"db_proxy_endpoint_name must be 1 characters or higher",
74+
attribute.Expr,
75+
)
76+
}
77+
if !r.pattern.MatchString(val) {
78+
runner.EmitIssueOnExpr(
79+
r,
80+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*$`),
81+
attribute.Expr,
82+
)
83+
}
84+
return nil
85+
})
86+
})
87+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
// AwsDBProxyEndpointInvalidDBProxyNameRule checks the pattern is valid
15+
type AwsDBProxyEndpointInvalidDBProxyNameRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
min int
20+
pattern *regexp.Regexp
21+
}
22+
23+
// NewAwsDBProxyEndpointInvalidDBProxyNameRule returns new rule with default attributes
24+
func NewAwsDBProxyEndpointInvalidDBProxyNameRule() *AwsDBProxyEndpointInvalidDBProxyNameRule {
25+
return &AwsDBProxyEndpointInvalidDBProxyNameRule{
26+
resourceType: "aws_db_proxy_endpoint",
27+
attributeName: "db_proxy_name",
28+
max: 63,
29+
min: 1,
30+
pattern: regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*$`),
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsDBProxyEndpointInvalidDBProxyNameRule) Name() string {
36+
return "aws_db_proxy_endpoint_invalid_db_proxy_name"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsDBProxyEndpointInvalidDBProxyNameRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsDBProxyEndpointInvalidDBProxyNameRule) Severity() string {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsDBProxyEndpointInvalidDBProxyNameRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsDBProxyEndpointInvalidDBProxyNameRule) Check(runner tflint.Runner) error {
56+
log.Printf("[TRACE] Check `%s` rule", r.Name())
57+
58+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
59+
var val string
60+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
61+
62+
return runner.EnsureNoError(err, func() error {
63+
if len(val) > r.max {
64+
runner.EmitIssueOnExpr(
65+
r,
66+
"db_proxy_name must be 63 characters or less",
67+
attribute.Expr,
68+
)
69+
}
70+
if len(val) < r.min {
71+
runner.EmitIssueOnExpr(
72+
r,
73+
"db_proxy_name must be 1 characters or higher",
74+
attribute.Expr,
75+
)
76+
}
77+
if !r.pattern.MatchString(val) {
78+
runner.EmitIssueOnExpr(
79+
r,
80+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*$`),
81+
attribute.Expr,
82+
)
83+
}
84+
return nil
85+
})
86+
})
87+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"fmt"
7+
"log"
8+
9+
hcl "github.com/hashicorp/hcl/v2"
10+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
11+
)
12+
13+
// AwsDBProxyEndpointInvalidTargetRoleRule checks the pattern is valid
14+
type AwsDBProxyEndpointInvalidTargetRoleRule struct {
15+
resourceType string
16+
attributeName string
17+
enum []string
18+
}
19+
20+
// NewAwsDBProxyEndpointInvalidTargetRoleRule returns new rule with default attributes
21+
func NewAwsDBProxyEndpointInvalidTargetRoleRule() *AwsDBProxyEndpointInvalidTargetRoleRule {
22+
return &AwsDBProxyEndpointInvalidTargetRoleRule{
23+
resourceType: "aws_db_proxy_endpoint",
24+
attributeName: "target_role",
25+
enum: []string{
26+
"READ_WRITE",
27+
"READ_ONLY",
28+
},
29+
}
30+
}
31+
32+
// Name returns the rule name
33+
func (r *AwsDBProxyEndpointInvalidTargetRoleRule) Name() string {
34+
return "aws_db_proxy_endpoint_invalid_target_role"
35+
}
36+
37+
// Enabled returns whether the rule is enabled by default
38+
func (r *AwsDBProxyEndpointInvalidTargetRoleRule) Enabled() bool {
39+
return true
40+
}
41+
42+
// Severity returns the rule severity
43+
func (r *AwsDBProxyEndpointInvalidTargetRoleRule) Severity() string {
44+
return tflint.ERROR
45+
}
46+
47+
// Link returns the rule reference link
48+
func (r *AwsDBProxyEndpointInvalidTargetRoleRule) Link() string {
49+
return ""
50+
}
51+
52+
// Check checks the pattern is valid
53+
func (r *AwsDBProxyEndpointInvalidTargetRoleRule) 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+
found := false
62+
for _, item := range r.enum {
63+
if item == val {
64+
found = true
65+
}
66+
}
67+
if !found {
68+
runner.EmitIssueOnExpr(
69+
r,
70+
fmt.Sprintf(`"%s" is an invalid value as target_role`, truncateLongMessage(val)),
71+
attribute.Expr,
72+
)
73+
}
74+
return nil
75+
})
76+
})
77+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"fmt"
7+
"log"
8+
9+
hcl "github.com/hashicorp/hcl/v2"
10+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
11+
)
12+
13+
// AwsDBProxyInvalidEngineFamilyRule checks the pattern is valid
14+
type AwsDBProxyInvalidEngineFamilyRule struct {
15+
resourceType string
16+
attributeName string
17+
enum []string
18+
}
19+
20+
// NewAwsDBProxyInvalidEngineFamilyRule returns new rule with default attributes
21+
func NewAwsDBProxyInvalidEngineFamilyRule() *AwsDBProxyInvalidEngineFamilyRule {
22+
return &AwsDBProxyInvalidEngineFamilyRule{
23+
resourceType: "aws_db_proxy",
24+
attributeName: "engine_family",
25+
enum: []string{
26+
"MYSQL",
27+
"POSTGRESQL",
28+
},
29+
}
30+
}
31+
32+
// Name returns the rule name
33+
func (r *AwsDBProxyInvalidEngineFamilyRule) Name() string {
34+
return "aws_db_proxy_invalid_engine_family"
35+
}
36+
37+
// Enabled returns whether the rule is enabled by default
38+
func (r *AwsDBProxyInvalidEngineFamilyRule) Enabled() bool {
39+
return true
40+
}
41+
42+
// Severity returns the rule severity
43+
func (r *AwsDBProxyInvalidEngineFamilyRule) Severity() string {
44+
return tflint.ERROR
45+
}
46+
47+
// Link returns the rule reference link
48+
func (r *AwsDBProxyInvalidEngineFamilyRule) Link() string {
49+
return ""
50+
}
51+
52+
// Check checks the pattern is valid
53+
func (r *AwsDBProxyInvalidEngineFamilyRule) 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+
found := false
62+
for _, item := range r.enum {
63+
if item == val {
64+
found = true
65+
}
66+
}
67+
if !found {
68+
runner.EmitIssueOnExpr(
69+
r,
70+
fmt.Sprintf(`"%s" is an invalid value as engine_family`, truncateLongMessage(val)),
71+
attribute.Expr,
72+
)
73+
}
74+
return nil
75+
})
76+
})
77+
}

rules/models/mappings/rds.hcl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ mapping "aws_db_parameter_group" {
9292
tags = TagList
9393
}
9494

95+
mapping "aws_db_proxy" {
96+
auth = UserAuthConfigList
97+
engine_family = EngineFamily
98+
tags = TagList
99+
}
100+
101+
mapping "aws_db_proxy_default_target_group" {
102+
connection_pool_config = ConnectionPoolConfiguration
103+
}
104+
105+
mapping "aws_db_proxy_endpoint" {
106+
db_proxy_endpoint_name = DBProxyEndpointName
107+
db_proxy_name = DBProxyName
108+
target_role = DBProxyEndpointTargetRole
109+
tags = TagList
110+
}
111+
95112
mapping "aws_db_security_group" {
96113
name = String
97114
description = String

rules/models/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ var Rules = []tflint.Rule{
383383
NewAwsDatasyncTaskInvalidDestinationLocationArnRule(),
384384
NewAwsDatasyncTaskInvalidNameRule(),
385385
NewAwsDatasyncTaskInvalidSourceLocationArnRule(),
386+
NewAwsDBProxyEndpointInvalidDBProxyEndpointNameRule(),
387+
NewAwsDBProxyEndpointInvalidDBProxyNameRule(),
388+
NewAwsDBProxyEndpointInvalidTargetRoleRule(),
389+
NewAwsDBProxyInvalidEngineFamilyRule(),
386390
NewAwsDevicefarmProjectInvalidNameRule(),
387391
NewAwsDirectoryServiceConditionalForwarderInvalidDirectoryIDRule(),
388392
NewAwsDirectoryServiceConditionalForwarderInvalidRemoteDomainNameRule(),

0 commit comments

Comments
 (0)