generated from terraform-linters/tflint-ruleset-template
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathaws_acm_certificate_lifecycle_test.go
80 lines (73 loc) · 1.91 KB
/
aws_acm_certificate_lifecycle_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package rules
import (
"testing"
hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/helper"
)
func Test_AwsAcmCertificateLifecycle(t *testing.T) {
cases := []struct {
Name string
Content string
Expected helper.Issues
}{
{
Name: "no lifecycle block",
Content: `
resource "aws_acm_certificate" "test" {
domain_name = var.domain_name
validation_method = "DNS"
}`,
Expected: helper.Issues{
{
Rule: NewAwsAcmCertificateLifecycleRule(),
Message: "resource `aws_acm_certificate` needs to contain `create_before_destroy = true` in `lifecycle` block",
Range: hcl.Range{
Filename: "resource.tf",
Start: hcl.Pos{Line: 2, Column: 1},
End: hcl.Pos{Line: 2, Column: 38},
},
},
},
},
{
Name: "no create_before_destroy attribute in lifecycle block",
Content: `
resource "aws_acm_certificate" "test" {
domain_name = var.domain_name
validation_method = "DNS"
lifecycle {}
}`,
Expected: helper.Issues{
{
Rule: NewAwsAcmCertificateLifecycleRule(),
Message: "resource `aws_acm_certificate` needs to contain `create_before_destroy = true` in `lifecycle` block",
Range: hcl.Range{
Filename: "resource.tf",
Start: hcl.Pos{Line: 2, Column: 1},
End: hcl.Pos{Line: 2, Column: 38},
},
},
},
},
{
Name: "create_before_destroy = false",
Content: `
resource "aws_acm_certificate" "test" {
domain_name = var.domain_name
validation_method = "DNS"
lifecycle {
create_before_destroy = true
}
}`,
Expected: helper.Issues{},
},
}
rule := NewAwsAcmCertificateLifecycleRule()
for _, tc := range cases {
runner := helper.TestRunner(t, map[string]string{"resource.tf": tc.Content})
if err := rule.Check(runner); err != nil {
t.Fatalf("Unexpected error occurred: %s", err)
}
helper.AssertIssues(t, tc.Expected, runner.Issues)
}
}