Skip to content

mapping wafv2 #248

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

Merged
merged 2 commits into from
Dec 27, 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
16 changes: 16 additions & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,22 @@ These rules enforce best practices and naming conventions:
|aws_wafregional_web_acl_invalid_metric_name|✔|
|aws_wafregional_web_acl_invalid_name|✔|
|aws_wafregional_xss_match_set_invalid_name|✔|
|aws_wafv2_ip_set_invalid_description|✔|
|aws_wafv2_ip_set_invalid_ip_address_version|✔|
|aws_wafv2_ip_set_invalid_name|✔|
|aws_wafv2_ip_set_invalid_scope|✔|
|aws_wafv2_regex_pattern_set_invalid_description|✔|
|aws_wafv2_regex_pattern_set_invalid_name|✔|
|aws_wafv2_regex_pattern_set_invalid_scope|✔|
|aws_wafv2_rule_group_invalid_description|✔|
|aws_wafv2_rule_group_invalid_name|✔|
|aws_wafv2_rule_group_invalid_scope|✔|
|aws_wafv2_web_acl_association_invalid_resource_arn|✔|
|aws_wafv2_web_acl_association_invalid_web_acl_arn|✔|
|aws_wafv2_web_acl_invalid_description|✔|
|aws_wafv2_web_acl_invalid_name|✔|
|aws_wafv2_web_acl_invalid_scope|✔|
|aws_wafv2_web_acl_logging_configuration_invalid_resource_arn|✔|
|aws_worklink_fleet_invalid_audit_stream_arn|✔|
|aws_worklink_fleet_invalid_device_ca_certificate|✔|
|aws_worklink_fleet_invalid_display_name|✔|
Expand Down
87 changes: 87 additions & 0 deletions rules/models/aws_wafv2_ip_set_invalid_description.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// This file generated by `generator/`. DO NOT EDIT

package models

import (
"fmt"
"log"
"regexp"

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

// AwsWafv2IPSetInvalidDescriptionRule checks the pattern is valid
type AwsWafv2IPSetInvalidDescriptionRule struct {
resourceType string
attributeName string
max int
min int
pattern *regexp.Regexp
}

// NewAwsWafv2IPSetInvalidDescriptionRule returns new rule with default attributes
func NewAwsWafv2IPSetInvalidDescriptionRule() *AwsWafv2IPSetInvalidDescriptionRule {
return &AwsWafv2IPSetInvalidDescriptionRule{
resourceType: "aws_wafv2_ip_set",
attributeName: "description",
max: 256,
min: 1,
pattern: regexp.MustCompile(`^[\w+=:#@/\-,\.][\w+=:#@/\-,\.\s]+[\w+=:#@/\-,\.]$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsWafv2IPSetInvalidDescriptionRule) 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 {
if len(val) > r.max {
runner.EmitIssueOnExpr(
r,
"description must be 256 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"description must be 1 characters or higher",
attribute.Expr,
)
}
if !r.pattern.MatchString(val) {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[\w+=:#@/\-,\.][\w+=:#@/\-,\.\s]+[\w+=:#@/\-,\.]$`),
attribute.Expr,
)
}
return nil
})
})
}
77 changes: 77 additions & 0 deletions rules/models/aws_wafv2_ip_set_invalid_ip_address_version.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"
)

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

// NewAwsWafv2IPSetInvalidIPAddressVersionRule returns new rule with default attributes
func NewAwsWafv2IPSetInvalidIPAddressVersionRule() *AwsWafv2IPSetInvalidIPAddressVersionRule {
return &AwsWafv2IPSetInvalidIPAddressVersionRule{
resourceType: "aws_wafv2_ip_set",
attributeName: "ip_address_version",
enum: []string{
"IPV4",
"IPV6",
},
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsWafv2IPSetInvalidIPAddressVersionRule) 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 ip_address_version`, truncateLongMessage(val)),
attribute.Expr,
)
}
return nil
})
})
}
87 changes: 87 additions & 0 deletions rules/models/aws_wafv2_ip_set_invalid_name.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// This file generated by `generator/`. DO NOT EDIT

package models

import (
"fmt"
"log"
"regexp"

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

// AwsWafv2IPSetInvalidNameRule checks the pattern is valid
type AwsWafv2IPSetInvalidNameRule struct {
resourceType string
attributeName string
max int
min int
pattern *regexp.Regexp
}

// NewAwsWafv2IPSetInvalidNameRule returns new rule with default attributes
func NewAwsWafv2IPSetInvalidNameRule() *AwsWafv2IPSetInvalidNameRule {
return &AwsWafv2IPSetInvalidNameRule{
resourceType: "aws_wafv2_ip_set",
attributeName: "name",
max: 128,
min: 1,
pattern: regexp.MustCompile(`^[\w\-]+$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsWafv2IPSetInvalidNameRule) 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 {
if len(val) > r.max {
runner.EmitIssueOnExpr(
r,
"name must be 128 characters or less",
attribute.Expr,
)
}
if len(val) < r.min {
runner.EmitIssueOnExpr(
r,
"name must be 1 characters or higher",
attribute.Expr,
)
}
if !r.pattern.MatchString(val) {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[\w\-]+$`),
attribute.Expr,
)
}
return nil
})
})
}
77 changes: 77 additions & 0 deletions rules/models/aws_wafv2_ip_set_invalid_scope.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"
)

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

// NewAwsWafv2IPSetInvalidScopeRule returns new rule with default attributes
func NewAwsWafv2IPSetInvalidScopeRule() *AwsWafv2IPSetInvalidScopeRule {
return &AwsWafv2IPSetInvalidScopeRule{
resourceType: "aws_wafv2_ip_set",
attributeName: "scope",
enum: []string{
"CLOUDFRONT",
"REGIONAL",
},
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsWafv2IPSetInvalidScopeRule) 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 scope`, truncateLongMessage(val)),
attribute.Expr,
)
}
return nil
})
})
}
Loading