Skip to content

Commit 6c1f13e

Browse files
committed
finish coding
1 parent 76ab2cb commit 6c1f13e

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

rules/aws_security_group_rule_deprecated.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
"github.com/terraform-linters/tflint-ruleset-aws/project"
77
)
88

9-
// TODO: Write the rule's description here
10-
// AwsSecurityGroupRuleDeprecatedRule checks ...
9+
// AwsSecurityGroupRuleDeprecatedRule checks that aws_security_group_rule is not used
1110
type AwsSecurityGroupRuleDeprecatedRule struct {
1211
tflint.DefaultRule
1312

@@ -18,9 +17,8 @@ type AwsSecurityGroupRuleDeprecatedRule struct {
1817
// NewAwsSecurityGroupRuleDeprecatedRule returns new rule with default attributes
1918
func NewAwsSecurityGroupRuleDeprecatedRule() *AwsSecurityGroupRuleDeprecatedRule {
2019
return &AwsSecurityGroupRuleDeprecatedRule{
21-
// TODO: Write resource type and attribute name here
22-
resourceType: "...",
23-
attributeName: "...",
20+
resourceType: "aws_security_group_rule",
21+
attributeName: "security_group_id",
2422
}
2523
}
2624

@@ -31,28 +29,21 @@ func (r *AwsSecurityGroupRuleDeprecatedRule) Name() string {
3129

3230
// Enabled returns whether the rule is enabled by default
3331
func (r *AwsSecurityGroupRuleDeprecatedRule) Enabled() bool {
34-
// TODO: Determine whether the rule is enabled by default
35-
return true
32+
return false
3633
}
3734

3835
// Severity returns the rule severity
3936
func (r *AwsSecurityGroupRuleDeprecatedRule) Severity() tflint.Severity {
40-
// TODO: Determine the rule's severiry
41-
return tflint.ERROR
37+
return tflint.WARNING
4238
}
4339

4440
// Link returns the rule reference link
4541
func (r *AwsSecurityGroupRuleDeprecatedRule) Link() string {
46-
// TODO: If the rule is so trivial that no documentation is needed, return "" instead.
4742
return project.ReferenceLink(r.Name())
4843
}
4944

50-
// TODO: Write the details of the inspection
51-
// Check checks ...
45+
// Check that aws_security_group_rule resource is not used
5246
func (r *AwsSecurityGroupRuleDeprecatedRule) Check(runner tflint.Runner) error {
53-
// TODO: Write the implementation here. See this documentation for what tflint.Runner can do.
54-
// https://pkg.go.dev/github.com/terraform-linters/tflint-plugin-sdk/tflint#Runner
55-
5647
resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{
5748
Attributes: []hclext.AttributeSchema{
5849
{Name: r.attributeName},

rules/aws_security_group_rule_deprecated_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,33 @@ func Test_AwsSecurityGroupRuleDeprecated(t *testing.T) {
1414
Expected helper.Issues
1515
}{
1616
{
17-
Name: "basic",
17+
Name: "resource is used",
1818
Content: `
19-
resource "null_resource" "null" {
19+
resource "aws_security_group_rule" "test" {
20+
security_group_id = "sg-12345678"
2021
}
2122
`,
2223
Expected: helper.Issues{
2324
{
2425
Rule: NewAwsSecurityGroupRuleDeprecatedRule(),
25-
Message: "TODO",
26+
Message: "Consider using aws_vpc_security_group_egress_rule or aws_vpc_security_group_ingress_rule instead.",
2627
Range: hcl.Range{
2728
Filename: "resource.tf",
28-
Start: hcl.Pos{Line: 0, Column: 0},
29-
End: hcl.Pos{Line: 0, Column: 0},
29+
Start: hcl.Pos{Line: 3, Column: 22},
30+
End: hcl.Pos{Line: 3, Column: 35},
3031
},
3132
},
3233
},
3334
},
35+
{
36+
Name: "everything is fine",
37+
Content: `
38+
resource "aws_security_group" "test" {
39+
name = "test"
40+
}
41+
`,
42+
Expected: helper.Issues{},
43+
},
3444
}
3545

3646
rule := NewAwsSecurityGroupRuleDeprecatedRule()

0 commit comments

Comments
 (0)