github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/aws_route53_resolver_endpoint_invalid_direction.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  // AwsRoute53ResolverEndpointInvalidDirectionRule checks the pattern is valid
    14  type AwsRoute53ResolverEndpointInvalidDirectionRule struct {
    15  	resourceType  string
    16  	attributeName string
    17  	enum          []string
    18  }
    19  
    20  // NewAwsRoute53ResolverEndpointInvalidDirectionRule returns new rule with default attributes
    21  func NewAwsRoute53ResolverEndpointInvalidDirectionRule() *AwsRoute53ResolverEndpointInvalidDirectionRule {
    22  	return &AwsRoute53ResolverEndpointInvalidDirectionRule{
    23  		resourceType:  "aws_route53_resolver_endpoint",
    24  		attributeName: "direction",
    25  		enum: []string{
    26  			"INBOUND",
    27  			"OUTBOUND",
    28  		},
    29  	}
    30  }
    31  
    32  // Name returns the rule name
    33  func (r *AwsRoute53ResolverEndpointInvalidDirectionRule) Name() string {
    34  	return "aws_route53_resolver_endpoint_invalid_direction"
    35  }
    36  
    37  // Enabled returns whether the rule is enabled by default
    38  func (r *AwsRoute53ResolverEndpointInvalidDirectionRule) Enabled() bool {
    39  	return true
    40  }
    41  
    42  // Severity returns the rule severity
    43  func (r *AwsRoute53ResolverEndpointInvalidDirectionRule) Severity() string {
    44  	return tflint.ERROR
    45  }
    46  
    47  // Link returns the rule reference link
    48  func (r *AwsRoute53ResolverEndpointInvalidDirectionRule) Link() string {
    49  	return ""
    50  }
    51  
    52  // Check checks the pattern is valid
    53  func (r *AwsRoute53ResolverEndpointInvalidDirectionRule) Check(runner *tflint.Runner) error {
    54  	log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath())
    55  
    56  	return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
    57  		var val string
    58  		err := runner.EvaluateExpr(attribute.Expr, &val)
    59  
    60  		return runner.EnsureNoError(err, func() error {
    61  			found := false
    62  			for _, item := range r.enum {
    63  				if item == val {
    64  					found = true
    65  				}
    66  			}
    67  			if !found {
    68  				runner.EmitIssue(
    69  					r,
    70  					fmt.Sprintf(`"%s" is an invalid value as direction`, truncateLongMessage(val)),
    71  					attribute.Expr.Range(),
    72  				)
    73  			}
    74  			return nil
    75  		})
    76  	})
    77  }