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