Skip to content

Commit b2d425a

Browse files
authored
aws_elasticache_replication_group_api - add aws_elasticache_replication_group api rules (#152)
1 parent 90948bf commit b2d425a

5 files changed

+283
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// This file generated by `generator/main.go`. DO NOT EDIT
2+
3+
package api
4+
5+
import (
6+
"fmt"
7+
"log"
8+
9+
hcl "github.com/hashicorp/hcl/v2"
10+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
11+
"github.com/terraform-linters/tflint-ruleset-aws/aws"
12+
)
13+
14+
// AwsElastiCacheReplicationGroupInvalidParameterGroupRule checks whether attribute value actually exists
15+
type AwsElastiCacheReplicationGroupInvalidParameterGroupRule struct {
16+
resourceType string
17+
attributeName string
18+
data map[string]bool
19+
dataPrepared bool
20+
}
21+
22+
// NewAwsElastiCacheReplicationGroupInvalidParameterGroupRule returns new rule with default attributes
23+
func NewAwsElastiCacheReplicationGroupInvalidParameterGroupRule() *AwsElastiCacheReplicationGroupInvalidParameterGroupRule {
24+
return &AwsElastiCacheReplicationGroupInvalidParameterGroupRule{
25+
resourceType: "aws_elasticache_replication_group",
26+
attributeName: "parameter_group_name",
27+
data: map[string]bool{},
28+
dataPrepared: false,
29+
}
30+
}
31+
32+
// Name returns the rule name
33+
func (r *AwsElastiCacheReplicationGroupInvalidParameterGroupRule) Name() string {
34+
return "aws_elasticache_replication_group_invalid_parameter_group"
35+
}
36+
37+
// Enabled returns whether the rule is enabled by default
38+
func (r *AwsElastiCacheReplicationGroupInvalidParameterGroupRule) Enabled() bool {
39+
return true
40+
}
41+
42+
// Severity returns the rule severity
43+
func (r *AwsElastiCacheReplicationGroupInvalidParameterGroupRule) Severity() string {
44+
return tflint.ERROR
45+
}
46+
47+
// Link returns the rule reference link
48+
func (r *AwsElastiCacheReplicationGroupInvalidParameterGroupRule) Link() string {
49+
return ""
50+
}
51+
52+
// Check checks whether the attributes are included in the list retrieved by DescribeCacheParameterGroups
53+
func (r *AwsElastiCacheReplicationGroupInvalidParameterGroupRule) Check(rr tflint.Runner) error {
54+
runner := rr.(*aws.Runner)
55+
56+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
57+
if !r.dataPrepared {
58+
log.Print("[DEBUG] invoking DescribeCacheParameterGroups")
59+
var err error
60+
r.data, err = runner.AwsClient.DescribeCacheParameterGroups()
61+
if err != nil {
62+
err := &tflint.Error{
63+
Code: tflint.ExternalAPIError,
64+
Level: tflint.ErrorLevel,
65+
Message: "An error occurred while invoking DescribeCacheParameterGroups",
66+
Cause: err,
67+
}
68+
log.Printf("[ERROR] %s", err)
69+
return err
70+
}
71+
r.dataPrepared = true
72+
}
73+
74+
var val string
75+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
76+
77+
return runner.EnsureNoError(err, func() error {
78+
if !r.data[val] {
79+
runner.EmitIssueOnExpr(
80+
r,
81+
fmt.Sprintf(`"%s" is invalid parameter group name.`, val),
82+
attribute.Expr,
83+
)
84+
}
85+
return nil
86+
})
87+
})
88+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// This file generated by `generator/main.go`. DO NOT EDIT
2+
3+
package api
4+
5+
import (
6+
"fmt"
7+
"log"
8+
9+
hcl "github.com/hashicorp/hcl/v2"
10+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
11+
"github.com/terraform-linters/tflint-ruleset-aws/aws"
12+
)
13+
14+
// AwsElastiCacheReplicationGroupInvalidSecurityGroupRule checks whether attribute value actually exists
15+
type AwsElastiCacheReplicationGroupInvalidSecurityGroupRule struct {
16+
resourceType string
17+
attributeName string
18+
data map[string]bool
19+
dataPrepared bool
20+
}
21+
22+
// NewAwsElastiCacheReplicationGroupInvalidSecurityGroupRule returns new rule with default attributes
23+
func NewAwsElastiCacheReplicationGroupInvalidSecurityGroupRule() *AwsElastiCacheReplicationGroupInvalidSecurityGroupRule {
24+
return &AwsElastiCacheReplicationGroupInvalidSecurityGroupRule{
25+
resourceType: "aws_elasticache_replication_group",
26+
attributeName: "security_group_ids",
27+
data: map[string]bool{},
28+
dataPrepared: false,
29+
}
30+
}
31+
32+
// Name returns the rule name
33+
func (r *AwsElastiCacheReplicationGroupInvalidSecurityGroupRule) Name() string {
34+
return "aws_elasticache_replication_group_invalid_security_group"
35+
}
36+
37+
// Enabled returns whether the rule is enabled by default
38+
func (r *AwsElastiCacheReplicationGroupInvalidSecurityGroupRule) Enabled() bool {
39+
return true
40+
}
41+
42+
// Severity returns the rule severity
43+
func (r *AwsElastiCacheReplicationGroupInvalidSecurityGroupRule) Severity() string {
44+
return tflint.ERROR
45+
}
46+
47+
// Link returns the rule reference link
48+
func (r *AwsElastiCacheReplicationGroupInvalidSecurityGroupRule) Link() string {
49+
return ""
50+
}
51+
52+
// Check checks whether the attributes are included in the list retrieved by DescribeSecurityGroups
53+
func (r *AwsElastiCacheReplicationGroupInvalidSecurityGroupRule) Check(rr tflint.Runner) error {
54+
runner := rr.(*aws.Runner)
55+
56+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
57+
if !r.dataPrepared {
58+
log.Print("[DEBUG] invoking DescribeSecurityGroups")
59+
var err error
60+
r.data, err = runner.AwsClient.DescribeSecurityGroups()
61+
if err != nil {
62+
err := &tflint.Error{
63+
Code: tflint.ExternalAPIError,
64+
Level: tflint.ErrorLevel,
65+
Message: "An error occurred while invoking DescribeSecurityGroups",
66+
Cause: err,
67+
}
68+
log.Printf("[ERROR] %s", err)
69+
return err
70+
}
71+
r.dataPrepared = true
72+
}
73+
74+
return runner.EachStringSliceExprs(attribute.Expr, func(val string, expr hcl.Expression) {
75+
if !r.data[val] {
76+
runner.EmitIssueOnExpr(
77+
r,
78+
fmt.Sprintf(`"%s" is invalid security group.`, val),
79+
expr,
80+
)
81+
}
82+
})
83+
})
84+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// This file generated by `generator/main.go`. DO NOT EDIT
2+
3+
package api
4+
5+
import (
6+
"fmt"
7+
"log"
8+
9+
hcl "github.com/hashicorp/hcl/v2"
10+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
11+
"github.com/terraform-linters/tflint-ruleset-aws/aws"
12+
)
13+
14+
// AwsElastiCacheReplicationGroupInvalidSubnetGroupRule checks whether attribute value actually exists
15+
type AwsElastiCacheReplicationGroupInvalidSubnetGroupRule struct {
16+
resourceType string
17+
attributeName string
18+
data map[string]bool
19+
dataPrepared bool
20+
}
21+
22+
// NewAwsElastiCacheReplicationGroupInvalidSubnetGroupRule returns new rule with default attributes
23+
func NewAwsElastiCacheReplicationGroupInvalidSubnetGroupRule() *AwsElastiCacheReplicationGroupInvalidSubnetGroupRule {
24+
return &AwsElastiCacheReplicationGroupInvalidSubnetGroupRule{
25+
resourceType: "aws_elasticache_replication_group",
26+
attributeName: "subnet_group_name",
27+
data: map[string]bool{},
28+
dataPrepared: false,
29+
}
30+
}
31+
32+
// Name returns the rule name
33+
func (r *AwsElastiCacheReplicationGroupInvalidSubnetGroupRule) Name() string {
34+
return "aws_elasticache_replication_group_invalid_subnet_group"
35+
}
36+
37+
// Enabled returns whether the rule is enabled by default
38+
func (r *AwsElastiCacheReplicationGroupInvalidSubnetGroupRule) Enabled() bool {
39+
return true
40+
}
41+
42+
// Severity returns the rule severity
43+
func (r *AwsElastiCacheReplicationGroupInvalidSubnetGroupRule) Severity() string {
44+
return tflint.ERROR
45+
}
46+
47+
// Link returns the rule reference link
48+
func (r *AwsElastiCacheReplicationGroupInvalidSubnetGroupRule) Link() string {
49+
return ""
50+
}
51+
52+
// Check checks whether the attributes are included in the list retrieved by DescribeCacheSubnetGroups
53+
func (r *AwsElastiCacheReplicationGroupInvalidSubnetGroupRule) Check(rr tflint.Runner) error {
54+
runner := rr.(*aws.Runner)
55+
56+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
57+
if !r.dataPrepared {
58+
log.Print("[DEBUG] invoking DescribeCacheSubnetGroups")
59+
var err error
60+
r.data, err = runner.AwsClient.DescribeCacheSubnetGroups()
61+
if err != nil {
62+
err := &tflint.Error{
63+
Code: tflint.ExternalAPIError,
64+
Level: tflint.ErrorLevel,
65+
Message: "An error occurred while invoking DescribeCacheSubnetGroups",
66+
Cause: err,
67+
}
68+
log.Printf("[ERROR] %s", err)
69+
return err
70+
}
71+
r.dataPrepared = true
72+
}
73+
74+
var val string
75+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
76+
77+
return runner.EnsureNoError(err, func() error {
78+
if !r.data[val] {
79+
runner.EmitIssueOnExpr(
80+
r,
81+
fmt.Sprintf(`"%s" is invalid subnet group name.`, val),
82+
attribute.Expr,
83+
)
84+
}
85+
return nil
86+
})
87+
})
88+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
rule "aws_elasticache_replication_group_invalid_parameter_group" {
2+
resource = "aws_elasticache_replication_group"
3+
attribute = "parameter_group_name"
4+
source_action = "DescribeCacheParameterGroups"
5+
template = "\"%s\" is invalid parameter group name."
6+
}
7+
8+
rule "aws_elasticache_replication_group_invalid_security_group" {
9+
resource = "aws_elasticache_replication_group"
10+
attribute = "security_group_ids"
11+
source_action = "DescribeSecurityGroups"
12+
template = "\"%s\" is invalid security group."
13+
}
14+
15+
rule "aws_elasticache_replication_group_invalid_subnet_group" {
16+
resource = "aws_elasticache_replication_group"
17+
attribute = "subnet_group_name"
18+
source_action = "DescribeCacheSubnetGroups"
19+
template = "\"%s\" is invalid subnet group name."
20+
}

rules/api/provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ var Rules = []tflint.Rule{
2020
NewAwsElastiCacheClusterInvalidParameterGroupRule(),
2121
NewAwsElastiCacheClusterInvalidSecurityGroupRule(),
2222
NewAwsElastiCacheClusterInvalidSubnetGroupRule(),
23+
NewAwsElastiCacheReplicationGroupInvalidParameterGroupRule(),
24+
NewAwsElastiCacheReplicationGroupInvalidSecurityGroupRule(),
25+
NewAwsElastiCacheReplicationGroupInvalidSubnetGroupRule(),
2326
NewAwsInstanceInvalidIAMProfileRule(),
2427
NewAwsInstanceInvalidKeyNameRule(),
2528
NewAwsInstanceInvalidSubnetRule(),

0 commit comments

Comments
 (0)