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