Skip to content

7 files changed

+347
-0
lines changed

docs/rules/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,14 @@ These rules enforce best practices and naming conventions:
536536
|aws_ecs_task_definition_invalid_network_mode||
537537
|aws_ecs_task_definition_invalid_pid_mode||
538538
|aws_ecs_task_set_invalid_launch_type||
539+
|aws_efs_access_point_invalid_file_system_id||
540+
|aws_efs_backup_policy_invalid_file_system_id||
539541
|aws_efs_file_system_invalid_creation_token||
540542
|aws_efs_file_system_invalid_kms_key_id||
541543
|aws_efs_file_system_invalid_performance_mode||
542544
|aws_efs_file_system_invalid_throughput_mode||
545+
|aws_efs_file_system_policy_invalid_file_system_id||
546+
|aws_efs_file_system_policy_invalid_policy||
543547
|aws_efs_mount_target_invalid_file_system_id||
544548
|aws_efs_mount_target_invalid_ip_address||
545549
|aws_efs_mount_target_invalid_subnet_id||
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+
// AwsEfsAccessPointInvalidFileSystemIDRule checks the pattern is valid
15+
type AwsEfsAccessPointInvalidFileSystemIDRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
pattern *regexp.Regexp
20+
}
21+
22+
// NewAwsEfsAccessPointInvalidFileSystemIDRule returns new rule with default attributes
23+
func NewAwsEfsAccessPointInvalidFileSystemIDRule() *AwsEfsAccessPointInvalidFileSystemIDRule {
24+
return &AwsEfsAccessPointInvalidFileSystemIDRule{
25+
resourceType: "aws_efs_access_point",
26+
attributeName: "file_system_id",
27+
max: 128,
28+
pattern: regexp.MustCompile(`^(arn:aws[-a-z]*:elasticfilesystem:[0-9a-z-:]+:file-system/fs-[0-9a-f]{8,40}|fs-[0-9a-f]{8,40})$`),
29+
}
30+
}
31+
32+
// Name returns the rule name
33+
func (r *AwsEfsAccessPointInvalidFileSystemIDRule) Name() string {
34+
return "aws_efs_access_point_invalid_file_system_id"
35+
}
36+
37+
// Enabled returns whether the rule is enabled by default
38+
func (r *AwsEfsAccessPointInvalidFileSystemIDRule) Enabled() bool {
39+
return true
40+
}
41+
42+
// Severity returns the rule severity
43+
func (r *AwsEfsAccessPointInvalidFileSystemIDRule) Severity() string {
44+
return tflint.ERROR
45+
}
46+
47+
// Link returns the rule reference link
48+
func (r *AwsEfsAccessPointInvalidFileSystemIDRule) Link() string {
49+
return ""
50+
}
51+
52+
// Check checks the pattern is valid
53+
func (r *AwsEfsAccessPointInvalidFileSystemIDRule) 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+
"file_system_id must be 128 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), `^(arn:aws[-a-z]*:elasticfilesystem:[0-9a-z-:]+:file-system/fs-[0-9a-f]{8,40}|fs-[0-9a-f]{8,40})$`),
72+
attribute.Expr,
73+
)
74+
}
75+
return nil
76+
})
77+
})
78+
}
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+
// AwsEfsBackupPolicyInvalidFileSystemIDRule checks the pattern is valid
15+
type AwsEfsBackupPolicyInvalidFileSystemIDRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
pattern *regexp.Regexp
20+
}
21+
22+
// NewAwsEfsBackupPolicyInvalidFileSystemIDRule returns new rule with default attributes
23+
func NewAwsEfsBackupPolicyInvalidFileSystemIDRule() *AwsEfsBackupPolicyInvalidFileSystemIDRule {
24+
return &AwsEfsBackupPolicyInvalidFileSystemIDRule{
25+
resourceType: "aws_efs_backup_policy",
26+
attributeName: "file_system_id",
27+
max: 128,
28+
pattern: regexp.MustCompile(`^(arn:aws[-a-z]*:elasticfilesystem:[0-9a-z-:]+:file-system/fs-[0-9a-f]{8,40}|fs-[0-9a-f]{8,40})$`),
29+
}
30+
}
31+
32+
// Name returns the rule name
33+
func (r *AwsEfsBackupPolicyInvalidFileSystemIDRule) Name() string {
34+
return "aws_efs_backup_policy_invalid_file_system_id"
35+
}
36+
37+
// Enabled returns whether the rule is enabled by default
38+
func (r *AwsEfsBackupPolicyInvalidFileSystemIDRule) Enabled() bool {
39+
return true
40+
}
41+
42+
// Severity returns the rule severity
43+
func (r *AwsEfsBackupPolicyInvalidFileSystemIDRule) Severity() string {
44+
return tflint.ERROR
45+
}
46+
47+
// Link returns the rule reference link
48+
func (r *AwsEfsBackupPolicyInvalidFileSystemIDRule) Link() string {
49+
return ""
50+
}
51+
52+
// Check checks the pattern is valid
53+
func (r *AwsEfsBackupPolicyInvalidFileSystemIDRule) 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+
"file_system_id must be 128 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), `^(arn:aws[-a-z]*:elasticfilesystem:[0-9a-z-:]+:file-system/fs-[0-9a-f]{8,40}|fs-[0-9a-f]{8,40})$`),
72+
attribute.Expr,
73+
)
74+
}
75+
return nil
76+
})
77+
})
78+
}
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+
// AwsEfsFileSystemPolicyInvalidFileSystemIDRule checks the pattern is valid
15+
type AwsEfsFileSystemPolicyInvalidFileSystemIDRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
pattern *regexp.Regexp
20+
}
21+
22+
// NewAwsEfsFileSystemPolicyInvalidFileSystemIDRule returns new rule with default attributes
23+
func NewAwsEfsFileSystemPolicyInvalidFileSystemIDRule() *AwsEfsFileSystemPolicyInvalidFileSystemIDRule {
24+
return &AwsEfsFileSystemPolicyInvalidFileSystemIDRule{
25+
resourceType: "aws_efs_file_system_policy",
26+
attributeName: "file_system_id",
27+
max: 128,
28+
pattern: regexp.MustCompile(`^(arn:aws[-a-z]*:elasticfilesystem:[0-9a-z-:]+:file-system/fs-[0-9a-f]{8,40}|fs-[0-9a-f]{8,40})$`),
29+
}
30+
}
31+
32+
// Name returns the rule name
33+
func (r *AwsEfsFileSystemPolicyInvalidFileSystemIDRule) Name() string {
34+
return "aws_efs_file_system_policy_invalid_file_system_id"
35+
}
36+
37+
// Enabled returns whether the rule is enabled by default
38+
func (r *AwsEfsFileSystemPolicyInvalidFileSystemIDRule) Enabled() bool {
39+
return true
40+
}
41+
42+
// Severity returns the rule severity
43+
func (r *AwsEfsFileSystemPolicyInvalidFileSystemIDRule) Severity() string {
44+
return tflint.ERROR
45+
}
46+
47+
// Link returns the rule reference link
48+
func (r *AwsEfsFileSystemPolicyInvalidFileSystemIDRule) Link() string {
49+
return ""
50+
}
51+
52+
// Check checks the pattern is valid
53+
func (r *AwsEfsFileSystemPolicyInvalidFileSystemIDRule) 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+
"file_system_id must be 128 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), `^(arn:aws[-a-z]*:elasticfilesystem:[0-9a-z-:]+:file-system/fs-[0-9a-f]{8,40}|fs-[0-9a-f]{8,40})$`),
72+
attribute.Expr,
73+
)
74+
}
75+
return nil
76+
})
77+
})
78+
}
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+
// AwsEfsFileSystemPolicyInvalidPolicyRule checks the pattern is valid
15+
type AwsEfsFileSystemPolicyInvalidPolicyRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
min int
20+
pattern *regexp.Regexp
21+
}
22+
23+
// NewAwsEfsFileSystemPolicyInvalidPolicyRule returns new rule with default attributes
24+
func NewAwsEfsFileSystemPolicyInvalidPolicyRule() *AwsEfsFileSystemPolicyInvalidPolicyRule {
25+
return &AwsEfsFileSystemPolicyInvalidPolicyRule{
26+
resourceType: "aws_efs_file_system_policy",
27+
attributeName: "policy",
28+
max: 20000,
29+
min: 1,
30+
pattern: regexp.MustCompile(`^[\s\S]+$`),
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsEfsFileSystemPolicyInvalidPolicyRule) Name() string {
36+
return "aws_efs_file_system_policy_invalid_policy"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsEfsFileSystemPolicyInvalidPolicyRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsEfsFileSystemPolicyInvalidPolicyRule) Severity() string {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsEfsFileSystemPolicyInvalidPolicyRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsEfsFileSystemPolicyInvalidPolicyRule) 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 20000 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), `^[\s\S]+$`),
81+
attribute.Expr,
82+
)
83+
}
84+
return nil
85+
})
86+
})
87+
}

rules/models/mappings/efs.hcl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import = "aws-sdk-go/models/apis/elasticfilesystem/2015-02-01/api-2.json"
22

3+
mapping "aws_efs_access_point" {
4+
file_system_id = FileSystemId
5+
posix_user = PosixUser
6+
root_directory = RootDirectory
7+
tags = Tags
8+
}
9+
10+
mapping "aws_efs_backup_policy" {
11+
file_system_id = FileSystemId
12+
backup_policy = BackupPolicy
13+
}
14+
315
mapping "aws_efs_file_system" {
416
creation_token = CreationToken
517
encrypted = Encrypted
@@ -10,6 +22,12 @@ mapping "aws_efs_file_system" {
1022
throughput_mode = ThroughputMode
1123
}
1224

25+
mapping "aws_efs_file_system_policy" {
26+
file_system_id = FileSystemId
27+
bypass_policy_lockout_safety_check = BypassPolicyLockoutSafetyCheck
28+
policy = Policy
29+
}
30+
1331
mapping "aws_efs_mount_target" {
1432
file_system_id = FileSystemId
1533
subnet_id = SubnetId

rules/models/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,14 @@ var Rules = []tflint.Rule{
464464
NewAwsEcsTaskDefinitionInvalidNetworkModeRule(),
465465
NewAwsEcsTaskDefinitionInvalidPidModeRule(),
466466
NewAwsEcsTaskSetInvalidLaunchTypeRule(),
467+
NewAwsEfsAccessPointInvalidFileSystemIDRule(),
468+
NewAwsEfsBackupPolicyInvalidFileSystemIDRule(),
467469
NewAwsEfsFileSystemInvalidCreationTokenRule(),
468470
NewAwsEfsFileSystemInvalidKmsKeyIDRule(),
469471
NewAwsEfsFileSystemInvalidPerformanceModeRule(),
470472
NewAwsEfsFileSystemInvalidThroughputModeRule(),
473+
NewAwsEfsFileSystemPolicyInvalidFileSystemIDRule(),
474+
NewAwsEfsFileSystemPolicyInvalidPolicyRule(),
471475
NewAwsEfsMountTargetInvalidFileSystemIDRule(),
472476
NewAwsEfsMountTargetInvalidIPAddressRule(),
473477
NewAwsEfsMountTargetInvalidSubnetIDRule(),

0 commit comments

Comments
 (0)