Skip to content

File tree

5 files changed

+191
-0
lines changed

5 files changed

+191
-0
lines changed

docs/rules/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,8 @@ These rules enforce best practices and naming conventions:
11321132
|aws_transfer_user_invalid_user_name||
11331133
|aws_vpc_endpoint_invalid_vpc_endpoint_type||
11341134
|aws_vpc_invalid_instance_tenancy||
1135+
|aws_vpc_ipam_pool_invalid_address_family||
1136+
|aws_vpc_ipam_pool_invalid_aws_service||
11351137
|aws_waf_byte_match_set_invalid_name||
11361138
|aws_waf_geo_match_set_invalid_name||
11371139
|aws_waf_ipset_invalid_name||
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+
// AwsVpcIpamPoolInvalidAddressFamilyRule checks the pattern is valid
14+
type AwsVpcIpamPoolInvalidAddressFamilyRule struct {
15+
resourceType string
16+
attributeName string
17+
enum []string
18+
}
19+
20+
// NewAwsVpcIpamPoolInvalidAddressFamilyRule returns new rule with default attributes
21+
func NewAwsVpcIpamPoolInvalidAddressFamilyRule() *AwsVpcIpamPoolInvalidAddressFamilyRule {
22+
return &AwsVpcIpamPoolInvalidAddressFamilyRule{
23+
resourceType: "aws_vpc_ipam_pool",
24+
attributeName: "address_family",
25+
enum: []string{
26+
"ipv4",
27+
"ipv6",
28+
},
29+
}
30+
}
31+
32+
// Name returns the rule name
33+
func (r *AwsVpcIpamPoolInvalidAddressFamilyRule) Name() string {
34+
return "aws_vpc_ipam_pool_invalid_address_family"
35+
}
36+
37+
// Enabled returns whether the rule is enabled by default
38+
func (r *AwsVpcIpamPoolInvalidAddressFamilyRule) Enabled() bool {
39+
return true
40+
}
41+
42+
// Severity returns the rule severity
43+
func (r *AwsVpcIpamPoolInvalidAddressFamilyRule) Severity() string {
44+
return tflint.ERROR
45+
}
46+
47+
// Link returns the rule reference link
48+
func (r *AwsVpcIpamPoolInvalidAddressFamilyRule) Link() string {
49+
return ""
50+
}
51+
52+
// Check checks the pattern is valid
53+
func (r *AwsVpcIpamPoolInvalidAddressFamilyRule) 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 address_family`, truncateLongMessage(val)),
71+
attribute.Expr,
72+
)
73+
}
74+
return nil
75+
})
76+
})
77+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
// AwsVpcIpamPoolInvalidAwsServiceRule checks the pattern is valid
14+
type AwsVpcIpamPoolInvalidAwsServiceRule struct {
15+
resourceType string
16+
attributeName string
17+
enum []string
18+
}
19+
20+
// NewAwsVpcIpamPoolInvalidAwsServiceRule returns new rule with default attributes
21+
func NewAwsVpcIpamPoolInvalidAwsServiceRule() *AwsVpcIpamPoolInvalidAwsServiceRule {
22+
return &AwsVpcIpamPoolInvalidAwsServiceRule{
23+
resourceType: "aws_vpc_ipam_pool",
24+
attributeName: "aws_service",
25+
enum: []string{
26+
"ec2",
27+
},
28+
}
29+
}
30+
31+
// Name returns the rule name
32+
func (r *AwsVpcIpamPoolInvalidAwsServiceRule) Name() string {
33+
return "aws_vpc_ipam_pool_invalid_aws_service"
34+
}
35+
36+
// Enabled returns whether the rule is enabled by default
37+
func (r *AwsVpcIpamPoolInvalidAwsServiceRule) Enabled() bool {
38+
return true
39+
}
40+
41+
// Severity returns the rule severity
42+
func (r *AwsVpcIpamPoolInvalidAwsServiceRule) Severity() string {
43+
return tflint.ERROR
44+
}
45+
46+
// Link returns the rule reference link
47+
func (r *AwsVpcIpamPoolInvalidAwsServiceRule) Link() string {
48+
return ""
49+
}
50+
51+
// Check checks the pattern is valid
52+
func (r *AwsVpcIpamPoolInvalidAwsServiceRule) Check(runner tflint.Runner) error {
53+
log.Printf("[TRACE] Check `%s` rule", r.Name())
54+
55+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
56+
var val string
57+
err := runner.EvaluateExpr(attribute.Expr, &val, nil)
58+
59+
return runner.EnsureNoError(err, func() error {
60+
found := false
61+
for _, item := range r.enum {
62+
if item == val {
63+
found = true
64+
}
65+
}
66+
if !found {
67+
runner.EmitIssueOnExpr(
68+
r,
69+
fmt.Sprintf(`"%s" is an invalid value as aws_service`, truncateLongMessage(val)),
70+
attribute.Expr,
71+
)
72+
}
73+
return nil
74+
})
75+
})
76+
}

rules/models/mappings/vpc.hcl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,45 @@ mapping "aws_vpc_endpoint_subnet_association" {
250250
subnet_id = String
251251
}
252252

253+
mapping "aws_vpc_ipam" {
254+
operating_regions = AddIpamOperatingRegionSet
255+
}
256+
257+
mapping "aws_vpc_ipam_pool" {
258+
address_family = AddressFamily
259+
allocation_default_netmask_length = IpamNetmaskLength
260+
allocation_max_netmask_length = IpamNetmaskLength
261+
allocation_min_netmask_length = IpamNetmaskLength
262+
allocation_resource_tags = RequestIpamResourceTagList
263+
aws_service = IpamPoolAwsService
264+
ipam_scope_id = IpamScopeId
265+
source_ipam_pool_id = IpamPoolId
266+
}
267+
268+
mapping "aws_vpc_ipam_pool_cidr" {
269+
cidr_authorization_context = IpamCidrAuthorizationContext
270+
ipam_pool_id = IpamPoolId
271+
}
272+
273+
mapping "aws_vpc_ipam_pool_cidr_allocation" {
274+
ipam_pool_id = IpamPoolId
275+
}
276+
277+
mapping "aws_vpc_ipam_scope" {
278+
ipam_id = IpamId
279+
}
280+
253281
mapping "aws_vpc_ipv4_cidr_block_association" {
254282
cidr_block = String
255283
vpc_id = String
256284
}
257285

286+
mapping "aws_vpc_ipv6_cidr_block_association" {
287+
ipv6_ipam_pool_id = IpamPoolId
288+
ipv6_netmask_length = NetmaskLength
289+
vpc_id = VpcId
290+
}
291+
258292
mapping "aws_vpc_peering_connection" {
259293
peer_owner_id = String
260294
peer_vpc_id = String

rules/models/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,8 @@ var Rules = []tflint.Rule{
10601060
NewAwsTransferUserInvalidUserNameRule(),
10611061
NewAwsVpcEndpointInvalidVpcEndpointTypeRule(),
10621062
NewAwsVpcInvalidInstanceTenancyRule(),
1063+
NewAwsVpcIpamPoolInvalidAddressFamilyRule(),
1064+
NewAwsVpcIpamPoolInvalidAwsServiceRule(),
10631065
NewAwsWafByteMatchSetInvalidNameRule(),
10641066
NewAwsWafGeoMatchSetInvalidNameRule(),
10651067
NewAwsWafIpsetInvalidNameRule(),

0 commit comments

Comments
 (0)