|
| 1 | +// ---------------------------------------------------------------------------- |
| 2 | +// |
| 3 | +// *** AUTO GENERATED CODE *** Type: MMv1 *** |
| 4 | +// |
| 5 | +// ---------------------------------------------------------------------------- |
| 6 | +// |
| 7 | +// This file is automatically generated by Magic Modules and manual |
| 8 | +// changes will be clobbered when the file is regenerated. |
| 9 | +// |
| 10 | +// Please read more about how to change this file in |
| 11 | +// .github/CONTRIBUTING.md. |
| 12 | +// |
| 13 | +// ---------------------------------------------------------------------------- |
| 14 | + |
| 15 | +package magicmodules |
| 16 | + |
| 17 | +import ( |
| 18 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" |
| 19 | + "github.com/terraform-linters/tflint-plugin-sdk/hclext" |
| 20 | + "github.com/terraform-linters/tflint-plugin-sdk/tflint" |
| 21 | +) |
| 22 | + |
| 23 | +// GoogleFirebaseAppHostingBackendInvalidServingLocalityRule checks the pattern is valid |
| 24 | +type GoogleFirebaseAppHostingBackendInvalidServingLocalityRule struct { |
| 25 | + tflint.DefaultRule |
| 26 | + |
| 27 | + resourceType string |
| 28 | + attributeName string |
| 29 | +} |
| 30 | + |
| 31 | +// NewGoogleFirebaseAppHostingBackendInvalidServingLocalityRule returns new rule with default attributes |
| 32 | +func NewGoogleFirebaseAppHostingBackendInvalidServingLocalityRule() *GoogleFirebaseAppHostingBackendInvalidServingLocalityRule { |
| 33 | + return &GoogleFirebaseAppHostingBackendInvalidServingLocalityRule{ |
| 34 | + resourceType: "google_firebase_app_hosting_backend", |
| 35 | + attributeName: "serving_locality", |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +// Name returns the rule name |
| 40 | +func (r *GoogleFirebaseAppHostingBackendInvalidServingLocalityRule) Name() string { |
| 41 | + return "google_firebase_app_hosting_backend_invalid_serving_locality" |
| 42 | +} |
| 43 | + |
| 44 | +// Enabled returns whether the rule is enabled by default |
| 45 | +func (r *GoogleFirebaseAppHostingBackendInvalidServingLocalityRule) Enabled() bool { |
| 46 | + return true |
| 47 | +} |
| 48 | + |
| 49 | +// Severity returns the rule severity |
| 50 | +func (r *GoogleFirebaseAppHostingBackendInvalidServingLocalityRule) Severity() tflint.Severity { |
| 51 | + return tflint.ERROR |
| 52 | +} |
| 53 | + |
| 54 | +// Link returns the rule reference link |
| 55 | +func (r *GoogleFirebaseAppHostingBackendInvalidServingLocalityRule) Link() string { |
| 56 | + return "" |
| 57 | +} |
| 58 | + |
| 59 | +// Check checks the pattern is valid |
| 60 | +func (r *GoogleFirebaseAppHostingBackendInvalidServingLocalityRule) Check(runner tflint.Runner) error { |
| 61 | + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ |
| 62 | + Attributes: []hclext.AttributeSchema{{Name: r.attributeName}}, |
| 63 | + }, nil) |
| 64 | + if err != nil { |
| 65 | + return err |
| 66 | + } |
| 67 | + |
| 68 | + for _, resource := range resources.Blocks { |
| 69 | + attribute, exists := resource.Body.Attributes[r.attributeName] |
| 70 | + if !exists { |
| 71 | + continue |
| 72 | + } |
| 73 | + |
| 74 | + err := runner.EvaluateExpr(attribute.Expr, func(val string) error { |
| 75 | + validateFunc := validation.StringInSlice([]string{"REGIONAL_STRICT", "GLOBAL_ACCESS"}, false) |
| 76 | + |
| 77 | + _, errors := validateFunc(val, r.attributeName) |
| 78 | + for _, err := range errors { |
| 79 | + if err := runner.EmitIssue(r, err.Error(), attribute.Expr.Range()); err != nil { |
| 80 | + return err |
| 81 | + } |
| 82 | + } |
| 83 | + return nil |
| 84 | + }, nil) |
| 85 | + if err != nil { |
| 86 | + return err |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + return nil |
| 91 | +} |
0 commit comments