github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/aws_route53_health_check_invalid_ip_address.go (about)

     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/tflint"
    12  )
    13  
    14  // AwsRoute53HealthCheckInvalidIPAddressRule checks the pattern is valid
    15  type AwsRoute53HealthCheckInvalidIPAddressRule struct {
    16  	resourceType  string
    17  	attributeName string
    18  	max           int
    19  	pattern       *regexp.Regexp
    20  }
    21  
    22  // NewAwsRoute53HealthCheckInvalidIPAddressRule returns new rule with default attributes
    23  func NewAwsRoute53HealthCheckInvalidIPAddressRule() *AwsRoute53HealthCheckInvalidIPAddressRule {
    24  	return &AwsRoute53HealthCheckInvalidIPAddressRule{
    25  		resourceType:  "aws_route53_health_check",
    26  		attributeName: "ip_address",
    27  		max:           45,
    28  		pattern:       regexp.MustCompile(`^(^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))$|^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$)$`),
    29  	}
    30  }
    31  
    32  // Name returns the rule name
    33  func (r *AwsRoute53HealthCheckInvalidIPAddressRule) Name() string {
    34  	return "aws_route53_health_check_invalid_ip_address"
    35  }
    36  
    37  // Enabled returns whether the rule is enabled by default
    38  func (r *AwsRoute53HealthCheckInvalidIPAddressRule) Enabled() bool {
    39  	return true
    40  }
    41  
    42  // Severity returns the rule severity
    43  func (r *AwsRoute53HealthCheckInvalidIPAddressRule) Severity() string {
    44  	return tflint.ERROR
    45  }
    46  
    47  // Link returns the rule reference link
    48  func (r *AwsRoute53HealthCheckInvalidIPAddressRule) Link() string {
    49  	return ""
    50  }
    51  
    52  // Check checks the pattern is valid
    53  func (r *AwsRoute53HealthCheckInvalidIPAddressRule) Check(runner *tflint.Runner) error {
    54  	log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath())
    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)
    59  
    60  		return runner.EnsureNoError(err, func() error {
    61  			if len(val) > r.max {
    62  				runner.EmitIssue(
    63  					r,
    64  					"ip_address must be 45 characters or less",
    65  					attribute.Expr.Range(),
    66  				)
    67  			}
    68  			if !r.pattern.MatchString(val) {
    69  				runner.EmitIssue(
    70  					r,
    71  					fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))$|^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$)$`),
    72  					attribute.Expr.Range(),
    73  				)
    74  			}
    75  			return nil
    76  		})
    77  	})
    78  }