Skip to content

17 files changed

+1228
-0
lines changed

docs/rules/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,20 @@ These rules enforce best practices and naming conventions:
287287
|aws_cloudhsm_v2_hsm_invalid_cluster_id||
288288
|aws_cloudhsm_v2_hsm_invalid_ip_address||
289289
|aws_cloudhsm_v2_hsm_invalid_subnet_id||
290+
|aws_cloudwatch_event_api_destination_invalid_connection_arn||
291+
|aws_cloudwatch_event_api_destination_invalid_description||
292+
|aws_cloudwatch_event_api_destination_invalid_http_method||
293+
|aws_cloudwatch_event_api_destination_invalid_invocation_endpoint||
294+
|aws_cloudwatch_event_api_destination_invalid_name||
295+
|aws_cloudwatch_event_archive_invalid_description||
296+
|aws_cloudwatch_event_archive_invalid_event_source_arn||
297+
|aws_cloudwatch_event_archive_invalid_name||
298+
|aws_cloudwatch_event_bus_invalid_event_source_name||
299+
|aws_cloudwatch_event_bus_invalid_name||
300+
|aws_cloudwatch_event_bus_policy_invalid_event_bus_name||
301+
|aws_cloudwatch_event_connection_invalid_authorization_type||
302+
|aws_cloudwatch_event_connection_invalid_description||
303+
|aws_cloudwatch_event_connection_invalid_name||
290304
|aws_cloudwatch_event_permission_invalid_action||
291305
|aws_cloudwatch_event_permission_invalid_principal||
292306
|aws_cloudwatch_event_permission_invalid_statement_id||
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+
// AwsCloudwatchEventAPIDestinationInvalidConnectionArnRule checks the pattern is valid
15+
type AwsCloudwatchEventAPIDestinationInvalidConnectionArnRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
min int
20+
pattern *regexp.Regexp
21+
}
22+
23+
// NewAwsCloudwatchEventAPIDestinationInvalidConnectionArnRule returns new rule with default attributes
24+
func NewAwsCloudwatchEventAPIDestinationInvalidConnectionArnRule() *AwsCloudwatchEventAPIDestinationInvalidConnectionArnRule {
25+
return &AwsCloudwatchEventAPIDestinationInvalidConnectionArnRule{
26+
resourceType: "aws_cloudwatch_event_api_destination",
27+
attributeName: "connection_arn",
28+
max: 1600,
29+
min: 1,
30+
pattern: regexp.MustCompile(`^arn:aws([a-z]|\-)*:events:([a-z]|\d|\-)*:([0-9]{12})?:connection\/[\.\-_A-Za-z0-9]+\/[\-A-Za-z0-9]+$`),
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsCloudwatchEventAPIDestinationInvalidConnectionArnRule) Name() string {
36+
return "aws_cloudwatch_event_api_destination_invalid_connection_arn"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsCloudwatchEventAPIDestinationInvalidConnectionArnRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsCloudwatchEventAPIDestinationInvalidConnectionArnRule) Severity() string {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsCloudwatchEventAPIDestinationInvalidConnectionArnRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsCloudwatchEventAPIDestinationInvalidConnectionArnRule) 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+
"connection_arn must be 1600 characters or less",
67+
attribute.Expr,
68+
)
69+
}
70+
if len(val) < r.min {
71+
runner.EmitIssueOnExpr(
72+
r,
73+
"connection_arn 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), `^arn:aws([a-z]|\-)*:events:([a-z]|\d|\-)*:([0-9]{12})?:connection\/[\.\-_A-Za-z0-9]+\/[\-A-Za-z0-9]+$`),
81+
attribute.Expr,
82+
)
83+
}
84+
return nil
85+
})
86+
})
87+
}
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+
// AwsCloudwatchEventAPIDestinationInvalidDescriptionRule checks the pattern is valid
15+
type AwsCloudwatchEventAPIDestinationInvalidDescriptionRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
pattern *regexp.Regexp
20+
}
21+
22+
// NewAwsCloudwatchEventAPIDestinationInvalidDescriptionRule returns new rule with default attributes
23+
func NewAwsCloudwatchEventAPIDestinationInvalidDescriptionRule() *AwsCloudwatchEventAPIDestinationInvalidDescriptionRule {
24+
return &AwsCloudwatchEventAPIDestinationInvalidDescriptionRule{
25+
resourceType: "aws_cloudwatch_event_api_destination",
26+
attributeName: "description",
27+
max: 512,
28+
pattern: regexp.MustCompile(`^.*$`),
29+
}
30+
}
31+
32+
// Name returns the rule name
33+
func (r *AwsCloudwatchEventAPIDestinationInvalidDescriptionRule) Name() string {
34+
return "aws_cloudwatch_event_api_destination_invalid_description"
35+
}
36+
37+
// Enabled returns whether the rule is enabled by default
38+
func (r *AwsCloudwatchEventAPIDestinationInvalidDescriptionRule) Enabled() bool {
39+
return true
40+
}
41+
42+
// Severity returns the rule severity
43+
func (r *AwsCloudwatchEventAPIDestinationInvalidDescriptionRule) Severity() string {
44+
return tflint.ERROR
45+
}
46+
47+
// Link returns the rule reference link
48+
func (r *AwsCloudwatchEventAPIDestinationInvalidDescriptionRule) Link() string {
49+
return ""
50+
}
51+
52+
// Check checks the pattern is valid
53+
func (r *AwsCloudwatchEventAPIDestinationInvalidDescriptionRule) 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.max {
62+
runner.EmitIssueOnExpr(
63+
r,
64+
"description must be 512 characters or less",
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), `^.*$`),
72+
attribute.Expr,
73+
)
74+
}
75+
return nil
76+
})
77+
})
78+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
// AwsCloudwatchEventAPIDestinationInvalidHTTPMethodRule checks the pattern is valid
14+
type AwsCloudwatchEventAPIDestinationInvalidHTTPMethodRule struct {
15+
resourceType string
16+
attributeName string
17+
enum []string
18+
}
19+
20+
// NewAwsCloudwatchEventAPIDestinationInvalidHTTPMethodRule returns new rule with default attributes
21+
func NewAwsCloudwatchEventAPIDestinationInvalidHTTPMethodRule() *AwsCloudwatchEventAPIDestinationInvalidHTTPMethodRule {
22+
return &AwsCloudwatchEventAPIDestinationInvalidHTTPMethodRule{
23+
resourceType: "aws_cloudwatch_event_api_destination",
24+
attributeName: "http_method",
25+
enum: []string{
26+
"POST",
27+
"GET",
28+
"HEAD",
29+
"OPTIONS",
30+
"PUT",
31+
"PATCH",
32+
"DELETE",
33+
},
34+
}
35+
}
36+
37+
// Name returns the rule name
38+
func (r *AwsCloudwatchEventAPIDestinationInvalidHTTPMethodRule) Name() string {
39+
return "aws_cloudwatch_event_api_destination_invalid_http_method"
40+
}
41+
42+
// Enabled returns whether the rule is enabled by default
43+
func (r *AwsCloudwatchEventAPIDestinationInvalidHTTPMethodRule) Enabled() bool {
44+
return true
45+
}
46+
47+
// Severity returns the rule severity
48+
func (r *AwsCloudwatchEventAPIDestinationInvalidHTTPMethodRule) Severity() string {
49+
return tflint.ERROR
50+
}
51+
52+
// Link returns the rule reference link
53+
func (r *AwsCloudwatchEventAPIDestinationInvalidHTTPMethodRule) Link() string {
54+
return ""
55+
}
56+
57+
// Check checks the pattern is valid
58+
func (r *AwsCloudwatchEventAPIDestinationInvalidHTTPMethodRule) Check(runner tflint.Runner) error {
59+
log.Printf("[TRACE] Check `%s` rule", r.Name())
60+
61+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
62+
var val string
63+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
64+
65+
return runner.EnsureNoError(err, func() error {
66+
found := false
67+
for _, item := range r.enum {
68+
if item == val {
69+
found = true
70+
}
71+
}
72+
if !found {
73+
runner.EmitIssueOnExpr(
74+
r,
75+
fmt.Sprintf(`"%s" is an invalid value as http_method`, truncateLongMessage(val)),
76+
attribute.Expr,
77+
)
78+
}
79+
return nil
80+
})
81+
})
82+
}
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+
// AwsCloudwatchEventAPIDestinationInvalidInvocationEndpointRule checks the pattern is valid
15+
type AwsCloudwatchEventAPIDestinationInvalidInvocationEndpointRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
min int
20+
pattern *regexp.Regexp
21+
}
22+
23+
// NewAwsCloudwatchEventAPIDestinationInvalidInvocationEndpointRule returns new rule with default attributes
24+
func NewAwsCloudwatchEventAPIDestinationInvalidInvocationEndpointRule() *AwsCloudwatchEventAPIDestinationInvalidInvocationEndpointRule {
25+
return &AwsCloudwatchEventAPIDestinationInvalidInvocationEndpointRule{
26+
resourceType: "aws_cloudwatch_event_api_destination",
27+
attributeName: "invocation_endpoint",
28+
max: 2048,
29+
min: 1,
30+
pattern: regexp.MustCompile(`^((%[0-9A-Fa-f]{2}|[-()_.!~*';/?:@\x26=+$,A-Za-z0-9])+)([).!';/?:,])?$`),
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsCloudwatchEventAPIDestinationInvalidInvocationEndpointRule) Name() string {
36+
return "aws_cloudwatch_event_api_destination_invalid_invocation_endpoint"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsCloudwatchEventAPIDestinationInvalidInvocationEndpointRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsCloudwatchEventAPIDestinationInvalidInvocationEndpointRule) Severity() string {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsCloudwatchEventAPIDestinationInvalidInvocationEndpointRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsCloudwatchEventAPIDestinationInvalidInvocationEndpointRule) 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+
"invocation_endpoint must be 2048 characters or less",
67+
attribute.Expr,
68+
)
69+
}
70+
if len(val) < r.min {
71+
runner.EmitIssueOnExpr(
72+
r,
73+
"invocation_endpoint 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), `^((%[0-9A-Fa-f]{2}|[-()_.!~*';/?:@\x26=+$,A-Za-z0-9])+)([).!';/?:,])?$`),
81+
attribute.Expr,
82+
)
83+
}
84+
return nil
85+
})
86+
})
87+
}

0 commit comments

Comments
 (0)