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