Skip to content

Commit 2ba747c

Browse files
bendruckerwata727
andauthored
aws_acm_certificate: fix false positive for private CA (#455)
* `aws_acm_certificate`: fix false positive for private CA * Use "%s" instead of %q %q escapes tab char to \t --------- Co-authored-by: Kazuma Watanabe <[email protected]>
1 parent bfee73b commit 2ba747c

File tree

149 files changed

+353
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+353
-150
lines changed

rules/models/aws_acm_certificate_invalid_certificate_authority_arn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewAwsAcmCertificateInvalidCertificateAuthorityArnRule() *AwsAcmCertificate
2929
attributeName: "certificate_authority_arn",
3030
max: 2048,
3131
min: 20,
32-
pattern: regexp.MustCompile(`^arn:[\w+=/,.@-]+:acm:[\w+=/,.@-]*:[0-9]+:[\w+=,.@-]+(/[\w+=,.@-]+)*$`),
32+
pattern: regexp.MustCompile(`^arn:[\w+=/,.@-]+:acm-pca:[\w+=/,.@-]*:[0-9]+:[\w+=,.@-]+(/[\w+=,.@-]+)*$`),
3333
}
3434
}
3535

@@ -93,7 +93,7 @@ func (r *AwsAcmCertificateInvalidCertificateAuthorityArnRule) Check(runner tflin
9393
if !r.pattern.MatchString(val) {
9494
runner.EmitIssue(
9595
r,
96-
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^arn:[\w+=/,.@-]+:acm:[\w+=/,.@-]*:[0-9]+:[\w+=,.@-]+(/[\w+=,.@-]+)*$`),
96+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^arn:[\w+=/,.@-]+:acm-pca:[\w+=/,.@-]*:[0-9]+:[\w+=,.@-]+(/[\w+=,.@-]+)*$`),
9797
attribute.Expr.Range(),
9898
)
9999
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
4+
5+
import (
6+
"testing"
7+
"fmt"
8+
9+
"github.com/terraform-linters/tflint-plugin-sdk/helper"
10+
)
11+
12+
func Test_AwsAcmCertificateInvalidCertificateAuthorityArnRule(t *testing.T) {
13+
cases := []struct {
14+
Name string
15+
Content string
16+
Expected helper.Issues
17+
}{
18+
{
19+
Name: "It includes invalid characters",
20+
Content: `
21+
resource "aws_acm_certificate" "foo" {
22+
certificate_authority_arn = "arn:aws:unknown-service:us-east-1:0000000000:certificate-authority/xxxxxx-xxx-xxx-xxxx-xxxxxxxxx"
23+
}`,
24+
Expected: helper.Issues{
25+
{
26+
Rule: NewAwsAcmCertificateInvalidCertificateAuthorityArnRule(),
27+
Message: fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage("arn:aws:unknown-service:us-east-1:0000000000:certificate-authority/xxxxxx-xxx-xxx-xxxx-xxxxxxxxx"), `^arn:[\w+=/,.@-]+:acm-pca:[\w+=/,.@-]*:[0-9]+:[\w+=,.@-]+(/[\w+=,.@-]+)*$`),
28+
},
29+
},
30+
},
31+
{
32+
Name: "It is valid",
33+
Content: `
34+
resource "aws_acm_certificate" "foo" {
35+
certificate_authority_arn = "arn:aws:acm-pca:us-east-1:0000000000:certificate-authority/xxxxxx-xxx-xxx-xxxx-xxxxxxxxx"
36+
}`,
37+
Expected: helper.Issues{},
38+
},
39+
}
40+
41+
rule := NewAwsAcmCertificateInvalidCertificateAuthorityArnRule()
42+
43+
for _, tc := range cases {
44+
runner := helper.TestRunner(t, map[string]string{"resource.tf": tc.Content})
45+
46+
if err := rule.Check(runner); err != nil {
47+
t.Fatalf("Unexpected error occurred: %s", err)
48+
}
49+
50+
helper.AssertIssuesWithoutRange(t, tc.Expected, runner.Issues)
51+
}
52+
}

rules/models/aws_acmpca_certificate_authority_invalid_type_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package models
44

55
import (
66
"testing"
7+
"fmt"
78

89
"github.com/terraform-linters/tflint-plugin-sdk/helper"
910
)
@@ -23,7 +24,7 @@ resource "aws_acmpca_certificate_authority" "foo" {
2324
Expected: helper.Issues{
2425
{
2526
Rule: NewAwsAcmpcaCertificateAuthorityInvalidTypeRule(),
26-
Message: `"ORDINATE" is an invalid value as type`,
27+
Message: fmt.Sprintf(`"%s" is an invalid value as %s`, truncateLongMessage("ORDINATE"), "type"),
2728
},
2829
},
2930
},

rules/models/aws_ami_invalid_architecture_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package models
44

55
import (
66
"testing"
7+
"fmt"
78

89
"github.com/terraform-linters/tflint-plugin-sdk/helper"
910
)
@@ -23,7 +24,7 @@ resource "aws_ami" "foo" {
2324
Expected: helper.Issues{
2425
{
2526
Rule: NewAwsAMIInvalidArchitectureRule(),
26-
Message: `"x86" is an invalid value as architecture`,
27+
Message: fmt.Sprintf(`"%s" is an invalid value as %s`, truncateLongMessage("x86"), "architecture"),
2728
},
2829
},
2930
},

rules/models/aws_api_gateway_authorizer_invalid_type_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package models
44

55
import (
66
"testing"
7+
"fmt"
78

89
"github.com/terraform-linters/tflint-plugin-sdk/helper"
910
)
@@ -23,7 +24,7 @@ resource "aws_api_gateway_authorizer" "foo" {
2324
Expected: helper.Issues{
2425
{
2526
Rule: NewAwsAPIGatewayAuthorizerInvalidTypeRule(),
26-
Message: `"RESPONSE" is an invalid value as type`,
27+
Message: fmt.Sprintf(`"%s" is an invalid value as %s`, truncateLongMessage("RESPONSE"), "type"),
2728
},
2829
},
2930
},

rules/models/aws_api_gateway_gateway_response_invalid_response_type_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package models
44

55
import (
66
"testing"
7+
"fmt"
78

89
"github.com/terraform-linters/tflint-plugin-sdk/helper"
910
)
@@ -23,7 +24,7 @@ resource "aws_api_gateway_gateway_response" "foo" {
2324
Expected: helper.Issues{
2425
{
2526
Rule: NewAwsAPIGatewayGatewayResponseInvalidResponseTypeRule(),
26-
Message: `"4XX" is an invalid value as response_type`,
27+
Message: fmt.Sprintf(`"%s" is an invalid value as %s`, truncateLongMessage("4XX"), "response_type"),
2728
},
2829
},
2930
},

rules/models/aws_api_gateway_gateway_response_invalid_status_code_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package models
44

55
import (
66
"testing"
7+
"fmt"
78

89
"github.com/terraform-linters/tflint-plugin-sdk/helper"
910
)
@@ -23,7 +24,7 @@ resource "aws_api_gateway_gateway_response" "foo" {
2324
Expected: helper.Issues{
2425
{
2526
Rule: NewAwsAPIGatewayGatewayResponseInvalidStatusCodeRule(),
26-
Message: `"004" does not match valid pattern ^[1-5]\d\d$`,
27+
Message: fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage("004"), `^[1-5]\d\d$`),
2728
},
2829
},
2930
},

rules/models/aws_api_gateway_integration_invalid_connection_type_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package models
44

55
import (
66
"testing"
7+
"fmt"
78

89
"github.com/terraform-linters/tflint-plugin-sdk/helper"
910
)
@@ -23,7 +24,7 @@ resource "aws_api_gateway_integration" "foo" {
2324
Expected: helper.Issues{
2425
{
2526
Rule: NewAwsAPIGatewayIntegrationInvalidConnectionTypeRule(),
26-
Message: `"INTRANET" is an invalid value as connection_type`,
27+
Message: fmt.Sprintf(`"%s" is an invalid value as %s`, truncateLongMessage("INTRANET"), "connection_type"),
2728
},
2829
},
2930
},

rules/models/aws_api_gateway_integration_invalid_content_handling_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package models
44

55
import (
66
"testing"
7+
"fmt"
78

89
"github.com/terraform-linters/tflint-plugin-sdk/helper"
910
)
@@ -23,7 +24,7 @@ resource "aws_api_gateway_integration" "foo" {
2324
Expected: helper.Issues{
2425
{
2526
Rule: NewAwsAPIGatewayIntegrationInvalidContentHandlingRule(),
26-
Message: `"CONVERT_TO_FILE" is an invalid value as content_handling`,
27+
Message: fmt.Sprintf(`"%s" is an invalid value as %s`, truncateLongMessage("CONVERT_TO_FILE"), "content_handling"),
2728
},
2829
},
2930
},

rules/models/aws_api_gateway_integration_invalid_type_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package models
44

55
import (
66
"testing"
7+
"fmt"
78

89
"github.com/terraform-linters/tflint-plugin-sdk/helper"
910
)
@@ -23,7 +24,7 @@ resource "aws_api_gateway_integration" "foo" {
2324
Expected: helper.Issues{
2425
{
2526
Rule: NewAwsAPIGatewayIntegrationInvalidTypeRule(),
26-
Message: `"AWS_HTTP" is an invalid value as type`,
27+
Message: fmt.Sprintf(`"%s" is an invalid value as %s`, truncateLongMessage("AWS_HTTP"), "type"),
2728
},
2829
},
2930
},

0 commit comments

Comments
 (0)