|
| 1 | +// ---------------------------------------------------------------------------- |
| 2 | +// |
| 3 | +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** |
| 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 | + hcl "github.com/hashicorp/hcl/v2" |
| 19 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" |
| 20 | + "github.com/terraform-linters/tflint-plugin-sdk/tflint" |
| 21 | +) |
| 22 | + |
| 23 | +// GoogleApigeeOrganizationInvalidRuntimeTypeRule checks the pattern is valid |
| 24 | +type GoogleApigeeOrganizationInvalidRuntimeTypeRule struct { |
| 25 | + resourceType string |
| 26 | + attributeName string |
| 27 | +} |
| 28 | + |
| 29 | +// NewGoogleApigeeOrganizationInvalidRuntimeTypeRule returns new rule with default attributes |
| 30 | +func NewGoogleApigeeOrganizationInvalidRuntimeTypeRule() *GoogleApigeeOrganizationInvalidRuntimeTypeRule { |
| 31 | + return &GoogleApigeeOrganizationInvalidRuntimeTypeRule{ |
| 32 | + resourceType: "google_apigee_organization", |
| 33 | + attributeName: "runtime_type", |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +// Name returns the rule name |
| 38 | +func (r *GoogleApigeeOrganizationInvalidRuntimeTypeRule) Name() string { |
| 39 | + return "google_apigee_organization_invalid_runtime_type" |
| 40 | +} |
| 41 | + |
| 42 | +// Enabled returns whether the rule is enabled by default |
| 43 | +func (r *GoogleApigeeOrganizationInvalidRuntimeTypeRule) Enabled() bool { |
| 44 | + return true |
| 45 | +} |
| 46 | + |
| 47 | +// Severity returns the rule severity |
| 48 | +func (r *GoogleApigeeOrganizationInvalidRuntimeTypeRule) Severity() string { |
| 49 | + return tflint.ERROR |
| 50 | +} |
| 51 | + |
| 52 | +// Link returns the rule reference link |
| 53 | +func (r *GoogleApigeeOrganizationInvalidRuntimeTypeRule) Link() string { |
| 54 | + return "" |
| 55 | +} |
| 56 | + |
| 57 | +// Check checks the pattern is valid |
| 58 | +func (r *GoogleApigeeOrganizationInvalidRuntimeTypeRule) Check(runner tflint.Runner) error { |
| 59 | + return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { |
| 60 | + var val string |
| 61 | + err := runner.EvaluateExpr(attribute.Expr, &val, nil) |
| 62 | + |
| 63 | + validateFunc := validation.StringInSlice([]string{"CLOUD", "HYBRID", ""}, false) |
| 64 | + |
| 65 | + return runner.EnsureNoError(err, func() error { |
| 66 | + _, errors := validateFunc(val, r.attributeName) |
| 67 | + for _, err := range errors { |
| 68 | + runner.EmitIssueOnExpr(r, err.Error(), attribute.Expr) |
| 69 | + } |
| 70 | + return nil |
| 71 | + }) |
| 72 | + }) |
| 73 | +} |
0 commit comments