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