Skip to content

mapping aws_glue #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,18 @@ These rules enforce best practices and naming conventions:
|aws_glue_connection_invalid_connection_type|✔|
|aws_glue_crawler_invalid_security_configuration|✔|
|aws_glue_crawler_invalid_table_prefix|✔|
|aws_glue_dev_endpoint_invalid_role_arn|✔|
|aws_glue_dev_endpoint_invalid_worker_type|✔|
|aws_glue_ml_transform_invalid_glue_version|✔|
|aws_glue_ml_transform_invalid_worker_type|✔|
|aws_glue_registry_invalid_registry_name|✔|
|aws_glue_resource_policy_invalid_enable_hybrid|✔|
|aws_glue_schema_invalid_compatibility|✔|
|aws_glue_schema_invalid_data_format|✔|
|aws_glue_schema_invalid_schema_definition|✔|
|aws_glue_schema_invalid_schema_name|✔|
|aws_glue_trigger_invalid_type|✔|
|aws_glue_user_defined_function_invalid_owner_type|✔|
|aws_guardduty_detector_invalid_finding_publishing_frequency|✔|
|aws_guardduty_invite_accepter_invalid_detector_id|✔|
|aws_guardduty_ipset_invalid_detector_id|✔|
Expand Down
69 changes: 69 additions & 0 deletions rules/models/aws_glue_dev_endpoint_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"
)

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

// NewAwsGlueDevEndpointInvalidRoleArnRule returns new rule with default attributes
func NewAwsGlueDevEndpointInvalidRoleArnRule() *AwsGlueDevEndpointInvalidRoleArnRule {
return &AwsGlueDevEndpointInvalidRoleArnRule{
resourceType: "aws_glue_dev_endpoint",
attributeName: "role_arn",
pattern: regexp.MustCompile(`^arn:aws:iam::\d{12}:role/.*$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsGlueDevEndpointInvalidRoleArnRule) 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::\d{12}:role/.*$`),
attribute.Expr,
)
}
return nil
})
})
}
78 changes: 78 additions & 0 deletions rules/models/aws_glue_dev_endpoint_invalid_worker_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// This file generated by `generator/`. DO NOT EDIT

package models

import (
"fmt"
"log"

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

// AwsGlueDevEndpointInvalidWorkerTypeRule checks the pattern is valid
type AwsGlueDevEndpointInvalidWorkerTypeRule struct {
resourceType string
attributeName string
enum []string
}

// NewAwsGlueDevEndpointInvalidWorkerTypeRule returns new rule with default attributes
func NewAwsGlueDevEndpointInvalidWorkerTypeRule() *AwsGlueDevEndpointInvalidWorkerTypeRule {
return &AwsGlueDevEndpointInvalidWorkerTypeRule{
resourceType: "aws_glue_dev_endpoint",
attributeName: "worker_type",
enum: []string{
"Standard",
"G.1X",
"G.2X",
},
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsGlueDevEndpointInvalidWorkerTypeRule) 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 {
found := false
for _, item := range r.enum {
if item == val {
found = true
}
}
if !found {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" is an invalid value as worker_type`, truncateLongMessage(val)),
attribute.Expr,
)
}
return nil
})
})
}
87 changes: 87 additions & 0 deletions rules/models/aws_glue_ml_transform_invalid_glue_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// 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"
)

// AwsGlueMlTransformInvalidGlueVersionRule checks the pattern is valid
type AwsGlueMlTransformInvalidGlueVersionRule struct {
resourceType string
attributeName string
max int
min int
pattern *regexp.Regexp
}

// NewAwsGlueMlTransformInvalidGlueVersionRule returns new rule with default attributes
func NewAwsGlueMlTransformInvalidGlueVersionRule() *AwsGlueMlTransformInvalidGlueVersionRule {
return &AwsGlueMlTransformInvalidGlueVersionRule{
resourceType: "aws_glue_ml_transform",
attributeName: "glue_version",
max: 255,
min: 1,
pattern: regexp.MustCompile(`^\w+\.\w+$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsGlueMlTransformInvalidGlueVersionRule) 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 len(val) > r.max {
runner.EmitIssueOnExpr(
r,
"glue_version must be 255 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"glue_version must be 1 characters or higher",
attribute.Expr,
)
}
if !r.pattern.MatchString(val) {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^\w+\.\w+$`),
attribute.Expr,
)
}
return nil
})
})
}
78 changes: 78 additions & 0 deletions rules/models/aws_glue_ml_transform_invalid_worker_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// This file generated by `generator/`. DO NOT EDIT

package models

import (
"fmt"
"log"

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

// AwsGlueMlTransformInvalidWorkerTypeRule checks the pattern is valid
type AwsGlueMlTransformInvalidWorkerTypeRule struct {
resourceType string
attributeName string
enum []string
}

// NewAwsGlueMlTransformInvalidWorkerTypeRule returns new rule with default attributes
func NewAwsGlueMlTransformInvalidWorkerTypeRule() *AwsGlueMlTransformInvalidWorkerTypeRule {
return &AwsGlueMlTransformInvalidWorkerTypeRule{
resourceType: "aws_glue_ml_transform",
attributeName: "worker_type",
enum: []string{
"Standard",
"G.1X",
"G.2X",
},
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsGlueMlTransformInvalidWorkerTypeRule) 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 {
found := false
for _, item := range r.enum {
if item == val {
found = true
}
}
if !found {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" is an invalid value as worker_type`, truncateLongMessage(val)),
attribute.Expr,
)
}
return nil
})
})
}
Loading