Skip to content

7 files changed

+361
-0
lines changed

docs/rules/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,10 @@ These rules enforce best practices and naming conventions:
889889
|aws_organizations_policy_invalid_name||
890890
|aws_organizations_policy_invalid_type||
891891
|aws_placement_group_invalid_strategy||
892+
|aws_prometheus_alert_manager_definition_invalid_workspace_id||
893+
|aws_prometheus_rule_group_namespace_invalid_name||
894+
|aws_prometheus_rule_group_namespace_invalid_workspace_id||
895+
|aws_prometheus_workspace_invalid_alias||
892896
|aws_quicksight_group_invalid_aws_account_id||
893897
|aws_quicksight_group_invalid_description||
894898
|aws_quicksight_group_invalid_group_name||
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"fmt"
7+
"log"
8+
"regexp"
9+
10+
hcl "github.com/hashicorp/hcl/v2"
11+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
12+
)
13+
14+
// AwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule checks the pattern is valid
15+
type AwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
min int
20+
pattern *regexp.Regexp
21+
}
22+
23+
// NewAwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule returns new rule with default attributes
24+
func NewAwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule() *AwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule {
25+
return &AwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule{
26+
resourceType: "aws_prometheus_alert_manager_definition",
27+
attributeName: "workspace_id",
28+
max: 64,
29+
min: 1,
30+
pattern: regexp.MustCompile(`^[0-9A-Za-z][-.0-9A-Z_a-z]*$`),
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule) Name() string {
36+
return "aws_prometheus_alert_manager_definition_invalid_workspace_id"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule) Severity() string {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule) Check(runner tflint.Runner) error {
56+
log.Printf("[TRACE] Check `%s` rule", r.Name())
57+
58+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
59+
var val string
60+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
61+
62+
return runner.EnsureNoError(err, func() error {
63+
if len(val) > r.max {
64+
runner.EmitIssueOnExpr(
65+
r,
66+
"workspace_id must be 64 characters or less",
67+
attribute.Expr,
68+
)
69+
}
70+
if len(val) < r.min {
71+
runner.EmitIssueOnExpr(
72+
r,
73+
"workspace_id must be 1 characters or higher",
74+
attribute.Expr,
75+
)
76+
}
77+
if !r.pattern.MatchString(val) {
78+
runner.EmitIssueOnExpr(
79+
r,
80+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[0-9A-Za-z][-.0-9A-Z_a-z]*$`),
81+
attribute.Expr,
82+
)
83+
}
84+
return nil
85+
})
86+
})
87+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"fmt"
7+
"log"
8+
"regexp"
9+
10+
hcl "github.com/hashicorp/hcl/v2"
11+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
12+
)
13+
14+
// AwsPrometheusRuleGroupNamespaceInvalidNameRule checks the pattern is valid
15+
type AwsPrometheusRuleGroupNamespaceInvalidNameRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
min int
20+
pattern *regexp.Regexp
21+
}
22+
23+
// NewAwsPrometheusRuleGroupNamespaceInvalidNameRule returns new rule with default attributes
24+
func NewAwsPrometheusRuleGroupNamespaceInvalidNameRule() *AwsPrometheusRuleGroupNamespaceInvalidNameRule {
25+
return &AwsPrometheusRuleGroupNamespaceInvalidNameRule{
26+
resourceType: "aws_prometheus_rule_group_namespace",
27+
attributeName: "name",
28+
max: 64,
29+
min: 1,
30+
pattern: regexp.MustCompile(`^[0-9A-Za-z][-.0-9A-Z_a-z]*$`),
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsPrometheusRuleGroupNamespaceInvalidNameRule) Name() string {
36+
return "aws_prometheus_rule_group_namespace_invalid_name"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsPrometheusRuleGroupNamespaceInvalidNameRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsPrometheusRuleGroupNamespaceInvalidNameRule) Severity() string {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsPrometheusRuleGroupNamespaceInvalidNameRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsPrometheusRuleGroupNamespaceInvalidNameRule) Check(runner tflint.Runner) error {
56+
log.Printf("[TRACE] Check `%s` rule", r.Name())
57+
58+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
59+
var val string
60+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
61+
62+
return runner.EnsureNoError(err, func() error {
63+
if len(val) > r.max {
64+
runner.EmitIssueOnExpr(
65+
r,
66+
"name must be 64 characters or less",
67+
attribute.Expr,
68+
)
69+
}
70+
if len(val) < r.min {
71+
runner.EmitIssueOnExpr(
72+
r,
73+
"name must be 1 characters or higher",
74+
attribute.Expr,
75+
)
76+
}
77+
if !r.pattern.MatchString(val) {
78+
runner.EmitIssueOnExpr(
79+
r,
80+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[0-9A-Za-z][-.0-9A-Z_a-z]*$`),
81+
attribute.Expr,
82+
)
83+
}
84+
return nil
85+
})
86+
})
87+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"fmt"
7+
"log"
8+
"regexp"
9+
10+
hcl "github.com/hashicorp/hcl/v2"
11+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
12+
)
13+
14+
// AwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule checks the pattern is valid
15+
type AwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
min int
20+
pattern *regexp.Regexp
21+
}
22+
23+
// NewAwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule returns new rule with default attributes
24+
func NewAwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule() *AwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule {
25+
return &AwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule{
26+
resourceType: "aws_prometheus_rule_group_namespace",
27+
attributeName: "workspace_id",
28+
max: 64,
29+
min: 1,
30+
pattern: regexp.MustCompile(`^[0-9A-Za-z][-.0-9A-Z_a-z]*$`),
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule) Name() string {
36+
return "aws_prometheus_rule_group_namespace_invalid_workspace_id"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule) Severity() string {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule) Check(runner tflint.Runner) error {
56+
log.Printf("[TRACE] Check `%s` rule", r.Name())
57+
58+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
59+
var val string
60+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
61+
62+
return runner.EnsureNoError(err, func() error {
63+
if len(val) > r.max {
64+
runner.EmitIssueOnExpr(
65+
r,
66+
"workspace_id must be 64 characters or less",
67+
attribute.Expr,
68+
)
69+
}
70+
if len(val) < r.min {
71+
runner.EmitIssueOnExpr(
72+
r,
73+
"workspace_id must be 1 characters or higher",
74+
attribute.Expr,
75+
)
76+
}
77+
if !r.pattern.MatchString(val) {
78+
runner.EmitIssueOnExpr(
79+
r,
80+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[0-9A-Za-z][-.0-9A-Z_a-z]*$`),
81+
attribute.Expr,
82+
)
83+
}
84+
return nil
85+
})
86+
})
87+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"log"
7+
8+
hcl "github.com/hashicorp/hcl/v2"
9+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
10+
)
11+
12+
// AwsPrometheusWorkspaceInvalidAliasRule checks the pattern is valid
13+
type AwsPrometheusWorkspaceInvalidAliasRule struct {
14+
resourceType string
15+
attributeName string
16+
max int
17+
min int
18+
}
19+
20+
// NewAwsPrometheusWorkspaceInvalidAliasRule returns new rule with default attributes
21+
func NewAwsPrometheusWorkspaceInvalidAliasRule() *AwsPrometheusWorkspaceInvalidAliasRule {
22+
return &AwsPrometheusWorkspaceInvalidAliasRule{
23+
resourceType: "aws_prometheus_workspace",
24+
attributeName: "alias",
25+
max: 100,
26+
min: 1,
27+
}
28+
}
29+
30+
// Name returns the rule name
31+
func (r *AwsPrometheusWorkspaceInvalidAliasRule) Name() string {
32+
return "aws_prometheus_workspace_invalid_alias"
33+
}
34+
35+
// Enabled returns whether the rule is enabled by default
36+
func (r *AwsPrometheusWorkspaceInvalidAliasRule) Enabled() bool {
37+
return true
38+
}
39+
40+
// Severity returns the rule severity
41+
func (r *AwsPrometheusWorkspaceInvalidAliasRule) Severity() string {
42+
return tflint.ERROR
43+
}
44+
45+
// Link returns the rule reference link
46+
func (r *AwsPrometheusWorkspaceInvalidAliasRule) Link() string {
47+
return ""
48+
}
49+
50+
// Check checks the pattern is valid
51+
func (r *AwsPrometheusWorkspaceInvalidAliasRule) Check(runner tflint.Runner) error {
52+
log.Printf("[TRACE] Check `%s` rule", r.Name())
53+
54+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
55+
var val string
56+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
57+
58+
return runner.EnsureNoError(err, func() error {
59+
if len(val) > r.max {
60+
runner.EmitIssueOnExpr(
61+
r,
62+
"alias must be 100 characters or less",
63+
attribute.Expr,
64+
)
65+
}
66+
if len(val) < r.min {
67+
runner.EmitIssueOnExpr(
68+
r,
69+
"alias must be 1 characters or higher",
70+
attribute.Expr,
71+
)
72+
}
73+
return nil
74+
})
75+
})
76+
}

rules/models/mappings/prometheus.hcl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import = "aws-sdk-go/models/apis/amp/2020-08-01/api-2.json"
2+
3+
mapping "aws_prometheus_alert_manager_definition" {
4+
workspace_id = WorkspaceId
5+
definition = AlertManagerDefinitionData
6+
}
7+
8+
mapping "aws_prometheus_rule_group_namespace" {
9+
name = RuleGroupsNamespaceName
10+
workspace_id = WorkspaceId
11+
data = RuleGroupsNamespaceData
12+
}
13+
14+
mapping "aws_prometheus_workspace" {
15+
alias = WorkspaceAlias
16+
}

rules/models/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,10 @@ var Rules = []tflint.Rule{
817817
NewAwsOrganizationsPolicyInvalidNameRule(),
818818
NewAwsOrganizationsPolicyInvalidTypeRule(),
819819
NewAwsPlacementGroupInvalidStrategyRule(),
820+
NewAwsPrometheusAlertManagerDefinitionInvalidWorkspaceIDRule(),
821+
NewAwsPrometheusRuleGroupNamespaceInvalidNameRule(),
822+
NewAwsPrometheusRuleGroupNamespaceInvalidWorkspaceIDRule(),
823+
NewAwsPrometheusWorkspaceInvalidAliasRule(),
820824
NewAwsQuicksightGroupInvalidAwsAccountIDRule(),
821825
NewAwsQuicksightGroupInvalidDescriptionRule(),
822826
NewAwsQuicksightGroupInvalidGroupNameRule(),

0 commit comments

Comments
 (0)