github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_elastic_beanstalk_environment_invalid_cname_prefix.go (about)

     1  // This file generated by `tools/model-rule-gen/main.go`. DO NOT EDIT
     2  
     3  package models
     4  
     5  import (
     6  	"log"
     7  
     8  	hcl "github.com/hashicorp/hcl/v2"
     9  	"github.com/wata727/tflint/tflint"
    10  )
    11  
    12  // AwsElasticBeanstalkEnvironmentInvalidCnamePrefixRule checks the pattern is valid
    13  type AwsElasticBeanstalkEnvironmentInvalidCnamePrefixRule struct {
    14  	resourceType  string
    15  	attributeName string
    16  	max           int
    17  	min           int
    18  }
    19  
    20  // NewAwsElasticBeanstalkEnvironmentInvalidCnamePrefixRule returns new rule with default attributes
    21  func NewAwsElasticBeanstalkEnvironmentInvalidCnamePrefixRule() *AwsElasticBeanstalkEnvironmentInvalidCnamePrefixRule {
    22  	return &AwsElasticBeanstalkEnvironmentInvalidCnamePrefixRule{
    23  		resourceType:  "aws_elastic_beanstalk_environment",
    24  		attributeName: "cname_prefix",
    25  		max:           63,
    26  		min:           4,
    27  	}
    28  }
    29  
    30  // Name returns the rule name
    31  func (r *AwsElasticBeanstalkEnvironmentInvalidCnamePrefixRule) Name() string {
    32  	return "aws_elastic_beanstalk_environment_invalid_cname_prefix"
    33  }
    34  
    35  // Enabled returns whether the rule is enabled by default
    36  func (r *AwsElasticBeanstalkEnvironmentInvalidCnamePrefixRule) Enabled() bool {
    37  	return true
    38  }
    39  
    40  // Severity returns the rule severity
    41  func (r *AwsElasticBeanstalkEnvironmentInvalidCnamePrefixRule) Severity() string {
    42  	return tflint.ERROR
    43  }
    44  
    45  // Link returns the rule reference link
    46  func (r *AwsElasticBeanstalkEnvironmentInvalidCnamePrefixRule) Link() string {
    47  	return ""
    48  }
    49  
    50  // Check checks the pattern is valid
    51  func (r *AwsElasticBeanstalkEnvironmentInvalidCnamePrefixRule) Check(runner *tflint.Runner) error {
    52  	log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath())
    53  
    54  	return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
    55  		var val string
    56  		err := runner.EvaluateExpr(attribute.Expr, &val)
    57  
    58  		return runner.EnsureNoError(err, func() error {
    59  			if len(val) > r.max {
    60  				runner.EmitIssue(
    61  					r,
    62  					"cname_prefix must be 63 characters or less",
    63  					attribute.Expr.Range(),
    64  				)
    65  			}
    66  			if len(val) < r.min {
    67  				runner.EmitIssue(
    68  					r,
    69  					"cname_prefix must be 4 characters or higher",
    70  					attribute.Expr.Range(),
    71  				)
    72  			}
    73  			return nil
    74  		})
    75  	})
    76  }