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