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

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