Skip to content

Commit 8d4e235

Browse files

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

docs/rules/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ These rules enforce best practices and naming conventions:
783783
|aws_kms_key_invalid_description||
784784
|aws_kms_key_invalid_key_usage||
785785
|aws_kms_key_invalid_policy||
786+
|aws_lakeformation_resource_invalid_role_arn||
786787
|aws_lambda_alias_invalid_description||
787788
|aws_lambda_alias_invalid_function_name||
788789
|aws_lambda_alias_invalid_function_version||
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+
// AwsLakeformationResourceInvalidRoleArnRule checks the pattern is valid
15+
type AwsLakeformationResourceInvalidRoleArnRule struct {
16+
resourceType string
17+
attributeName string
18+
pattern *regexp.Regexp
19+
}
20+
21+
// NewAwsLakeformationResourceInvalidRoleArnRule returns new rule with default attributes
22+
func NewAwsLakeformationResourceInvalidRoleArnRule() *AwsLakeformationResourceInvalidRoleArnRule {
23+
return &AwsLakeformationResourceInvalidRoleArnRule{
24+
resourceType: "aws_lakeformation_resource",
25+
attributeName: "role_arn",
26+
pattern: regexp.MustCompile(`^arn:aws:iam::[0-9]*:role/.*$`),
27+
}
28+
}
29+
30+
// Name returns the rule name
31+
func (r *AwsLakeformationResourceInvalidRoleArnRule) Name() string {
32+
return "aws_lakeformation_resource_invalid_role_arn"
33+
}
34+
35+
// Enabled returns whether the rule is enabled by default
36+
func (r *AwsLakeformationResourceInvalidRoleArnRule) Enabled() bool {
37+
return true
38+
}
39+
40+
// Severity returns the rule severity
41+
func (r *AwsLakeformationResourceInvalidRoleArnRule) Severity() string {
42+
return tflint.ERROR
43+
}
44+
45+
// Link returns the rule reference link
46+
func (r *AwsLakeformationResourceInvalidRoleArnRule) Link() string {
47+
return ""
48+
}
49+
50+
// Check checks the pattern is valid
51+
func (r *AwsLakeformationResourceInvalidRoleArnRule) 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), `^arn:aws:iam::[0-9]*:role/.*$`),
63+
attribute.Expr,
64+
)
65+
}
66+
return nil
67+
})
68+
})
69+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import = "aws-sdk-go/models/apis/lakeformation/2017-03-31/api-2.json"
2+
3+
mapping "aws_lakeformation_data_lake_settings" {
4+
admins = DataLakePrincipalList
5+
# catalog_id = CatalogIdString
6+
create_database_default_permissions = PrincipalPermissionsList
7+
create_table_default_permissions = PrincipalPermissionsList
8+
trusted_resource_owners = TrustedResourceOwners
9+
}
10+
11+
mapping "aws_lakeformation_permissions" {
12+
permissions = PermissionList
13+
principal = DataLakePrincipal
14+
catalog_resource = CatalogResource
15+
data_location = DataLocationResource
16+
database = DatabaseResource
17+
table = TableResource
18+
table_with_columns = TableWithColumnsResource
19+
# catalog_id = CatalogIdString
20+
permissions_with_grant_option = PermissionList
21+
}
22+
23+
mapping "aws_lakeformation_resource" {
24+
arn = ResourceArnString
25+
role_arn = IAMRoleArn
26+
}

rules/models/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ var Rules = []tflint.Rule{
711711
NewAwsKmsKeyInvalidDescriptionRule(),
712712
NewAwsKmsKeyInvalidKeyUsageRule(),
713713
NewAwsKmsKeyInvalidPolicyRule(),
714+
NewAwsLakeformationResourceInvalidRoleArnRule(),
714715
NewAwsLambdaAliasInvalidDescriptionRule(),
715716
NewAwsLambdaAliasInvalidFunctionNameRule(),
716717
NewAwsLambdaAliasInvalidFunctionVersionRule(),

0 commit comments

Comments
 (0)