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_codestarconnections #281

Merged
merged 2 commits into from
Dec 31, 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
6 changes: 6 additions & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ These rules enforce best practices and naming conventions:
|aws_codepipeline_webhook_invalid_name|✔|
|aws_codepipeline_webhook_invalid_target_action|✔|
|aws_codepipeline_webhook_invalid_target_pipeline|✔|
|aws_codestarconnections_connection_invalid_host_arn|✔|
|aws_codestarconnections_connection_invalid_name|✔|
|aws_codestarconnections_connection_invalid_provider_type|✔|
|aws_codestarconnections_host_invalid_name|✔|
|aws_codestarconnections_host_invalid_provider_endpoint|✔|
|aws_codestarconnections_host_invalid_provider_type|✔|
|aws_cognito_identity_pool_invalid_developer_provider_name|✔|
|aws_cognito_identity_pool_invalid_identity_pool_name|✔|
|aws_cognito_identity_pool_roles_attachment_invalid_identity_pool_id|✔|
Expand Down
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"
"regexp"

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

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

// NewAwsCodestarconnectionsConnectionInvalidHostArnRule returns new rule with default attributes
func NewAwsCodestarconnectionsConnectionInvalidHostArnRule() *AwsCodestarconnectionsConnectionInvalidHostArnRule {
return &AwsCodestarconnectionsConnectionInvalidHostArnRule{
resourceType: "aws_codestarconnections_connection",
attributeName: "host_arn",
max: 256,
pattern: regexp.MustCompile(`^arn:aws(-[\w]+)*:codestar-connections:.+:[0-9]{12}:host\/.+$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsCodestarconnectionsConnectionInvalidHostArnRule) 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,
"host_arn must be 256 characters or less",
attribute.Expr,
)
}
if !r.pattern.MatchString(val) {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^arn:aws(-[\w]+)*:codestar-connections:.+:[0-9]{12}:host\/.+$`),
attribute.Expr,
)
}
return nil
})
})
}
87 changes: 87 additions & 0 deletions rules/models/aws_codestarconnections_connection_invalid_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"
)

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

// NewAwsCodestarconnectionsConnectionInvalidNameRule returns new rule with default attributes
func NewAwsCodestarconnectionsConnectionInvalidNameRule() *AwsCodestarconnectionsConnectionInvalidNameRule {
return &AwsCodestarconnectionsConnectionInvalidNameRule{
resourceType: "aws_codestarconnections_connection",
attributeName: "name",
max: 32,
min: 1,
pattern: regexp.MustCompile(`^[\s\S]*$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsCodestarconnectionsConnectionInvalidNameRule) 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,
"name must be 32 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"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), `^[\s\S]*$`),
attribute.Expr,
)
}
return nil
})
})
}
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"
)

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

// NewAwsCodestarconnectionsConnectionInvalidProviderTypeRule returns new rule with default attributes
func NewAwsCodestarconnectionsConnectionInvalidProviderTypeRule() *AwsCodestarconnectionsConnectionInvalidProviderTypeRule {
return &AwsCodestarconnectionsConnectionInvalidProviderTypeRule{
resourceType: "aws_codestarconnections_connection",
attributeName: "provider_type",
enum: []string{
"Bitbucket",
"GitHub",
"GitHubEnterpriseServer",
},
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsCodestarconnectionsConnectionInvalidProviderTypeRule) 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 provider_type`, truncateLongMessage(val)),
attribute.Expr,
)
}
return nil
})
})
}
87 changes: 87 additions & 0 deletions rules/models/aws_codestarconnections_host_invalid_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"
)

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

// NewAwsCodestarconnectionsHostInvalidNameRule returns new rule with default attributes
func NewAwsCodestarconnectionsHostInvalidNameRule() *AwsCodestarconnectionsHostInvalidNameRule {
return &AwsCodestarconnectionsHostInvalidNameRule{
resourceType: "aws_codestarconnections_host",
attributeName: "name",
max: 64,
min: 1,
pattern: regexp.MustCompile(`^.*$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsCodestarconnectionsHostInvalidNameRule) 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,
"name must be 64 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"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), `^.*$`),
attribute.Expr,
)
}
return nil
})
})
}
Loading