github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_service_discovery_http_namespace_invalid_name.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  // AwsServiceDiscoveryHTTPNamespaceInvalidNameRule checks the pattern is valid
    13  type AwsServiceDiscoveryHTTPNamespaceInvalidNameRule struct {
    14  	resourceType  string
    15  	attributeName string
    16  	max           int
    17  }
    18  
    19  // NewAwsServiceDiscoveryHTTPNamespaceInvalidNameRule returns new rule with default attributes
    20  func NewAwsServiceDiscoveryHTTPNamespaceInvalidNameRule() *AwsServiceDiscoveryHTTPNamespaceInvalidNameRule {
    21  	return &AwsServiceDiscoveryHTTPNamespaceInvalidNameRule{
    22  		resourceType:  "aws_service_discovery_http_namespace",
    23  		attributeName: "name",
    24  		max:           1024,
    25  	}
    26  }
    27  
    28  // Name returns the rule name
    29  func (r *AwsServiceDiscoveryHTTPNamespaceInvalidNameRule) Name() string {
    30  	return "aws_service_discovery_http_namespace_invalid_name"
    31  }
    32  
    33  // Enabled returns whether the rule is enabled by default
    34  func (r *AwsServiceDiscoveryHTTPNamespaceInvalidNameRule) Enabled() bool {
    35  	return true
    36  }
    37  
    38  // Severity returns the rule severity
    39  func (r *AwsServiceDiscoveryHTTPNamespaceInvalidNameRule) Severity() string {
    40  	return tflint.ERROR
    41  }
    42  
    43  // Link returns the rule reference link
    44  func (r *AwsServiceDiscoveryHTTPNamespaceInvalidNameRule) Link() string {
    45  	return ""
    46  }
    47  
    48  // Check checks the pattern is valid
    49  func (r *AwsServiceDiscoveryHTTPNamespaceInvalidNameRule) Check(runner *tflint.Runner) error {
    50  	log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath())
    51  
    52  	return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
    53  		var val string
    54  		err := runner.EvaluateExpr(attribute.Expr, &val)
    55  
    56  		return runner.EnsureNoError(err, func() error {
    57  			if len(val) > r.max {
    58  				runner.EmitIssue(
    59  					r,
    60  					"name must be 1024 characters or less",
    61  					attribute.Expr.Range(),
    62  				)
    63  			}
    64  			return nil
    65  		})
    66  	})
    67  }