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_quicksight #270

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
13 changes: 13 additions & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -893,10 +893,23 @@ These rules enforce best practices and naming conventions:
|aws_prometheus_rule_group_namespace_invalid_name|✔|
|aws_prometheus_rule_group_namespace_invalid_workspace_id|✔|
|aws_prometheus_workspace_invalid_alias|✔|
|aws_quicksight_data_source_invalid_aws_account_id|✔|
|aws_quicksight_data_source_invalid_name|✔|
|aws_quicksight_data_source_invalid_type|✔|
|aws_quicksight_group_invalid_aws_account_id|✔|
|aws_quicksight_group_invalid_description|✔|
|aws_quicksight_group_invalid_group_name|✔|
|aws_quicksight_group_invalid_namespace|✔|
|aws_quicksight_group_membership_invalid_aws_account_id|✔|
|aws_quicksight_group_membership_invalid_group_name|✔|
|aws_quicksight_group_membership_invalid_member_name|✔|
|aws_quicksight_group_membership_invalid_namespace|✔|
|aws_quicksight_user_invalid_aws_account_id|✔|
|aws_quicksight_user_invalid_identity_type|✔|
|aws_quicksight_user_invalid_namespace|✔|
|aws_quicksight_user_invalid_session_name|✔|
|aws_quicksight_user_invalid_user_name|✔|
|aws_quicksight_user_invalid_user_role|✔|
|aws_redshift_cluster_invalid_availability_zone|✔|
|aws_redshift_cluster_invalid_cluster_identifier|✔|
|aws_redshift_cluster_invalid_cluster_parameter_group_name|✔|
Expand Down
87 changes: 87 additions & 0 deletions rules/models/aws_quicksight_data_source_invalid_aws_account_id.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"
)

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

// NewAwsQuicksightDataSourceInvalidAwsAccountIDRule returns new rule with default attributes
func NewAwsQuicksightDataSourceInvalidAwsAccountIDRule() *AwsQuicksightDataSourceInvalidAwsAccountIDRule {
return &AwsQuicksightDataSourceInvalidAwsAccountIDRule{
resourceType: "aws_quicksight_data_source",
attributeName: "aws_account_id",
max: 12,
min: 12,
pattern: regexp.MustCompile(`^[0-9]{12}$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsQuicksightDataSourceInvalidAwsAccountIDRule) 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,
"aws_account_id must be 12 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"aws_account_id must be 12 characters or higher",
attribute.Expr,
)
}
if !r.pattern.MatchString(val) {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[0-9]{12}$`),
attribute.Expr,
)
}
return nil
})
})
}
76 changes: 76 additions & 0 deletions rules/models/aws_quicksight_data_source_invalid_name.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"
)

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

// NewAwsQuicksightDataSourceInvalidNameRule returns new rule with default attributes
func NewAwsQuicksightDataSourceInvalidNameRule() *AwsQuicksightDataSourceInvalidNameRule {
return &AwsQuicksightDataSourceInvalidNameRule{
resourceType: "aws_quicksight_data_source",
attributeName: "name",
max: 128,
min: 1,
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsQuicksightDataSourceInvalidNameRule) 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 128 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"name must be 1 characters or higher",
attribute.Expr,
)
}
return nil
})
})
}
100 changes: 100 additions & 0 deletions rules/models/aws_quicksight_data_source_invalid_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// 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"
)

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

// NewAwsQuicksightDataSourceInvalidTypeRule returns new rule with default attributes
func NewAwsQuicksightDataSourceInvalidTypeRule() *AwsQuicksightDataSourceInvalidTypeRule {
return &AwsQuicksightDataSourceInvalidTypeRule{
resourceType: "aws_quicksight_data_source",
attributeName: "type",
enum: []string{
"ADOBE_ANALYTICS",
"AMAZON_ELASTICSEARCH",
"ATHENA",
"AURORA",
"AURORA_POSTGRESQL",
"AWS_IOT_ANALYTICS",
"GITHUB",
"JIRA",
"MARIADB",
"MYSQL",
"ORACLE",
"POSTGRESQL",
"PRESTO",
"REDSHIFT",
"S3",
"SALESFORCE",
"SERVICENOW",
"SNOWFLAKE",
"SPARK",
"SQLSERVER",
"TERADATA",
"TWITTER",
"TIMESTREAM",
"AMAZON_OPENSEARCH",
"EXASOL",
},
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsQuicksightDataSourceInvalidTypeRule) 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
})
})
}
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"
)

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

// NewAwsQuicksightGroupMembershipInvalidAwsAccountIDRule returns new rule with default attributes
func NewAwsQuicksightGroupMembershipInvalidAwsAccountIDRule() *AwsQuicksightGroupMembershipInvalidAwsAccountIDRule {
return &AwsQuicksightGroupMembershipInvalidAwsAccountIDRule{
resourceType: "aws_quicksight_group_membership",
attributeName: "aws_account_id",
max: 12,
min: 12,
pattern: regexp.MustCompile(`^[0-9]{12}$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsQuicksightGroupMembershipInvalidAwsAccountIDRule) 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,
"aws_account_id must be 12 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"aws_account_id must be 12 characters or higher",
attribute.Expr,
)
}
if !r.pattern.MatchString(val) {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[0-9]{12}$`),
attribute.Expr,
)
}
return nil
})
})
}
Loading