Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapping aws_ec2 #251

Merged
merged 3 commits into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,19 @@ These rules enforce best practices and naming conventions:
|aws_dynamodb_table_item_invalid_range_key|✔|
|aws_dynamodb_table_item_invalid_table_name|✔|
|aws_ebs_volume_invalid_type|✔|
|aws_ec2_availability_zone_group_invalid_opt_in_status|✔|
|aws_ec2_capacity_reservation_invalid_end_date_type|✔|
|aws_ec2_capacity_reservation_invalid_instance_match_criteria|✔|
|aws_ec2_capacity_reservation_invalid_instance_platform|✔|
|aws_ec2_capacity_reservation_invalid_tenancy|✔|
|aws_ec2_client_vpn_endpoint_invalid_transport_protocol|✔|
|aws_ec2_fleet_invalid_excess_capacity_termination_policy|✔|
|aws_ec2_fleet_invalid_type|✔|
|aws_ec2_host_invalid_auto_placement|✔|
|aws_ec2_host_invalid_host_recovery|✔|
|aws_ec2_subnet_cidr_reservation_invalid_reservation_type|✔|
|aws_ec2_traffic_mirror_filter_rule_invalid_rule_action|✔|
|aws_ec2_traffic_mirror_filter_rule_invalid_traffic_direction|✔|
|aws_ec2_transit_gateway_invalid_auto_accept_shared_attachments|✔|
|aws_ec2_transit_gateway_invalid_default_route_table_association|✔|
|aws_ec2_transit_gateway_invalid_default_route_table_propagation|✔|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// This file generated by `generator/`. DO NOT EDIT

package models

import (
"fmt"
"log"

hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)

// AwsEc2AvailabilityZoneGroupInvalidOptInStatusRule checks the pattern is valid
type AwsEc2AvailabilityZoneGroupInvalidOptInStatusRule struct {
resourceType string
attributeName string
enum []string
}

// NewAwsEc2AvailabilityZoneGroupInvalidOptInStatusRule returns new rule with default attributes
func NewAwsEc2AvailabilityZoneGroupInvalidOptInStatusRule() *AwsEc2AvailabilityZoneGroupInvalidOptInStatusRule {
return &AwsEc2AvailabilityZoneGroupInvalidOptInStatusRule{
resourceType: "aws_ec2_availability_zone_group",
attributeName: "opt_in_status",
enum: []string{
"opted-in",
"not-opted-in",
},
}
}

// Name returns the rule name
func (r *AwsEc2AvailabilityZoneGroupInvalidOptInStatusRule) Name() string {
return "aws_ec2_availability_zone_group_invalid_opt_in_status"
}

// Enabled returns whether the rule is enabled by default
func (r *AwsEc2AvailabilityZoneGroupInvalidOptInStatusRule) Enabled() bool {
return true
}

// Severity returns the rule severity
func (r *AwsEc2AvailabilityZoneGroupInvalidOptInStatusRule) Severity() string {
return tflint.ERROR
}

// Link returns the rule reference link
func (r *AwsEc2AvailabilityZoneGroupInvalidOptInStatusRule) Link() string {
return ""
}

// Check checks the pattern is valid
func (r *AwsEc2AvailabilityZoneGroupInvalidOptInStatusRule) Check(runner tflint.Runner) error {
log.Printf("[TRACE] Check `%s` rule", r.Name())

return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
var val string
err := runner.EvaluateExpr(attribute.Expr, &val, nil)

return runner.EnsureNoError(err, func() error {
found := false
for _, item := range r.enum {
if item == val {
found = true
}
}
if !found {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" is an invalid value as opt_in_status`, truncateLongMessage(val)),
attribute.Expr,
)
}
return nil
})
})
}
77 changes: 77 additions & 0 deletions rules/models/aws_ec2_host_invalid_auto_placement.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// This file generated by `generator/`. DO NOT EDIT

package models

import (
"fmt"
"log"

hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)

// AwsEc2HostInvalidAutoPlacementRule checks the pattern is valid
type AwsEc2HostInvalidAutoPlacementRule struct {
resourceType string
attributeName string
enum []string
}

// NewAwsEc2HostInvalidAutoPlacementRule returns new rule with default attributes
func NewAwsEc2HostInvalidAutoPlacementRule() *AwsEc2HostInvalidAutoPlacementRule {
return &AwsEc2HostInvalidAutoPlacementRule{
resourceType: "aws_ec2_host",
attributeName: "auto_placement",
enum: []string{
"on",
"off",
},
}
}

// Name returns the rule name
func (r *AwsEc2HostInvalidAutoPlacementRule) Name() string {
return "aws_ec2_host_invalid_auto_placement"
}

// Enabled returns whether the rule is enabled by default
func (r *AwsEc2HostInvalidAutoPlacementRule) Enabled() bool {
return true
}

// Severity returns the rule severity
func (r *AwsEc2HostInvalidAutoPlacementRule) Severity() string {
return tflint.ERROR
}

// Link returns the rule reference link
func (r *AwsEc2HostInvalidAutoPlacementRule) Link() string {
return ""
}

// Check checks the pattern is valid
func (r *AwsEc2HostInvalidAutoPlacementRule) Check(runner tflint.Runner) error {
log.Printf("[TRACE] Check `%s` rule", r.Name())

return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
var val string
err := runner.EvaluateExpr(attribute.Expr, &val, nil)

return runner.EnsureNoError(err, func() error {
found := false
for _, item := range r.enum {
if item == val {
found = true
}
}
if !found {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" is an invalid value as auto_placement`, truncateLongMessage(val)),
attribute.Expr,
)
}
return nil
})
})
}
77 changes: 77 additions & 0 deletions rules/models/aws_ec2_host_invalid_host_recovery.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// This file generated by `generator/`. DO NOT EDIT

package models

import (
"fmt"
"log"

hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)

// AwsEc2HostInvalidHostRecoveryRule checks the pattern is valid
type AwsEc2HostInvalidHostRecoveryRule struct {
resourceType string
attributeName string
enum []string
}

// NewAwsEc2HostInvalidHostRecoveryRule returns new rule with default attributes
func NewAwsEc2HostInvalidHostRecoveryRule() *AwsEc2HostInvalidHostRecoveryRule {
return &AwsEc2HostInvalidHostRecoveryRule{
resourceType: "aws_ec2_host",
attributeName: "host_recovery",
enum: []string{
"on",
"off",
},
}
}

// Name returns the rule name
func (r *AwsEc2HostInvalidHostRecoveryRule) Name() string {
return "aws_ec2_host_invalid_host_recovery"
}

// Enabled returns whether the rule is enabled by default
func (r *AwsEc2HostInvalidHostRecoveryRule) Enabled() bool {
return true
}

// Severity returns the rule severity
func (r *AwsEc2HostInvalidHostRecoveryRule) Severity() string {
return tflint.ERROR
}

// Link returns the rule reference link
func (r *AwsEc2HostInvalidHostRecoveryRule) Link() string {
return ""
}

// Check checks the pattern is valid
func (r *AwsEc2HostInvalidHostRecoveryRule) Check(runner tflint.Runner) error {
log.Printf("[TRACE] Check `%s` rule", r.Name())

return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
var val string
err := runner.EvaluateExpr(attribute.Expr, &val, nil)

return runner.EnsureNoError(err, func() error {
found := false
for _, item := range r.enum {
if item == val {
found = true
}
}
if !found {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" is an invalid value as host_recovery`, truncateLongMessage(val)),
attribute.Expr,
)
}
return nil
})
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// This file generated by `generator/`. DO NOT EDIT

package models

import (
"fmt"
"log"

hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)

// AwsEc2SubnetCidrReservationInvalidReservationTypeRule checks the pattern is valid
type AwsEc2SubnetCidrReservationInvalidReservationTypeRule struct {
resourceType string
attributeName string
enum []string
}

// NewAwsEc2SubnetCidrReservationInvalidReservationTypeRule returns new rule with default attributes
func NewAwsEc2SubnetCidrReservationInvalidReservationTypeRule() *AwsEc2SubnetCidrReservationInvalidReservationTypeRule {
return &AwsEc2SubnetCidrReservationInvalidReservationTypeRule{
resourceType: "aws_ec2_subnet_cidr_reservation",
attributeName: "reservation_type",
enum: []string{
"prefix",
"explicit",
},
}
}

// Name returns the rule name
func (r *AwsEc2SubnetCidrReservationInvalidReservationTypeRule) Name() string {
return "aws_ec2_subnet_cidr_reservation_invalid_reservation_type"
}

// Enabled returns whether the rule is enabled by default
func (r *AwsEc2SubnetCidrReservationInvalidReservationTypeRule) Enabled() bool {
return true
}

// Severity returns the rule severity
func (r *AwsEc2SubnetCidrReservationInvalidReservationTypeRule) Severity() string {
return tflint.ERROR
}

// Link returns the rule reference link
func (r *AwsEc2SubnetCidrReservationInvalidReservationTypeRule) Link() string {
return ""
}

// Check checks the pattern is valid
func (r *AwsEc2SubnetCidrReservationInvalidReservationTypeRule) Check(runner tflint.Runner) error {
log.Printf("[TRACE] Check `%s` rule", r.Name())

return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
var val string
err := runner.EvaluateExpr(attribute.Expr, &val, nil)

return runner.EnsureNoError(err, func() error {
found := false
for _, item := range r.enum {
if item == val {
found = true
}
}
if !found {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" is an invalid value as reservation_type`, truncateLongMessage(val)),
attribute.Expr,
)
}
return nil
})
})
}
Loading