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_prometheus #269

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
4 changes: 4 additions & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,10 @@ These rules enforce best practices and naming conventions:
|aws_organizations_policy_invalid_name|✔|
|aws_organizations_policy_invalid_type|✔|
|aws_placement_group_invalid_strategy|✔|
|aws_prometheus_alert_manager_definition_invalid_workspace_id|✔|
|aws_prometheus_rule_group_namespace_invalid_name|✔|
|aws_prometheus_rule_group_namespace_invalid_workspace_id|✔|
|aws_prometheus_workspace_invalid_alias|✔|
|aws_quicksight_group_invalid_aws_account_id|✔|
|aws_quicksight_group_invalid_description|✔|
|aws_quicksight_group_invalid_group_name|✔|
Expand Down
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"
)

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

// NewAwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule returns new rule with default attributes
func NewAwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule() *AwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule {
return &AwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule{
resourceType: "aws_prometheus_alert_manager_definition",
attributeName: "workspace_id",
max: 64,
min: 1,
pattern: regexp.MustCompile(`^[0-9A-Za-z][-.0-9A-Z_a-z]*$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule) 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,
"workspace_id must be 64 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"workspace_id 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), `^[0-9A-Za-z][-.0-9A-Z_a-z]*$`),
attribute.Expr,
)
}
return nil
})
})
}
87 changes: 87 additions & 0 deletions rules/models/aws_prometheus_rule_group_namespace_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"
)

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

// NewAwsPrometheusRuleGroupNamespaceInvalidNameRule returns new rule with default attributes
func NewAwsPrometheusRuleGroupNamespaceInvalidNameRule() *AwsPrometheusRuleGroupNamespaceInvalidNameRule {
return &AwsPrometheusRuleGroupNamespaceInvalidNameRule{
resourceType: "aws_prometheus_rule_group_namespace",
attributeName: "name",
max: 64,
min: 1,
pattern: regexp.MustCompile(`^[0-9A-Za-z][-.0-9A-Z_a-z]*$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsPrometheusRuleGroupNamespaceInvalidNameRule) 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), `^[0-9A-Za-z][-.0-9A-Z_a-z]*$`),
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"
)

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

// NewAwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule returns new rule with default attributes
func NewAwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule() *AwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule {
return &AwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule{
resourceType: "aws_prometheus_rule_group_namespace",
attributeName: "workspace_id",
max: 64,
min: 1,
pattern: regexp.MustCompile(`^[0-9A-Za-z][-.0-9A-Z_a-z]*$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule) 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,
"workspace_id must be 64 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"workspace_id 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), `^[0-9A-Za-z][-.0-9A-Z_a-z]*$`),
attribute.Expr,
)
}
return nil
})
})
}
76 changes: 76 additions & 0 deletions rules/models/aws_prometheus_workspace_invalid_alias.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"
)

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

// NewAwsPrometheusWorkspaceInvalidAliasRule returns new rule with default attributes
func NewAwsPrometheusWorkspaceInvalidAliasRule() *AwsPrometheusWorkspaceInvalidAliasRule {
return &AwsPrometheusWorkspaceInvalidAliasRule{
resourceType: "aws_prometheus_workspace",
attributeName: "alias",
max: 100,
min: 1,
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsPrometheusWorkspaceInvalidAliasRule) 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,
"alias must be 100 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"alias must be 1 characters or higher",
attribute.Expr,
)
}
return nil
})
})
}
16 changes: 16 additions & 0 deletions rules/models/mappings/prometheus.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import = "aws-sdk-go/models/apis/amp/2020-08-01/api-2.json"

mapping "aws_prometheus_alert_manager_definition" {
workspace_id = WorkspaceId
definition = AlertManagerDefinitionData
}

mapping "aws_prometheus_rule_group_namespace" {
name = RuleGroupsNamespaceName
workspace_id = WorkspaceId
data = RuleGroupsNamespaceData
}

mapping "aws_prometheus_workspace" {
alias = WorkspaceAlias
}
4 changes: 4 additions & 0 deletions rules/models/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,10 @@ var Rules = []tflint.Rule{
NewAwsOrganizationsPolicyInvalidNameRule(),
NewAwsOrganizationsPolicyInvalidTypeRule(),
NewAwsPlacementGroupInvalidStrategyRule(),
NewAwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule(),
NewAwsPrometheusRuleGroupNamespaceInvalidNameRule(),
NewAwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule(),
NewAwsPrometheusWorkspaceInvalidAliasRule(),
NewAwsQuicksightGroupInvalidAwsAccountIDRule(),
NewAwsQuicksightGroupInvalidDescriptionRule(),
NewAwsQuicksightGroupInvalidGroupNameRule(),
Expand Down