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