Skip to content

6 files changed

+255
-0
lines changed

docs/rules/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ These rules enforce best practices and naming conventions:
513513
|aws_ec2_transit_gateway_vpc_attachment_invalid_ipv6_support||
514514
|aws_ecr_lifecycle_policy_invalid_policy||
515515
|aws_ecr_lifecycle_policy_invalid_repository||
516+
|aws_ecr_pull_through_cache_rule_invalid_ecr_repository_prefix||
517+
|aws_ecr_registry_policy_invalid_policy||
518+
|aws_ecr_registry_scanning_configuration_invalid_scan_type||
516519
|aws_ecr_repository_invalid_name||
517520
|aws_ecr_repository_policy_invalid_policy||
518521
|aws_ecr_repository_policy_invalid_repository||
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+
// AwsEcrPullThroughCacheRuleInvalidEcrRepositoryPrefixRule checks the pattern is valid
15+
type AwsEcrPullThroughCacheRuleInvalidEcrRepositoryPrefixRule struct {
16+
resourceType string
17+
attributeName string
18+
max int
19+
min int
20+
pattern *regexp.Regexp
21+
}
22+
23+
// NewAwsEcrPullThroughCacheRuleInvalidEcrRepositoryPrefixRule returns new rule with default attributes
24+
func NewAwsEcrPullThroughCacheRuleInvalidEcrRepositoryPrefixRule() *AwsEcrPullThroughCacheRuleInvalidEcrRepositoryPrefixRule {
25+
return &AwsEcrPullThroughCacheRuleInvalidEcrRepositoryPrefixRule{
26+
resourceType: "aws_ecr_pull_through_cache_rule",
27+
attributeName: "ecr_repository_prefix",
28+
max: 20,
29+
min: 2,
30+
pattern: regexp.MustCompile(`^[a-z0-9]+(?:[._-][a-z0-9]+)*$`),
31+
}
32+
}
33+
34+
// Name returns the rule name
35+
func (r *AwsEcrPullThroughCacheRuleInvalidEcrRepositoryPrefixRule) Name() string {
36+
return "aws_ecr_pull_through_cache_rule_invalid_ecr_repository_prefix"
37+
}
38+
39+
// Enabled returns whether the rule is enabled by default
40+
func (r *AwsEcrPullThroughCacheRuleInvalidEcrRepositoryPrefixRule) Enabled() bool {
41+
return true
42+
}
43+
44+
// Severity returns the rule severity
45+
func (r *AwsEcrPullThroughCacheRuleInvalidEcrRepositoryPrefixRule) Severity() string {
46+
return tflint.ERROR
47+
}
48+
49+
// Link returns the rule reference link
50+
func (r *AwsEcrPullThroughCacheRuleInvalidEcrRepositoryPrefixRule) Link() string {
51+
return ""
52+
}
53+
54+
// Check checks the pattern is valid
55+
func (r *AwsEcrPullThroughCacheRuleInvalidEcrRepositoryPrefixRule) 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+
"ecr_repository_prefix must be 20 characters or less",
67+
attribute.Expr,
68+
)
69+
}
70+
if len(val) < r.min {
71+
runner.EmitIssueOnExpr(
72+
r,
73+
"ecr_repository_prefix must be 2 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), `^[a-z0-9]+(?:[._-][a-z0-9]+)*$`),
81+
attribute.Expr,
82+
)
83+
}
84+
return nil
85+
})
86+
})
87+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
// AwsEcrRegistryPolicyInvalidPolicyRule checks the pattern is valid
13+
type AwsEcrRegistryPolicyInvalidPolicyRule struct {
14+
resourceType string
15+
attributeName string
16+
max int
17+
}
18+
19+
// NewAwsEcrRegistryPolicyInvalidPolicyRule returns new rule with default attributes
20+
func NewAwsEcrRegistryPolicyInvalidPolicyRule() *AwsEcrRegistryPolicyInvalidPolicyRule {
21+
return &AwsEcrRegistryPolicyInvalidPolicyRule{
22+
resourceType: "aws_ecr_registry_policy",
23+
attributeName: "policy",
24+
max: 10240,
25+
}
26+
}
27+
28+
// Name returns the rule name
29+
func (r *AwsEcrRegistryPolicyInvalidPolicyRule) Name() string {
30+
return "aws_ecr_registry_policy_invalid_policy"
31+
}
32+
33+
// Enabled returns whether the rule is enabled by default
34+
func (r *AwsEcrRegistryPolicyInvalidPolicyRule) Enabled() bool {
35+
return true
36+
}
37+
38+
// Severity returns the rule severity
39+
func (r *AwsEcrRegistryPolicyInvalidPolicyRule) Severity() string {
40+
return tflint.ERROR
41+
}
42+
43+
// Link returns the rule reference link
44+
func (r *AwsEcrRegistryPolicyInvalidPolicyRule) Link() string {
45+
return ""
46+
}
47+
48+
// Check checks the pattern is valid
49+
func (r *AwsEcrRegistryPolicyInvalidPolicyRule) Check(runner tflint.Runner) error {
50+
log.Printf("[TRACE] Check `%s` rule", r.Name())
51+
52+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
53+
var val string
54+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
55+
56+
return runner.EnsureNoError(err, func() error {
57+
if len(val) > r.max {
58+
runner.EmitIssueOnExpr(
59+
r,
60+
"policy must be 10240 characters or less",
61+
attribute.Expr,
62+
)
63+
}
64+
return nil
65+
})
66+
})
67+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// This file generated by `generator/`. DO NOT EDIT
2+
3+
package models
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+
)
12+
13+
// AwsEcrRegistryScanningConfigurationInvalidScanTypeRule checks the pattern is valid
14+
type AwsEcrRegistryScanningConfigurationInvalidScanTypeRule struct {
15+
resourceType string
16+
attributeName string
17+
enum []string
18+
}
19+
20+
// NewAwsEcrRegistryScanningConfigurationInvalidScanTypeRule returns new rule with default attributes
21+
func NewAwsEcrRegistryScanningConfigurationInvalidScanTypeRule() *AwsEcrRegistryScanningConfigurationInvalidScanTypeRule {
22+
return &AwsEcrRegistryScanningConfigurationInvalidScanTypeRule{
23+
resourceType: "aws_ecr_registry_scanning_configuration",
24+
attributeName: "scan_type",
25+
enum: []string{
26+
"BASIC",
27+
"ENHANCED",
28+
},
29+
}
30+
}
31+
32+
// Name returns the rule name
33+
func (r *AwsEcrRegistryScanningConfigurationInvalidScanTypeRule) Name() string {
34+
return "aws_ecr_registry_scanning_configuration_invalid_scan_type"
35+
}
36+
37+
// Enabled returns whether the rule is enabled by default
38+
func (r *AwsEcrRegistryScanningConfigurationInvalidScanTypeRule) Enabled() bool {
39+
return true
40+
}
41+
42+
// Severity returns the rule severity
43+
func (r *AwsEcrRegistryScanningConfigurationInvalidScanTypeRule) Severity() string {
44+
return tflint.ERROR
45+
}
46+
47+
// Link returns the rule reference link
48+
func (r *AwsEcrRegistryScanningConfigurationInvalidScanTypeRule) Link() string {
49+
return ""
50+
}
51+
52+
// Check checks the pattern is valid
53+
func (r *AwsEcrRegistryScanningConfigurationInvalidScanTypeRule) Check(runner tflint.Runner) error {
54+
log.Printf("[TRACE] Check `%s` rule", r.Name())
55+
56+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
57+
var val string
58+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
59+
60+
return runner.EnsureNoError(err, func() error {
61+
found := false
62+
for _, item := range r.enum {
63+
if item == val {
64+
found = true
65+
}
66+
}
67+
if !found {
68+
runner.EmitIssueOnExpr(
69+
r,
70+
fmt.Sprintf(`"%s" is an invalid value as scan_type`, truncateLongMessage(val)),
71+
attribute.Expr,
72+
)
73+
}
74+
return nil
75+
})
76+
})
77+
}

rules/models/mappings/ecr.hcl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ mapping "aws_ecr_lifecycle_policy" {
55
policy = LifecyclePolicyText
66
}
77

8+
mapping "aws_ecr_pull_through_cache_rule" {
9+
ecr_repository_prefix = PullThroughCacheRuleRepositoryPrefix
10+
upstream_registry_url = Url
11+
}
12+
13+
mapping "aws_ecr_registry_policy" {
14+
policy = RegistryPolicyText
15+
}
16+
17+
mapping "aws_ecr_registry_scanning_configuration" {
18+
scan_type = ScanType
19+
rule = RegistryScanningRuleList
20+
}
21+
22+
mapping "aws_ecr_replication_configuration" {
23+
replication_configuration = ReplicationConfiguration
24+
}
25+
826
mapping "aws_ecr_repository" {
927
name = RepositoryName
1028
tags = TagList

rules/models/provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@ var Rules = []tflint.Rule{
441441
NewAwsEc2TransitGatewayVpcAttachmentInvalidIpv6SupportRule(),
442442
NewAwsEcrLifecyclePolicyInvalidPolicyRule(),
443443
NewAwsEcrLifecyclePolicyInvalidRepositoryRule(),
444+
NewAwsEcrPullThroughCacheRuleInvalidEcrRepositoryPrefixRule(),
445+
NewAwsEcrRegistryPolicyInvalidPolicyRule(),
446+
NewAwsEcrRegistryScanningConfigurationInvalidScanTypeRule(),
444447
NewAwsEcrRepositoryInvalidNameRule(),
445448
NewAwsEcrRepositoryPolicyInvalidPolicyRule(),
446449
NewAwsEcrRepositoryPolicyInvalidRepositoryRule(),

0 commit comments

Comments
 (0)