github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_config_aggregate_authorization_invalid_account_id.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  	"regexp"
     8  
     9  	hcl "github.com/hashicorp/hcl/v2"
    10  	"github.com/wata727/tflint/tflint"
    11  )
    12  
    13  // AwsConfigAggregateAuthorizationInvalidAccountIDRule checks the pattern is valid
    14  type AwsConfigAggregateAuthorizationInvalidAccountIDRule struct {
    15  	resourceType  string
    16  	attributeName string
    17  	pattern       *regexp.Regexp
    18  }
    19  
    20  // NewAwsConfigAggregateAuthorizationInvalidAccountIDRule returns new rule with default attributes
    21  func NewAwsConfigAggregateAuthorizationInvalidAccountIDRule() *AwsConfigAggregateAuthorizationInvalidAccountIDRule {
    22  	return &AwsConfigAggregateAuthorizationInvalidAccountIDRule{
    23  		resourceType:  "aws_config_aggregate_authorization",
    24  		attributeName: "account_id",
    25  		pattern:       regexp.MustCompile(`^\d{12}$`),
    26  	}
    27  }
    28  
    29  // Name returns the rule name
    30  func (r *AwsConfigAggregateAuthorizationInvalidAccountIDRule) Name() string {
    31  	return "aws_config_aggregate_authorization_invalid_account_id"
    32  }
    33  
    34  // Enabled returns whether the rule is enabled by default
    35  func (r *AwsConfigAggregateAuthorizationInvalidAccountIDRule) Enabled() bool {
    36  	return true
    37  }
    38  
    39  // Severity returns the rule severity
    40  func (r *AwsConfigAggregateAuthorizationInvalidAccountIDRule) Severity() string {
    41  	return tflint.ERROR
    42  }
    43  
    44  // Link returns the rule reference link
    45  func (r *AwsConfigAggregateAuthorizationInvalidAccountIDRule) Link() string {
    46  	return ""
    47  }
    48  
    49  // Check checks the pattern is valid
    50  func (r *AwsConfigAggregateAuthorizationInvalidAccountIDRule) Check(runner *tflint.Runner) error {
    51  	log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath())
    52  
    53  	return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
    54  		var val string
    55  		err := runner.EvaluateExpr(attribute.Expr, &val)
    56  
    57  		return runner.EnsureNoError(err, func() error {
    58  			if !r.pattern.MatchString(val) {
    59  				runner.EmitIssue(
    60  					r,
    61  					`account_id does not match valid pattern ^\d{12}$`,
    62  					attribute.Expr.Range(),
    63  				)
    64  			}
    65  			return nil
    66  		})
    67  	})
    68  }