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