github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_route53_health_check_invalid_cloudwatch_alarm_region.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  // AwsRoute53HealthCheckInvalidCloudwatchAlarmRegionRule checks the pattern is valid
    13  type AwsRoute53HealthCheckInvalidCloudwatchAlarmRegionRule struct {
    14  	resourceType  string
    15  	attributeName string
    16  	max           int
    17  	min           int
    18  	enum          []string
    19  }
    20  
    21  // NewAwsRoute53HealthCheckInvalidCloudwatchAlarmRegionRule returns new rule with default attributes
    22  func NewAwsRoute53HealthCheckInvalidCloudwatchAlarmRegionRule() *AwsRoute53HealthCheckInvalidCloudwatchAlarmRegionRule {
    23  	return &AwsRoute53HealthCheckInvalidCloudwatchAlarmRegionRule{
    24  		resourceType:  "aws_route53_health_check",
    25  		attributeName: "cloudwatch_alarm_region",
    26  		max:           64,
    27  		min:           1,
    28  		enum: []string{
    29  			"us-east-1",
    30  			"us-east-2",
    31  			"us-west-1",
    32  			"us-west-2",
    33  			"ca-central-1",
    34  			"eu-central-1",
    35  			"eu-west-1",
    36  			"eu-west-2",
    37  			"eu-west-3",
    38  			"ap-east-1",
    39  			"me-south-1",
    40  			"ap-south-1",
    41  			"ap-southeast-1",
    42  			"ap-southeast-2",
    43  			"ap-northeast-1",
    44  			"ap-northeast-2",
    45  			"ap-northeast-3",
    46  			"eu-north-1",
    47  			"sa-east-1",
    48  			"cn-northwest-1",
    49  			"cn-north-1",
    50  		},
    51  	}
    52  }
    53  
    54  // Name returns the rule name
    55  func (r *AwsRoute53HealthCheckInvalidCloudwatchAlarmRegionRule) Name() string {
    56  	return "aws_route53_health_check_invalid_cloudwatch_alarm_region"
    57  }
    58  
    59  // Enabled returns whether the rule is enabled by default
    60  func (r *AwsRoute53HealthCheckInvalidCloudwatchAlarmRegionRule) Enabled() bool {
    61  	return true
    62  }
    63  
    64  // Severity returns the rule severity
    65  func (r *AwsRoute53HealthCheckInvalidCloudwatchAlarmRegionRule) Severity() string {
    66  	return tflint.ERROR
    67  }
    68  
    69  // Link returns the rule reference link
    70  func (r *AwsRoute53HealthCheckInvalidCloudwatchAlarmRegionRule) Link() string {
    71  	return ""
    72  }
    73  
    74  // Check checks the pattern is valid
    75  func (r *AwsRoute53HealthCheckInvalidCloudwatchAlarmRegionRule) Check(runner *tflint.Runner) error {
    76  	log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath())
    77  
    78  	return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
    79  		var val string
    80  		err := runner.EvaluateExpr(attribute.Expr, &val)
    81  
    82  		return runner.EnsureNoError(err, func() error {
    83  			if len(val) > r.max {
    84  				runner.EmitIssue(
    85  					r,
    86  					"cloudwatch_alarm_region must be 64 characters or less",
    87  					attribute.Expr.Range(),
    88  				)
    89  			}
    90  			if len(val) < r.min {
    91  				runner.EmitIssue(
    92  					r,
    93  					"cloudwatch_alarm_region must be 1 characters or higher",
    94  					attribute.Expr.Range(),
    95  				)
    96  			}
    97  			found := false
    98  			for _, item := range r.enum {
    99  				if item == val {
   100  					found = true
   101  				}
   102  			}
   103  			if !found {
   104  				runner.EmitIssue(
   105  					r,
   106  					`cloudwatch_alarm_region is not a valid value`,
   107  					attribute.Expr.Range(),
   108  				)
   109  			}
   110  			return nil
   111  		})
   112  	})
   113  }