Skip to content

7 files changed

+351
-0
lines changed

docs/rules/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,10 @@ These rules enforce best practices and naming conventions:
14131413
|aws_worklink_website_certificate_authority_association_invalid_certificate||
14141414
|aws_worklink_website_certificate_authority_association_invalid_display_name||
14151415
|aws_worklink_website_certificate_authority_association_invalid_fleet_arn||
1416+
|aws_workspaces_directory_invalid_directory_id||
1417+
|aws_workspaces_workspace_invalid_bundle_id||
1418+
|aws_workspaces_workspace_invalid_directory_id||
1419+
|aws_workspaces_workspace_invalid_user_name||
14161420
|aws_xray_encryption_config_invalid_key_id||
14171421
|aws_xray_encryption_config_invalid_type||
14181422
|aws_xray_group_invalid_group_name||
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+
// AwsWorkspacesDirectoryInvalidDirectoryIDRule checks the pattern is valid
15+
type AwsWorkspacesDirectoryInvalidDirectoryIDRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
min int
20+
pattern *regexp.Regexp
21+
}
22+
23+
// NewAwsWorkspacesDirectoryInvalidDirectoryIDRule returns new rule with default attributes
24+
func NewAwsWorkspacesDirectoryInvalidDirectoryIDRule() *AwsWorkspacesDirectoryInvalidDirectoryIDRule {
25+
return &AwsWorkspacesDirectoryInvalidDirectoryIDRule{
26+
resourceType: "aws_workspaces_directory",
27+
attributeName: "directory_id",
28+
max: 65,
29+
min: 10,
30+
pattern: regexp.MustCompile(`^d-[0-9a-f]{8,63}$`),
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsWorkspacesDirectoryInvalidDirectoryIDRule) Name() string {
36+
return "aws_workspaces_directory_invalid_directory_id"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsWorkspacesDirectoryInvalidDirectoryIDRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsWorkspacesDirectoryInvalidDirectoryIDRule) Severity() string {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsWorkspacesDirectoryInvalidDirectoryIDRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsWorkspacesDirectoryInvalidDirectoryIDRule) 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+
"directory_id must be 65 characters or less",
67+
attribute.Expr,
68+
)
69+
}
70+
if len(val) < r.min {
71+
runner.EmitIssueOnExpr(
72+
r,
73+
"directory_id must be 10 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), `^d-[0-9a-f]{8,63}$`),
81+
attribute.Expr,
82+
)
83+
}
84+
return nil
85+
})
86+
})
87+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
// AwsWorkspacesWorkspaceInvalidBundleIDRule checks the pattern is valid
15+
type AwsWorkspacesWorkspaceInvalidBundleIDRule struct {
16+
resourceType string
17+
attributeName string
18+
pattern *regexp.Regexp
19+
}
20+
21+
// NewAwsWorkspacesWorkspaceInvalidBundleIDRule returns new rule with default attributes
22+
func NewAwsWorkspacesWorkspaceInvalidBundleIDRule() *AwsWorkspacesWorkspaceInvalidBundleIDRule {
23+
return &AwsWorkspacesWorkspaceInvalidBundleIDRule{
24+
resourceType: "aws_workspaces_workspace",
25+
attributeName: "bundle_id",
26+
pattern: regexp.MustCompile(`^wsb-[0-9a-z]{8,63}$`),
27+
}
28+
}
29+
30+
// Name returns the rule name
31+
func (r *AwsWorkspacesWorkspaceInvalidBundleIDRule) Name() string {
32+
return "aws_workspaces_workspace_invalid_bundle_id"
33+
}
34+
35+
// Enabled returns whether the rule is enabled by default
36+
func (r *AwsWorkspacesWorkspaceInvalidBundleIDRule) Enabled() bool {
37+
return true
38+
}
39+
40+
// Severity returns the rule severity
41+
func (r *AwsWorkspacesWorkspaceInvalidBundleIDRule) Severity() string {
42+
return tflint.ERROR
43+
}
44+
45+
// Link returns the rule reference link
46+
func (r *AwsWorkspacesWorkspaceInvalidBundleIDRule) Link() string {
47+
return ""
48+
}
49+
50+
// Check checks the pattern is valid
51+
func (r *AwsWorkspacesWorkspaceInvalidBundleIDRule) 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 !r.pattern.MatchString(val) {
60+
runner.EmitIssueOnExpr(
61+
r,
62+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^wsb-[0-9a-z]{8,63}$`),
63+
attribute.Expr,
64+
)
65+
}
66+
return nil
67+
})
68+
})
69+
}
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+
// AwsWorkspacesWorkspaceInvalidDirectoryIDRule checks the pattern is valid
15+
type AwsWorkspacesWorkspaceInvalidDirectoryIDRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
min int
20+
pattern *regexp.Regexp
21+
}
22+
23+
// NewAwsWorkspacesWorkspaceInvalidDirectoryIDRule returns new rule with default attributes
24+
func NewAwsWorkspacesWorkspaceInvalidDirectoryIDRule() *AwsWorkspacesWorkspaceInvalidDirectoryIDRule {
25+
return &AwsWorkspacesWorkspaceInvalidDirectoryIDRule{
26+
resourceType: "aws_workspaces_workspace",
27+
attributeName: "directory_id",
28+
max: 65,
29+
min: 10,
30+
pattern: regexp.MustCompile(`^d-[0-9a-f]{8,63}$`),
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsWorkspacesWorkspaceInvalidDirectoryIDRule) Name() string {
36+
return "aws_workspaces_workspace_invalid_directory_id"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsWorkspacesWorkspaceInvalidDirectoryIDRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsWorkspacesWorkspaceInvalidDirectoryIDRule) Severity() string {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsWorkspacesWorkspaceInvalidDirectoryIDRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsWorkspacesWorkspaceInvalidDirectoryIDRule) 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+
"directory_id must be 65 characters or less",
67+
attribute.Expr,
68+
)
69+
}
70+
if len(val) < r.min {
71+
runner.EmitIssueOnExpr(
72+
r,
73+
"directory_id must be 10 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), `^d-[0-9a-f]{8,63}$`),
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+
// AwsWorkspacesWorkspaceInvalidUserNameRule checks the pattern is valid
13+
type AwsWorkspacesWorkspaceInvalidUserNameRule struct {
14+
resourceType string
15+
attributeName string
16+
max int
17+
min int
18+
}
19+
20+
// NewAwsWorkspacesWorkspaceInvalidUserNameRule returns new rule with default attributes
21+
func NewAwsWorkspacesWorkspaceInvalidUserNameRule() *AwsWorkspacesWorkspaceInvalidUserNameRule {
22+
return &AwsWorkspacesWorkspaceInvalidUserNameRule{
23+
resourceType: "aws_workspaces_workspace",
24+
attributeName: "user_name",
25+
max: 63,
26+
min: 1,
27+
}
28+
}
29+
30+
// Name returns the rule name
31+
func (r *AwsWorkspacesWorkspaceInvalidUserNameRule) Name() string {
32+
return "aws_workspaces_workspace_invalid_user_name"
33+
}
34+
35+
// Enabled returns whether the rule is enabled by default
36+
func (r *AwsWorkspacesWorkspaceInvalidUserNameRule) Enabled() bool {
37+
return true
38+
}
39+
40+
// Severity returns the rule severity
41+
func (r *AwsWorkspacesWorkspaceInvalidUserNameRule) Severity() string {
42+
return tflint.ERROR
43+
}
44+
45+
// Link returns the rule reference link
46+
func (r *AwsWorkspacesWorkspaceInvalidUserNameRule) Link() string {
47+
return ""
48+
}
49+
50+
// Check checks the pattern is valid
51+
func (r *AwsWorkspacesWorkspaceInvalidUserNameRule) 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+
"user_name must be 63 characters or less",
63+
attribute.Expr,
64+
)
65+
}
66+
if len(val) < r.min {
67+
runner.EmitIssueOnExpr(
68+
r,
69+
"user_name must be 1 characters or higher",
70+
attribute.Expr,
71+
)
72+
}
73+
return nil
74+
})
75+
})
76+
}

rules/models/mappings/workspaces.hcl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import = "aws-sdk-go/models/apis/workspaces/2015-04-08/api-2.json"
2+
3+
mapping "aws_workspaces_directory" {
4+
directory_id = DirectoryId
5+
subnet_ids = SubnetIds
6+
ip_group_ids = IpGroupIdList
7+
tags = TagList
8+
}
9+
10+
mapping "aws_workspaces_ip_group" {
11+
name = IpGroupName
12+
description = IpGroupDesc
13+
rules = IpRuleList
14+
tags = TagList
15+
}
16+
17+
mapping "aws_workspaces_workspace" {
18+
directory_id = DirectoryId
19+
bundle_id = BundleId
20+
user_name = UserName
21+
volume_encryption_key = VolumeEncryptionKey
22+
tags = TagList
23+
workspace_properties = WorkspaceProperties
24+
}

rules/models/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,10 @@ var Rules = []tflint.Rule{
13411341
NewAwsWorklinkWebsiteCertificateAuthorityAssociationInvalidCertificateRule(),
13421342
NewAwsWorklinkWebsiteCertificateAuthorityAssociationInvalidDisplayNameRule(),
13431343
NewAwsWorklinkWebsiteCertificateAuthorityAssociationInvalidFleetArnRule(),
1344+
NewAwsWorkspacesDirectoryInvalidDirectoryIDRule(),
1345+
NewAwsWorkspacesWorkspaceInvalidBundleIDRule(),
1346+
NewAwsWorkspacesWorkspaceInvalidDirectoryIDRule(),
1347+
NewAwsWorkspacesWorkspaceInvalidUserNameRule(),
13441348
NewAwsXrayEncryptionConfigInvalidKeyIDRule(),
13451349
NewAwsXrayEncryptionConfigInvalidTypeRule(),
13461350
NewAwsXrayGroupInvalidGroupNameRule(),

0 commit comments

Comments
 (0)