Skip to content

Commit

Permalink
mapping aws_route53recoveryreadiness (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatMyron authored Dec 31, 2021
1 parent ff08998 commit 5378609
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ These rules enforce best practices and naming conventions:
|aws_route53recoverycontrolconfig_routing_control_invalid_name||
|aws_route53recoverycontrolconfig_safety_rule_invalid_control_panel_arn||
|aws_route53recoverycontrolconfig_safety_rule_invalid_name||
|aws_route53recoveryreadiness_resource_set_invalid_resource_set_type||
|aws_s3_bucket_intelligent_tiering_configuration_invalid_status||
|aws_s3_bucket_invalid_acceleration_status||
|aws_s3_bucket_invalid_request_payer||
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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"
)

// AwsRoute53recoveryreadinessResourceSetInvalidResourceSetTypeRule checks the pattern is valid
type AwsRoute53recoveryreadinessResourceSetInvalidResourceSetTypeRule struct {
resourceType string
attributeName string
pattern *regexp.Regexp
}

// NewAwsRoute53recoveryreadinessResourceSetInvalidResourceSetTypeRule returns new rule with default attributes
func NewAwsRoute53recoveryreadinessResourceSetInvalidResourceSetTypeRule() *AwsRoute53recoveryreadinessResourceSetInvalidResourceSetTypeRule {
return &AwsRoute53recoveryreadinessResourceSetInvalidResourceSetTypeRule{
resourceType: "aws_route53recoveryreadiness_resource_set",
attributeName: "resource_set_type",
pattern: regexp.MustCompile(`^AWS::[A-Za-z0-9]+::[A-Za-z0-9]+$`),
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *AwsRoute53recoveryreadinessResourceSetInvalidResourceSetTypeRule) 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 !r.pattern.MatchString(val) {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^AWS::[A-Za-z0-9]+::[A-Za-z0-9]+$`),
attribute.Expr,
)
}
return nil
})
})
}
18 changes: 18 additions & 0 deletions rules/models/mappings/route53-recovery-readiness.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import = "aws-sdk-go/models/apis/route53-recovery-readiness/2019-12-02/api-2.json"

mapping "aws_route53recoveryreadiness_cell" {
tags = Tags
}

mapping "aws_route53recoveryreadiness_readiness_check" {
tags = Tags
}

mapping "aws_route53recoveryreadiness_recovery_group" {
tags = Tags
}

mapping "aws_route53recoveryreadiness_resource_set" {
resource_set_type = __stringPatternAWSAZaZ09AZaZ09
tags = Tags
}
1 change: 1 addition & 0 deletions rules/models/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ var Rules = []tflint.Rule{
NewAwsRoute53recoverycontrolconfigRoutingControlInvalidNameRule(),
NewAwsRoute53recoverycontrolconfigSafetyRuleInvalidControlPanelArnRule(),
NewAwsRoute53recoverycontrolconfigSafetyRuleInvalidNameRule(),
NewAwsRoute53recoveryreadinessResourceSetInvalidResourceSetTypeRule(),
NewAwsS3BucketIntelligentTieringConfigurationInvalidStatusRule(),
NewAwsS3BucketInvalidAccelerationStatusRule(),
NewAwsS3BucketInvalidRequestPayerRule(),
Expand Down

0 comments on commit 5378609

Please sign in to comment.