Skip to content

File tree

6 files changed

+246
-0
lines changed

6 files changed

+246
-0
lines changed

docs/rules/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,9 @@ These rules enforce best practices and naming conventions:
13941394
|aws_worklink_website_certificate_authority_association_invalid_certificate||
13951395
|aws_worklink_website_certificate_authority_association_invalid_display_name||
13961396
|aws_worklink_website_certificate_authority_association_invalid_fleet_arn||
1397+
|aws_xray_encryption_config_invalid_key_id||
1398+
|aws_xray_encryption_config_invalid_type||
1399+
|aws_xray_group_invalid_group_name||
13971400
|aws_xray_sampling_rule_invalid_host||
13981401
|aws_xray_sampling_rule_invalid_http_method||
13991402
|aws_xray_sampling_rule_invalid_resource_arn||
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
// AwsXrayEncryptionConfigInvalidKeyIDRule checks the pattern is valid
13+
type AwsXrayEncryptionConfigInvalidKeyIDRule struct {
14+
resourceType string
15+
attributeName string
16+
max int
17+
min int
18+
}
19+
20+
// NewAwsXrayEncryptionConfigInvalidKeyIDRule returns new rule with default attributes
21+
func NewAwsXrayEncryptionConfigInvalidKeyIDRule() *AwsXrayEncryptionConfigInvalidKeyIDRule {
22+
return &AwsXrayEncryptionConfigInvalidKeyIDRule{
23+
resourceType: "aws_xray_encryption_config",
24+
attributeName: "key_id",
25+
max: 3000,
26+
min: 1,
27+
}
28+
}
29+
30+
// Name returns the rule name
31+
func (r *AwsXrayEncryptionConfigInvalidKeyIDRule) Name() string {
32+
return "aws_xray_encryption_config_invalid_key_id"
33+
}
34+
35+
// Enabled returns whether the rule is enabled by default
36+
func (r *AwsXrayEncryptionConfigInvalidKeyIDRule) Enabled() bool {
37+
return true
38+
}
39+
40+
// Severity returns the rule severity
41+
func (r *AwsXrayEncryptionConfigInvalidKeyIDRule) Severity() string {
42+
return tflint.ERROR
43+
}
44+
45+
// Link returns the rule reference link
46+
func (r *AwsXrayEncryptionConfigInvalidKeyIDRule) Link() string {
47+
return ""
48+
}
49+
50+
// Check checks the pattern is valid
51+
func (r *AwsXrayEncryptionConfigInvalidKeyIDRule) 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 len(val) > r.max {
60+
runner.EmitIssueOnExpr(
61+
r,
62+
"key_id must be 3000 characters or less",
63+
attribute.Expr,
64+
)
65+
}
66+
if len(val) < r.min {
67+
runner.EmitIssueOnExpr(
68+
r,
69+
"key_id must be 1 characters or higher",
70+
attribute.Expr,
71+
)
72+
}
73+
return nil
74+
})
75+
})
76+
}
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+
// AwsXrayEncryptionConfigInvalidTypeRule checks the pattern is valid
14+
type AwsXrayEncryptionConfigInvalidTypeRule struct {
15+
resourceType string
16+
attributeName string
17+
enum []string
18+
}
19+
20+
// NewAwsXrayEncryptionConfigInvalidTypeRule returns new rule with default attributes
21+
func NewAwsXrayEncryptionConfigInvalidTypeRule() *AwsXrayEncryptionConfigInvalidTypeRule {
22+
return &AwsXrayEncryptionConfigInvalidTypeRule{
23+
resourceType: "aws_xray_encryption_config",
24+
attributeName: "type",
25+
enum: []string{
26+
"NONE",
27+
"KMS",
28+
},
29+
}
30+
}
31+
32+
// Name returns the rule name
33+
func (r *AwsXrayEncryptionConfigInvalidTypeRule) Name() string {
34+
return "aws_xray_encryption_config_invalid_type"
35+
}
36+
37+
// Enabled returns whether the rule is enabled by default
38+
func (r *AwsXrayEncryptionConfigInvalidTypeRule) Enabled() bool {
39+
return true
40+
}
41+
42+
// Severity returns the rule severity
43+
func (r *AwsXrayEncryptionConfigInvalidTypeRule) Severity() string {
44+
return tflint.ERROR
45+
}
46+
47+
// Link returns the rule reference link
48+
func (r *AwsXrayEncryptionConfigInvalidTypeRule) Link() string {
49+
return ""
50+
}
51+
52+
// Check checks the pattern is valid
53+
func (r *AwsXrayEncryptionConfigInvalidTypeRule) 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 type`, truncateLongMessage(val)),
71+
attribute.Expr,
72+
)
73+
}
74+
return nil
75+
})
76+
})
77+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
// AwsXrayGroupInvalidGroupNameRule checks the pattern is valid
13+
type AwsXrayGroupInvalidGroupNameRule struct {
14+
resourceType string
15+
attributeName string
16+
max int
17+
min int
18+
}
19+
20+
// NewAwsXrayGroupInvalidGroupNameRule returns new rule with default attributes
21+
func NewAwsXrayGroupInvalidGroupNameRule() *AwsXrayGroupInvalidGroupNameRule {
22+
return &AwsXrayGroupInvalidGroupNameRule{
23+
resourceType: "aws_xray_group",
24+
attributeName: "group_name",
25+
max: 32,
26+
min: 1,
27+
}
28+
}
29+
30+
// Name returns the rule name
31+
func (r *AwsXrayGroupInvalidGroupNameRule) Name() string {
32+
return "aws_xray_group_invalid_group_name"
33+
}
34+
35+
// Enabled returns whether the rule is enabled by default
36+
func (r *AwsXrayGroupInvalidGroupNameRule) Enabled() bool {
37+
return true
38+
}
39+
40+
// Severity returns the rule severity
41+
func (r *AwsXrayGroupInvalidGroupNameRule) Severity() string {
42+
return tflint.ERROR
43+
}
44+
45+
// Link returns the rule reference link
46+
func (r *AwsXrayGroupInvalidGroupNameRule) Link() string {
47+
return ""
48+
}
49+
50+
// Check checks the pattern is valid
51+
func (r *AwsXrayGroupInvalidGroupNameRule) 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 len(val) > r.max {
60+
runner.EmitIssueOnExpr(
61+
r,
62+
"group_name must be 32 characters or less",
63+
attribute.Expr,
64+
)
65+
}
66+
if len(val) < r.min {
67+
runner.EmitIssueOnExpr(
68+
r,
69+
"group_name must be 1 characters or higher",
70+
attribute.Expr,
71+
)
72+
}
73+
return nil
74+
})
75+
})
76+
}

rules/models/mappings/xray.hcl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import = "aws-sdk-go/models/apis/xray/2016-04-12/api-2.json"
22

3+
mapping "aws_xray_encryption_config" {
4+
type = EncryptionType
5+
key_id = EncryptionKeyId
6+
}
7+
8+
mapping "aws_xray_group" {
9+
group_name = GroupName
10+
filter_expression = FilterExpression
11+
tags = TagList
12+
}
13+
314
mapping "aws_xray_sampling_rule" {
415
rule_name = RuleName
516
resource_arn = ResourceARN

rules/models/provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,9 @@ var Rules = []tflint.Rule{
13221322
NewAwsWorklinkWebsiteCertificateAuthorityAssociationInvalidCertificateRule(),
13231323
NewAwsWorklinkWebsiteCertificateAuthorityAssociationInvalidDisplayNameRule(),
13241324
NewAwsWorklinkWebsiteCertificateAuthorityAssociationInvalidFleetArnRule(),
1325+
NewAwsXrayEncryptionConfigInvalidKeyIDRule(),
1326+
NewAwsXrayEncryptionConfigInvalidTypeRule(),
1327+
NewAwsXrayGroupInvalidGroupNameRule(),
13251328
NewAwsXraySamplingRuleInvalidHostRule(),
13261329
NewAwsXraySamplingRuleInvalidHTTPMethodRule(),
13271330
NewAwsXraySamplingRuleInvalidResourceArnRule(),

0 commit comments

Comments
 (0)