Skip to content
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

mapping aws_accessanalyzer_analyzer #223

Merged
merged 2 commits into from
Dec 23, 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
2 changes: 2 additions & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ These rules enforce best practices and naming conventions:

|Rule|Enabled by default|
| --- | --- |
|aws_accessanalyzer_analyzer_invalid_analyzer_name|✔|
|aws_accessanalyzer_analyzer_invalid_type|✔|
|aws_acm_certificate_invalid_certificate_body|✔|
|aws_acm_certificate_invalid_certificate_chain|✔|
|aws_acm_certificate_invalid_private_key|✔|
Expand Down
87 changes: 87 additions & 0 deletions rules/models/aws_accessanalyzer_analyzer_invalid_analyzer_name.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"
)

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

// NewAwsAccessanalyzerAnalyzerInvalidAnalyzerNameRule returns new rule with default attributes
func NewAwsAccessanalyzerAnalyzerInvalidAnalyzerNameRule() *AwsAccessanalyzerAnalyzerInvalidAnalyzerNameRule {
return &AwsAccessanalyzerAnalyzerInvalidAnalyzerNameRule{
resourceType: "aws_accessanalyzer_analyzer",
attributeName: "analyzer_name",
max: 255,
min: 1,
pattern: regexp.MustCompile(`^[A-Za-z][A-Za-z0-9_.-]*$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsAccessanalyzerAnalyzerInvalidAnalyzerNameRule) 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,
"analyzer_name must be 255 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"analyzer_name 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), `^[A-Za-z][A-Za-z0-9_.-]*$`),
attribute.Expr,
)
}
return nil
})
})
}
77 changes: 77 additions & 0 deletions rules/models/aws_accessanalyzer_analyzer_invalid_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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"
)

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

// NewAwsAccessanalyzerAnalyzerInvalidTypeRule returns new rule with default attributes
func NewAwsAccessanalyzerAnalyzerInvalidTypeRule() *AwsAccessanalyzerAnalyzerInvalidTypeRule {
return &AwsAccessanalyzerAnalyzerInvalidTypeRule{
resourceType: "aws_accessanalyzer_analyzer",
attributeName: "type",
enum: []string{
"ACCOUNT",
"ORGANIZATION",
},
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsAccessanalyzerAnalyzerInvalidTypeRule) 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 type`, truncateLongMessage(val)),
attribute.Expr,
)
}
return nil
})
})
}
7 changes: 7 additions & 0 deletions rules/models/mappings/access-analyzer.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import = "aws-sdk-go/models/apis/accessanalyzer/2019-11-01/api-2.json"

mapping "aws_accessanalyzer_analyzer" {
analyzer_name = Name
tags = TagsMap
type = Type
}
2 changes: 2 additions & 0 deletions rules/models/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "github.com/terraform-linters/tflint-plugin-sdk/tflint"

// Rules is a list of rules generated from aws-sdk-go
var Rules = []tflint.Rule{
NewAwsAccessanalyzerAnalyzerInvalidAnalyzerNameRule(),
NewAwsAccessanalyzerAnalyzerInvalidTypeRule(),
NewAwsAcmCertificateInvalidCertificateBodyRule(),
NewAwsAcmCertificateInvalidCertificateChainRule(),
NewAwsAcmCertificateInvalidPrivateKeyRule(),
Expand Down