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