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