github.com/terraform-linters/tflint-ruleset-azurerm@v0.26.0/rules/apispec/azurerm_servicebus_topic_invalid_status.go (about) 1 // This file generated by `tools/apispec-rule-gen/main.go`. DO NOT EDIT 2 3 package apispec 4 5 import ( 6 "fmt" 7 8 "github.com/terraform-linters/tflint-plugin-sdk/hclext" 9 "github.com/terraform-linters/tflint-plugin-sdk/tflint" 10 "github.com/terraform-linters/tflint-ruleset-azurerm/project" 11 ) 12 13 // AzurermServicebusTopicInvalidStatusRule checks the pattern is valid 14 type AzurermServicebusTopicInvalidStatusRule struct { 15 tflint.DefaultRule 16 17 resourceType string 18 attributeName string 19 enum []string 20 } 21 22 // NewAzurermServicebusTopicInvalidStatusRule returns new rule with default attributes 23 func NewAzurermServicebusTopicInvalidStatusRule() *AzurermServicebusTopicInvalidStatusRule { 24 return &AzurermServicebusTopicInvalidStatusRule{ 25 resourceType: "azurerm_servicebus_topic", 26 attributeName: "status", 27 enum: []string{ 28 "Active", 29 "Disabled", 30 "Restoring", 31 "SendDisabled", 32 "ReceiveDisabled", 33 "Creating", 34 "Deleting", 35 "Renaming", 36 "Unknown", 37 }, 38 } 39 } 40 41 // Name returns the rule name 42 func (r *AzurermServicebusTopicInvalidStatusRule) Name() string { 43 return "azurerm_servicebus_topic_invalid_status" 44 } 45 46 // Enabled returns whether the rule is enabled by default 47 func (r *AzurermServicebusTopicInvalidStatusRule) Enabled() bool { 48 return true 49 } 50 51 // Severity returns the rule severity 52 func (r *AzurermServicebusTopicInvalidStatusRule) Severity() tflint.Severity { 53 return tflint.ERROR 54 } 55 56 // Link returns the rule reference link 57 func (r *AzurermServicebusTopicInvalidStatusRule) Link() string { 58 return project.ReferenceLink(r.Name()) 59 } 60 61 // Check checks the pattern is valid 62 func (r *AzurermServicebusTopicInvalidStatusRule) Check(runner tflint.Runner) error { 63 resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ 64 Attributes: []hclext.AttributeSchema{ 65 {Name: r.attributeName}, 66 }, 67 }, nil) 68 if err != nil { 69 return err 70 } 71 72 for _, resource := range resources.Blocks { 73 attribute, exists := resource.Body.Attributes[r.attributeName] 74 if !exists { 75 continue 76 } 77 err := runner.EvaluateExpr(attribute.Expr, func (val string) error { 78 found := false 79 for _, item := range r.enum { 80 if item == val { 81 found = true 82 } 83 } 84 if !found { 85 runner.EmitIssue( 86 r, 87 fmt.Sprintf(`"%s" is an invalid value as status`, truncateLongMessage(val)), 88 attribute.Expr.Range(), 89 ) 90 } 91 return nil 92 }, nil) 93 if err != nil { 94 return err 95 } 96 } 97 98 return nil 99 }