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