Skip to content

6 files changed

+254
-0
lines changed

docs/rules/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,16 @@ These rules enforce best practices and naming conventions:
508508
|aws_dx_private_virtual_interface_invalid_address_family||
509509
|aws_dx_public_virtual_interface_invalid_address_family||
510510
|aws_dynamodb_global_table_invalid_name||
511+
|aws_dynamodb_kinesis_streaming_destination_invalid_stream_arn||
512+
|aws_dynamodb_kinesis_streaming_destination_invalid_table_name||
511513
|aws_dynamodb_table_invalid_billing_mode||
512514
|aws_dynamodb_table_invalid_hash_key||
513515
|aws_dynamodb_table_invalid_name||
514516
|aws_dynamodb_table_invalid_range_key||
515517
|aws_dynamodb_table_item_invalid_hash_key||
516518
|aws_dynamodb_table_item_invalid_range_key||
517519
|aws_dynamodb_table_item_invalid_table_name||
520+
|aws_dynamodb_tag_invalid_resource_arn||
518521
|aws_ebs_volume_invalid_type||
519522
|aws_ec2_availability_zone_group_invalid_opt_in_status||
520523
|aws_ec2_capacity_reservation_invalid_end_date_type||
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+
// AwsDynamoDBKinesisStreamingDestinationInvalidStreamArnRule checks the pattern is valid
13+
type AwsDynamoDBKinesisStreamingDestinationInvalidStreamArnRule struct {
14+
resourceType string
15+
attributeName string
16+
max int
17+
min int
18+
}
19+
20+
// NewAwsDynamoDBKinesisStreamingDestinationInvalidStreamArnRule returns new rule with default attributes
21+
func NewAwsDynamoDBKinesisStreamingDestinationInvalidStreamArnRule() *AwsDynamoDBKinesisStreamingDestinationInvalidStreamArnRule {
22+
return &AwsDynamoDBKinesisStreamingDestinationInvalidStreamArnRule{
23+
resourceType: "aws_dynamodb_kinesis_streaming_destination",
24+
attributeName: "stream_arn",
25+
max: 1024,
26+
min: 37,
27+
}
28+
}
29+
30+
// Name returns the rule name
31+
func (r *AwsDynamoDBKinesisStreamingDestinationInvalidStreamArnRule) Name() string {
32+
return "aws_dynamodb_kinesis_streaming_destination_invalid_stream_arn"
33+
}
34+
35+
// Enabled returns whether the rule is enabled by default
36+
func (r *AwsDynamoDBKinesisStreamingDestinationInvalidStreamArnRule) Enabled() bool {
37+
return true
38+
}
39+
40+
// Severity returns the rule severity
41+
func (r *AwsDynamoDBKinesisStreamingDestinationInvalidStreamArnRule) Severity() string {
42+
return tflint.ERROR
43+
}
44+
45+
// Link returns the rule reference link
46+
func (r *AwsDynamoDBKinesisStreamingDestinationInvalidStreamArnRule) Link() string {
47+
return ""
48+
}
49+
50+
// Check checks the pattern is valid
51+
func (r *AwsDynamoDBKinesisStreamingDestinationInvalidStreamArnRule) 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+
"stream_arn must be 1024 characters or less",
63+
attribute.Expr,
64+
)
65+
}
66+
if len(val) < r.min {
67+
runner.EmitIssueOnExpr(
68+
r,
69+
"stream_arn must be 37 characters or higher",
70+
attribute.Expr,
71+
)
72+
}
73+
return nil
74+
})
75+
})
76+
}
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+
// AwsDynamoDBKinesisStreamingDestinationInvalidTableNameRule checks the pattern is valid
15+
type AwsDynamoDBKinesisStreamingDestinationInvalidTableNameRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
min int
20+
pattern *regexp.Regexp
21+
}
22+
23+
// NewAwsDynamoDBKinesisStreamingDestinationInvalidTableNameRule returns new rule with default attributes
24+
func NewAwsDynamoDBKinesisStreamingDestinationInvalidTableNameRule() *AwsDynamoDBKinesisStreamingDestinationInvalidTableNameRule {
25+
return &AwsDynamoDBKinesisStreamingDestinationInvalidTableNameRule{
26+
resourceType: "aws_dynamodb_kinesis_streaming_destination",
27+
attributeName: "table_name",
28+
max: 255,
29+
min: 3,
30+
pattern: regexp.MustCompile(`^[a-zA-Z0-9_.-]+$`),
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsDynamoDBKinesisStreamingDestinationInvalidTableNameRule) Name() string {
36+
return "aws_dynamodb_kinesis_streaming_destination_invalid_table_name"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsDynamoDBKinesisStreamingDestinationInvalidTableNameRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsDynamoDBKinesisStreamingDestinationInvalidTableNameRule) Severity() string {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsDynamoDBKinesisStreamingDestinationInvalidTableNameRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsDynamoDBKinesisStreamingDestinationInvalidTableNameRule) 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+
"table_name must be 255 characters or less",
67+
attribute.Expr,
68+
)
69+
}
70+
if len(val) < r.min {
71+
runner.EmitIssueOnExpr(
72+
r,
73+
"table_name must be 3 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-Z0-9_.-]+$`),
81+
attribute.Expr,
82+
)
83+
}
84+
return nil
85+
})
86+
})
87+
}
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+
// AwsDynamoDBTagInvalidResourceArnRule checks the pattern is valid
13+
type AwsDynamoDBTagInvalidResourceArnRule struct {
14+
resourceType string
15+
attributeName string
16+
max int
17+
min int
18+
}
19+
20+
// NewAwsDynamoDBTagInvalidResourceArnRule returns new rule with default attributes
21+
func NewAwsDynamoDBTagInvalidResourceArnRule() *AwsDynamoDBTagInvalidResourceArnRule {
22+
return &AwsDynamoDBTagInvalidResourceArnRule{
23+
resourceType: "aws_dynamodb_tag",
24+
attributeName: "resource_arn",
25+
max: 1283,
26+
min: 1,
27+
}
28+
}
29+
30+
// Name returns the rule name
31+
func (r *AwsDynamoDBTagInvalidResourceArnRule) Name() string {
32+
return "aws_dynamodb_tag_invalid_resource_arn"
33+
}
34+
35+
// Enabled returns whether the rule is enabled by default
36+
func (r *AwsDynamoDBTagInvalidResourceArnRule) Enabled() bool {
37+
return true
38+
}
39+
40+
// Severity returns the rule severity
41+
func (r *AwsDynamoDBTagInvalidResourceArnRule) Severity() string {
42+
return tflint.ERROR
43+
}
44+
45+
// Link returns the rule reference link
46+
func (r *AwsDynamoDBTagInvalidResourceArnRule) Link() string {
47+
return ""
48+
}
49+
50+
// Check checks the pattern is valid
51+
func (r *AwsDynamoDBTagInvalidResourceArnRule) 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+
"resource_arn must be 1283 characters or less",
63+
attribute.Expr,
64+
)
65+
}
66+
if len(val) < r.min {
67+
runner.EmitIssueOnExpr(
68+
r,
69+
"resource_arn must be 1 characters or higher",
70+
attribute.Expr,
71+
)
72+
}
73+
return nil
74+
})
75+
})
76+
}

rules/models/mappings/dynamodb.hcl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ mapping "aws_dynamodb_global_table" {
55
replica = ReplicaList
66
}
77

8+
mapping "aws_dynamodb_kinesis_streaming_destination" {
9+
stream_arn = StreamArn
10+
table_name = TableName
11+
}
12+
813
mapping "aws_dynamodb_table" {
914
name = TableName
1015
billing_mode = BillingMode
@@ -29,6 +34,10 @@ mapping "aws_dynamodb_table_item" {
2934
item = AttributeMap
3035
}
3136

37+
mapping "aws_dynamodb_tag" {
38+
resource_arn = ResourceArnString
39+
}
40+
3241
test "aws_dynamodb_global_table" "name" {
3342
ok = "myTable"
3443
ng = "myTable@development"

rules/models/provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,16 @@ var Rules = []tflint.Rule{
436436
NewAwsDxPrivateVirtualInterfaceInvalidAddressFamilyRule(),
437437
NewAwsDxPublicVirtualInterfaceInvalidAddressFamilyRule(),
438438
NewAwsDynamoDBGlobalTableInvalidNameRule(),
439+
NewAwsDynamoDBKinesisStreamingDestinationInvalidStreamArnRule(),
440+
NewAwsDynamoDBKinesisStreamingDestinationInvalidTableNameRule(),
439441
NewAwsDynamoDBTableInvalidBillingModeRule(),
440442
NewAwsDynamoDBTableInvalidHashKeyRule(),
441443
NewAwsDynamoDBTableInvalidNameRule(),
442444
NewAwsDynamoDBTableInvalidRangeKeyRule(),
443445
NewAwsDynamoDBTableItemInvalidHashKeyRule(),
444446
NewAwsDynamoDBTableItemInvalidRangeKeyRule(),
445447
NewAwsDynamoDBTableItemInvalidTableNameRule(),
448+
NewAwsDynamoDBTagInvalidResourceArnRule(),
446449
NewAwsEbsVolumeInvalidTypeRule(),
447450
NewAwsEc2AvailabilityZoneGroupInvalidOptInStatusRule(),
448451
NewAwsEc2CapacityReservationInvalidEndDateTypeRule(),

0 commit comments

Comments
 (0)