github.com/terraform-linters/tflint-ruleset-azurerm@v0.26.0/rules/apispec/azurerm_relay_namespace_invalid_sku_name.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 // AzurermRelayNamespaceInvalidSkuNameRule checks the pattern is valid 14 type AzurermRelayNamespaceInvalidSkuNameRule struct { 15 tflint.DefaultRule 16 17 resourceType string 18 attributeName string 19 enum []string 20 } 21 22 // NewAzurermRelayNamespaceInvalidSkuNameRule returns new rule with default attributes 23 func NewAzurermRelayNamespaceInvalidSkuNameRule() *AzurermRelayNamespaceInvalidSkuNameRule { 24 return &AzurermRelayNamespaceInvalidSkuNameRule{ 25 resourceType: "azurerm_relay_namespace", 26 attributeName: "sku_name", 27 enum: []string{ 28 "Standard", 29 }, 30 } 31 } 32 33 // Name returns the rule name 34 func (r *AzurermRelayNamespaceInvalidSkuNameRule) Name() string { 35 return "azurerm_relay_namespace_invalid_sku_name" 36 } 37 38 // Enabled returns whether the rule is enabled by default 39 func (r *AzurermRelayNamespaceInvalidSkuNameRule) Enabled() bool { 40 return true 41 } 42 43 // Severity returns the rule severity 44 func (r *AzurermRelayNamespaceInvalidSkuNameRule) Severity() tflint.Severity { 45 return tflint.ERROR 46 } 47 48 // Link returns the rule reference link 49 func (r *AzurermRelayNamespaceInvalidSkuNameRule) Link() string { 50 return project.ReferenceLink(r.Name()) 51 } 52 53 // Check checks the pattern is valid 54 func (r *AzurermRelayNamespaceInvalidSkuNameRule) Check(runner tflint.Runner) error { 55 resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ 56 Attributes: []hclext.AttributeSchema{ 57 {Name: r.attributeName}, 58 }, 59 }, nil) 60 if err != nil { 61 return err 62 } 63 64 for _, resource := range resources.Blocks { 65 attribute, exists := resource.Body.Attributes[r.attributeName] 66 if !exists { 67 continue 68 } 69 err := runner.EvaluateExpr(attribute.Expr, func (val string) error { 70 found := false 71 for _, item := range r.enum { 72 if item == val { 73 found = true 74 } 75 } 76 if !found { 77 runner.EmitIssue( 78 r, 79 fmt.Sprintf(`"%s" is an invalid value as sku_name`, truncateLongMessage(val)), 80 attribute.Expr.Range(), 81 ) 82 } 83 return nil 84 }, nil) 85 if err != nil { 86 return err 87 } 88 } 89 90 return nil 91 }