Skip to content

Commit

Permalink
mapping imagebuilder (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatMyron committed Dec 29, 2021
1 parent f60fe4d commit b3993e3
Show file tree
Hide file tree
Showing 32 changed files with 2,255 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,35 @@ These rules enforce best practices and naming conventions:
|aws_iam_user_ssh_key_invalid_public_key||
|aws_iam_user_ssh_key_invalid_status||
|aws_iam_user_ssh_key_invalid_username||
|aws_imagebuilder_component_invalid_change_description||
|aws_imagebuilder_component_invalid_data||
|aws_imagebuilder_component_invalid_description||
|aws_imagebuilder_component_invalid_kms_key_id||
|aws_imagebuilder_component_invalid_name||
|aws_imagebuilder_component_invalid_platform||
|aws_imagebuilder_component_invalid_version||
|aws_imagebuilder_distribution_configuration_invalid_description||
|aws_imagebuilder_distribution_configuration_invalid_name||
|aws_imagebuilder_image_invalid_distribution_configuration_arn||
|aws_imagebuilder_image_invalid_image_recipe_arn||
|aws_imagebuilder_image_invalid_infrastructure_configuration_arn||
|aws_imagebuilder_image_pipeline_invalid_description||
|aws_imagebuilder_image_pipeline_invalid_distribution_configuration_arn||
|aws_imagebuilder_image_pipeline_invalid_image_recipe_arn||
|aws_imagebuilder_image_pipeline_invalid_infrastructure_configuration_arn||
|aws_imagebuilder_image_pipeline_invalid_name||
|aws_imagebuilder_image_pipeline_invalid_status||
|aws_imagebuilder_image_recipe_invalid_description||
|aws_imagebuilder_image_recipe_invalid_name||
|aws_imagebuilder_image_recipe_invalid_parent_image||
|aws_imagebuilder_image_recipe_invalid_version||
|aws_imagebuilder_image_recipe_invalid_working_directory||
|aws_imagebuilder_infrastructure_configuration_invalid_description||
|aws_imagebuilder_infrastructure_configuration_invalid_instance_profile_name||
|aws_imagebuilder_infrastructure_configuration_invalid_key_pair||
|aws_imagebuilder_infrastructure_configuration_invalid_name||
|aws_imagebuilder_infrastructure_configuration_invalid_sns_topic_arn||
|aws_imagebuilder_infrastructure_configuration_invalid_subnet_id||
|aws_inspector_assessment_target_invalid_name||
|aws_inspector_assessment_target_invalid_resource_group_arn||
|aws_inspector_assessment_template_invalid_name||
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// This file generated by `generator/`. DO NOT EDIT

package models

import (
"log"

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

// AwsImagebuilderComponentInvalidChangeDescriptionRule checks the pattern is valid
type AwsImagebuilderComponentInvalidChangeDescriptionRule struct {
resourceType string
attributeName string
max int
min int
}

// NewAwsImagebuilderComponentInvalidChangeDescriptionRule returns new rule with default attributes
func NewAwsImagebuilderComponentInvalidChangeDescriptionRule() *AwsImagebuilderComponentInvalidChangeDescriptionRule {
return &AwsImagebuilderComponentInvalidChangeDescriptionRule{
resourceType: "aws_imagebuilder_component",
attributeName: "change_description",
max: 1024,
min: 1,
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsImagebuilderComponentInvalidChangeDescriptionRule) 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,
"change_description must be 1024 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"change_description must be 1 characters or higher",
attribute.Expr,
)
}
return nil
})
})
}
87 changes: 87 additions & 0 deletions rules/models/aws_imagebuilder_component_invalid_data.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"
)

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

// NewAwsImagebuilderComponentInvalidDataRule returns new rule with default attributes
func NewAwsImagebuilderComponentInvalidDataRule() *AwsImagebuilderComponentInvalidDataRule {
return &AwsImagebuilderComponentInvalidDataRule{
resourceType: "aws_imagebuilder_component",
attributeName: "data",
max: 16000,
min: 1,
pattern: regexp.MustCompile(`^[^\x00]+$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsImagebuilderComponentInvalidDataRule) 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,
"data must be 16000 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"data 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), `^[^\x00]+$`),
attribute.Expr,
)
}
return nil
})
})
}
76 changes: 76 additions & 0 deletions rules/models/aws_imagebuilder_component_invalid_description.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// This file generated by `generator/`. DO NOT EDIT

package models

import (
"log"

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

// AwsImagebuilderComponentInvalidDescriptionRule checks the pattern is valid
type AwsImagebuilderComponentInvalidDescriptionRule struct {
resourceType string
attributeName string
max int
min int
}

// NewAwsImagebuilderComponentInvalidDescriptionRule returns new rule with default attributes
func NewAwsImagebuilderComponentInvalidDescriptionRule() *AwsImagebuilderComponentInvalidDescriptionRule {
return &AwsImagebuilderComponentInvalidDescriptionRule{
resourceType: "aws_imagebuilder_component",
attributeName: "description",
max: 1024,
min: 1,
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsImagebuilderComponentInvalidDescriptionRule) 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,
"description must be 1024 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"description must be 1 characters or higher",
attribute.Expr,
)
}
return nil
})
})
}
76 changes: 76 additions & 0 deletions rules/models/aws_imagebuilder_component_invalid_kms_key_id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// This file generated by `generator/`. DO NOT EDIT

package models

import (
"log"

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

// AwsImagebuilderComponentInvalidKmsKeyIDRule checks the pattern is valid
type AwsImagebuilderComponentInvalidKmsKeyIDRule struct {
resourceType string
attributeName string
max int
min int
}

// NewAwsImagebuilderComponentInvalidKmsKeyIDRule returns new rule with default attributes
func NewAwsImagebuilderComponentInvalidKmsKeyIDRule() *AwsImagebuilderComponentInvalidKmsKeyIDRule {
return &AwsImagebuilderComponentInvalidKmsKeyIDRule{
resourceType: "aws_imagebuilder_component",
attributeName: "kms_key_id",
max: 1024,
min: 1,
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsImagebuilderComponentInvalidKmsKeyIDRule) 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,
"kms_key_id must be 1024 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"kms_key_id must be 1 characters or higher",
attribute.Expr,
)
}
return nil
})
})
}
Loading

0 comments on commit b3993e3

Please sign in to comment.