Skip to content

7 files changed

+331
-0
lines changed

docs/rules/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,10 @@ These rules enforce best practices and naming conventions:
801801
|aws_kms_key_invalid_description||
802802
|aws_kms_key_invalid_key_usage||
803803
|aws_kms_key_invalid_policy||
804+
|aws_kms_replica_external_key_invalid_description||
805+
|aws_kms_replica_external_key_invalid_policy||
806+
|aws_kms_replica_key_invalid_description||
807+
|aws_kms_replica_key_invalid_policy||
804808
|aws_lakeformation_resource_invalid_role_arn||
805809
|aws_lambda_alias_invalid_description||
806810
|aws_lambda_alias_invalid_function_name||
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"log"
7+
8+
hcl "github.com/hashicorp/hcl/v2"
9+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
10+
)
11+
12+
// AwsKmsReplicaExternalKeyInvalidDescriptionRule checks the pattern is valid
13+
type AwsKmsReplicaExternalKeyInvalidDescriptionRule struct {
14+
resourceType string
15+
attributeName string
16+
max int
17+
}
18+
19+
// NewAwsKmsReplicaExternalKeyInvalidDescriptionRule returns new rule with default attributes
20+
func NewAwsKmsReplicaExternalKeyInvalidDescriptionRule() *AwsKmsReplicaExternalKeyInvalidDescriptionRule {
21+
return &AwsKmsReplicaExternalKeyInvalidDescriptionRule{
22+
resourceType: "aws_kms_replica_external_key",
23+
attributeName: "description",
24+
max: 8192,
25+
}
26+
}
27+
28+
// Name returns the rule name
29+
func (r *AwsKmsReplicaExternalKeyInvalidDescriptionRule) Name() string {
30+
return "aws_kms_replica_external_key_invalid_description"
31+
}
32+
33+
// Enabled returns whether the rule is enabled by default
34+
func (r *AwsKmsReplicaExternalKeyInvalidDescriptionRule) Enabled() bool {
35+
return true
36+
}
37+
38+
// Severity returns the rule severity
39+
func (r *AwsKmsReplicaExternalKeyInvalidDescriptionRule) Severity() string {
40+
return tflint.ERROR
41+
}
42+
43+
// Link returns the rule reference link
44+
func (r *AwsKmsReplicaExternalKeyInvalidDescriptionRule) Link() string {
45+
return ""
46+
}
47+
48+
// Check checks the pattern is valid
49+
func (r *AwsKmsReplicaExternalKeyInvalidDescriptionRule) Check(runner tflint.Runner) error {
50+
log.Printf("[TRACE] Check `%s` rule", r.Name())
51+
52+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
53+
var val string
54+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
55+
56+
return runner.EnsureNoError(err, func() error {
57+
if len(val) > r.max {
58+
runner.EmitIssueOnExpr(
59+
r,
60+
"description must be 8192 characters or less",
61+
attribute.Expr,
62+
)
63+
}
64+
return nil
65+
})
66+
})
67+
}
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+
// AwsKmsReplicaExternalKeyInvalidPolicyRule checks the pattern is valid
15+
type AwsKmsReplicaExternalKeyInvalidPolicyRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
min int
20+
pattern *regexp.Regexp
21+
}
22+
23+
// NewAwsKmsReplicaExternalKeyInvalidPolicyRule returns new rule with default attributes
24+
func NewAwsKmsReplicaExternalKeyInvalidPolicyRule() *AwsKmsReplicaExternalKeyInvalidPolicyRule {
25+
return &AwsKmsReplicaExternalKeyInvalidPolicyRule{
26+
resourceType: "aws_kms_replica_external_key",
27+
attributeName: "policy",
28+
max: 131072,
29+
min: 1,
30+
pattern: regexp.MustCompile(`^[\x{0009}\x{000A}\x{000D}\x{0020}-\x{00FF}]+$`),
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsKmsReplicaExternalKeyInvalidPolicyRule) Name() string {
36+
return "aws_kms_replica_external_key_invalid_policy"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsKmsReplicaExternalKeyInvalidPolicyRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsKmsReplicaExternalKeyInvalidPolicyRule) Severity() string {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsKmsReplicaExternalKeyInvalidPolicyRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsKmsReplicaExternalKeyInvalidPolicyRule) 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+
"policy must be 131072 characters or less",
67+
attribute.Expr,
68+
)
69+
}
70+
if len(val) < r.min {
71+
runner.EmitIssueOnExpr(
72+
r,
73+
"policy 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), `^[\x{0009}\x{000A}\x{000D}\x{0020}-\x{00FF}]+$`),
81+
attribute.Expr,
82+
)
83+
}
84+
return nil
85+
})
86+
})
87+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"log"
7+
8+
hcl "github.com/hashicorp/hcl/v2"
9+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
10+
)
11+
12+
// AwsKmsReplicaKeyInvalidDescriptionRule checks the pattern is valid
13+
type AwsKmsReplicaKeyInvalidDescriptionRule struct {
14+
resourceType string
15+
attributeName string
16+
max int
17+
}
18+
19+
// NewAwsKmsReplicaKeyInvalidDescriptionRule returns new rule with default attributes
20+
func NewAwsKmsReplicaKeyInvalidDescriptionRule() *AwsKmsReplicaKeyInvalidDescriptionRule {
21+
return &AwsKmsReplicaKeyInvalidDescriptionRule{
22+
resourceType: "aws_kms_replica_key",
23+
attributeName: "description",
24+
max: 8192,
25+
}
26+
}
27+
28+
// Name returns the rule name
29+
func (r *AwsKmsReplicaKeyInvalidDescriptionRule) Name() string {
30+
return "aws_kms_replica_key_invalid_description"
31+
}
32+
33+
// Enabled returns whether the rule is enabled by default
34+
func (r *AwsKmsReplicaKeyInvalidDescriptionRule) Enabled() bool {
35+
return true
36+
}
37+
38+
// Severity returns the rule severity
39+
func (r *AwsKmsReplicaKeyInvalidDescriptionRule) Severity() string {
40+
return tflint.ERROR
41+
}
42+
43+
// Link returns the rule reference link
44+
func (r *AwsKmsReplicaKeyInvalidDescriptionRule) Link() string {
45+
return ""
46+
}
47+
48+
// Check checks the pattern is valid
49+
func (r *AwsKmsReplicaKeyInvalidDescriptionRule) Check(runner tflint.Runner) error {
50+
log.Printf("[TRACE] Check `%s` rule", r.Name())
51+
52+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
53+
var val string
54+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
55+
56+
return runner.EnsureNoError(err, func() error {
57+
if len(val) > r.max {
58+
runner.EmitIssueOnExpr(
59+
r,
60+
"description must be 8192 characters or less",
61+
attribute.Expr,
62+
)
63+
}
64+
return nil
65+
})
66+
})
67+
}
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+
// AwsKmsReplicaKeyInvalidPolicyRule checks the pattern is valid
15+
type AwsKmsReplicaKeyInvalidPolicyRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
min int
20+
pattern *regexp.Regexp
21+
}
22+
23+
// NewAwsKmsReplicaKeyInvalidPolicyRule returns new rule with default attributes
24+
func NewAwsKmsReplicaKeyInvalidPolicyRule() *AwsKmsReplicaKeyInvalidPolicyRule {
25+
return &AwsKmsReplicaKeyInvalidPolicyRule{
26+
resourceType: "aws_kms_replica_key",
27+
attributeName: "policy",
28+
max: 131072,
29+
min: 1,
30+
pattern: regexp.MustCompile(`^[\x{0009}\x{000A}\x{000D}\x{0020}-\x{00FF}]+$`),
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsKmsReplicaKeyInvalidPolicyRule) Name() string {
36+
return "aws_kms_replica_key_invalid_policy"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsKmsReplicaKeyInvalidPolicyRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsKmsReplicaKeyInvalidPolicyRule) Severity() string {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsKmsReplicaKeyInvalidPolicyRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsKmsReplicaKeyInvalidPolicyRule) 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+
"policy must be 131072 characters or less",
67+
attribute.Expr,
68+
)
69+
}
70+
if len(val) < r.min {
71+
runner.EmitIssueOnExpr(
72+
r,
73+
"policy 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), `^[\x{0009}\x{000A}\x{000D}\x{0020}-\x{00FF}]+$`),
81+
attribute.Expr,
82+
)
83+
}
84+
return nil
85+
})
86+
})
87+
}

rules/models/mappings/kms.hcl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,18 @@ mapping "aws_kms_key" {
4242
enable_key_rotation = BooleanType
4343
tags = TagList
4444
}
45+
46+
mapping "aws_kms_replica_external_key" {
47+
deletion_window_in_days = PendingWindowInDaysType
48+
description = DescriptionType
49+
policy = PolicyType
50+
tags = TagList
51+
valid_to = DateType
52+
}
53+
54+
mapping "aws_kms_replica_key" {
55+
deletion_window_in_days = PendingWindowInDaysType
56+
description = DescriptionType
57+
policy = PolicyType
58+
tags = TagList
59+
}

rules/models/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,10 @@ var Rules = []tflint.Rule{
729729
NewAwsKmsKeyInvalidDescriptionRule(),
730730
NewAwsKmsKeyInvalidKeyUsageRule(),
731731
NewAwsKmsKeyInvalidPolicyRule(),
732+
NewAwsKmsReplicaExternalKeyInvalidDescriptionRule(),
733+
NewAwsKmsReplicaExternalKeyInvalidPolicyRule(),
734+
NewAwsKmsReplicaKeyInvalidDescriptionRule(),
735+
NewAwsKmsReplicaKeyInvalidPolicyRule(),
732736
NewAwsLakeformationResourceInvalidRoleArnRule(),
733737
NewAwsLambdaAliasInvalidDescriptionRule(),
734738
NewAwsLambdaAliasInvalidFunctionNameRule(),

0 commit comments

Comments
 (0)