Skip to content

Commit

Permalink
mapping aws_lakeformation (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatMyron authored Dec 31, 2021
1 parent 3e7d1f5 commit 8d4e235
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ These rules enforce best practices and naming conventions:
|aws_kms_key_invalid_description||
|aws_kms_key_invalid_key_usage||
|aws_kms_key_invalid_policy||
|aws_lakeformation_resource_invalid_role_arn||
|aws_lambda_alias_invalid_description||
|aws_lambda_alias_invalid_function_name||
|aws_lambda_alias_invalid_function_version||
Expand Down
69 changes: 69 additions & 0 deletions rules/models/aws_lakeformation_resource_invalid_role_arn.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// This file generated by `generator/`. DO NOT EDIT

package models

import (
"fmt"
"log"
"regexp"

hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)

// AwsLakeformationResourceInvalidRoleArnRule checks the pattern is valid
type AwsLakeformationResourceInvalidRoleArnRule struct {
resourceType string
attributeName string
pattern *regexp.Regexp
}

// NewAwsLakeformationResourceInvalidRoleArnRule returns new rule with default attributes
func NewAwsLakeformationResourceInvalidRoleArnRule() *AwsLakeformationResourceInvalidRoleArnRule {
return &AwsLakeformationResourceInvalidRoleArnRule{
resourceType: "aws_lakeformation_resource",
attributeName: "role_arn",
pattern: regexp.MustCompile(`^arn:aws:iam::[0-9]*:role/.*$`),
}
}

// Name returns the rule name
func (r *AwsLakeformationResourceInvalidRoleArnRule) Name() string {
return "aws_lakeformation_resource_invalid_role_arn"
}

// Enabled returns whether the rule is enabled by default
func (r *AwsLakeformationResourceInvalidRoleArnRule) Enabled() bool {
return true
}

// Severity returns the rule severity
func (r *AwsLakeformationResourceInvalidRoleArnRule) Severity() string {
return tflint.ERROR
}

// Link returns the rule reference link
func (r *AwsLakeformationResourceInvalidRoleArnRule) Link() string {
return ""
}

// Check checks the pattern is valid
func (r *AwsLakeformationResourceInvalidRoleArnRule) Check(runner tflint.Runner) error {
log.Printf("[TRACE] Check `%s` rule", r.Name())

return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
var val string
err := runner.EvaluateExpr(attribute.Expr, &val, nil)

return runner.EnsureNoError(err, func() error {
if !r.pattern.MatchString(val) {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^arn:aws:iam::[0-9]*:role/.*$`),
attribute.Expr,
)
}
return nil
})
})
}
26 changes: 26 additions & 0 deletions rules/models/mappings/lakeformation.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import = "aws-sdk-go/models/apis/lakeformation/2017-03-31/api-2.json"

mapping "aws_lakeformation_data_lake_settings" {
admins = DataLakePrincipalList
# catalog_id = CatalogIdString
create_database_default_permissions = PrincipalPermissionsList
create_table_default_permissions = PrincipalPermissionsList
trusted_resource_owners = TrustedResourceOwners
}

mapping "aws_lakeformation_permissions" {
permissions = PermissionList
principal = DataLakePrincipal
catalog_resource = CatalogResource
data_location = DataLocationResource
database = DatabaseResource
table = TableResource
table_with_columns = TableWithColumnsResource
# catalog_id = CatalogIdString
permissions_with_grant_option = PermissionList
}

mapping "aws_lakeformation_resource" {
arn = ResourceArnString
role_arn = IAMRoleArn
}
1 change: 1 addition & 0 deletions rules/models/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ var Rules = []tflint.Rule{
NewAwsKmsKeyInvalidDescriptionRule(),
NewAwsKmsKeyInvalidKeyUsageRule(),
NewAwsKmsKeyInvalidPolicyRule(),
NewAwsLakeformationResourceInvalidRoleArnRule(),
NewAwsLambdaAliasInvalidDescriptionRule(),
NewAwsLambdaAliasInvalidFunctionNameRule(),
NewAwsLambdaAliasInvalidFunctionVersionRule(),
Expand Down

0 comments on commit 8d4e235

Please sign in to comment.