generated from terraform-linters/tflint-ruleset-template
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
844 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
rules/magicmodules/google_compute_interconnect_invalid_interconnect_type.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// This file is automatically generated by Magic Modules and manual | ||
// changes will be clobbered when the file is regenerated. | ||
// | ||
// Please read more about how to change this file in | ||
// .github/CONTRIBUTING.md. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
package magicmodules | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
"github.com/terraform-linters/tflint-plugin-sdk/hclext" | ||
"github.com/terraform-linters/tflint-plugin-sdk/tflint" | ||
) | ||
|
||
// GoogleComputeInterconnectInvalidInterconnectTypeRule checks the pattern is valid | ||
type GoogleComputeInterconnectInvalidInterconnectTypeRule struct { | ||
tflint.DefaultRule | ||
|
||
resourceType string | ||
attributeName string | ||
} | ||
|
||
// NewGoogleComputeInterconnectInvalidInterconnectTypeRule returns new rule with default attributes | ||
func NewGoogleComputeInterconnectInvalidInterconnectTypeRule() *GoogleComputeInterconnectInvalidInterconnectTypeRule { | ||
return &GoogleComputeInterconnectInvalidInterconnectTypeRule{ | ||
resourceType: "google_compute_interconnect", | ||
attributeName: "interconnect_type", | ||
} | ||
} | ||
|
||
// Name returns the rule name | ||
func (r *GoogleComputeInterconnectInvalidInterconnectTypeRule) Name() string { | ||
return "google_compute_interconnect_invalid_interconnect_type" | ||
} | ||
|
||
// Enabled returns whether the rule is enabled by default | ||
func (r *GoogleComputeInterconnectInvalidInterconnectTypeRule) Enabled() bool { | ||
return true | ||
} | ||
|
||
// Severity returns the rule severity | ||
func (r *GoogleComputeInterconnectInvalidInterconnectTypeRule) Severity() tflint.Severity { | ||
return tflint.ERROR | ||
} | ||
|
||
// Link returns the rule reference link | ||
func (r *GoogleComputeInterconnectInvalidInterconnectTypeRule) Link() string { | ||
return "" | ||
} | ||
|
||
// Check checks the pattern is valid | ||
func (r *GoogleComputeInterconnectInvalidInterconnectTypeRule) Check(runner tflint.Runner) error { | ||
resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ | ||
Attributes: []hclext.AttributeSchema{{Name: r.attributeName}}, | ||
}, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, resource := range resources.Blocks { | ||
attribute, exists := resource.Body.Attributes[r.attributeName] | ||
if !exists { | ||
continue | ||
} | ||
|
||
err := runner.EvaluateExpr(attribute.Expr, func(val string) error { | ||
validateFunc := validation.StringInSlice([]string{"DEDICATED", "PARTNER", "IT_PRIVATE"}, false) | ||
|
||
_, errors := validateFunc(val, r.attributeName) | ||
for _, err := range errors { | ||
if err := runner.EmitIssue(r, err.Error(), attribute.Expr.Range()); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
}, nil) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
91 changes: 91 additions & 0 deletions
91
rules/magicmodules/google_compute_interconnect_invalid_link_type.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// This file is automatically generated by Magic Modules and manual | ||
// changes will be clobbered when the file is regenerated. | ||
// | ||
// Please read more about how to change this file in | ||
// .github/CONTRIBUTING.md. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
package magicmodules | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
"github.com/terraform-linters/tflint-plugin-sdk/hclext" | ||
"github.com/terraform-linters/tflint-plugin-sdk/tflint" | ||
) | ||
|
||
// GoogleComputeInterconnectInvalidLinkTypeRule checks the pattern is valid | ||
type GoogleComputeInterconnectInvalidLinkTypeRule struct { | ||
tflint.DefaultRule | ||
|
||
resourceType string | ||
attributeName string | ||
} | ||
|
||
// NewGoogleComputeInterconnectInvalidLinkTypeRule returns new rule with default attributes | ||
func NewGoogleComputeInterconnectInvalidLinkTypeRule() *GoogleComputeInterconnectInvalidLinkTypeRule { | ||
return &GoogleComputeInterconnectInvalidLinkTypeRule{ | ||
resourceType: "google_compute_interconnect", | ||
attributeName: "link_type", | ||
} | ||
} | ||
|
||
// Name returns the rule name | ||
func (r *GoogleComputeInterconnectInvalidLinkTypeRule) Name() string { | ||
return "google_compute_interconnect_invalid_link_type" | ||
} | ||
|
||
// Enabled returns whether the rule is enabled by default | ||
func (r *GoogleComputeInterconnectInvalidLinkTypeRule) Enabled() bool { | ||
return true | ||
} | ||
|
||
// Severity returns the rule severity | ||
func (r *GoogleComputeInterconnectInvalidLinkTypeRule) Severity() tflint.Severity { | ||
return tflint.ERROR | ||
} | ||
|
||
// Link returns the rule reference link | ||
func (r *GoogleComputeInterconnectInvalidLinkTypeRule) Link() string { | ||
return "" | ||
} | ||
|
||
// Check checks the pattern is valid | ||
func (r *GoogleComputeInterconnectInvalidLinkTypeRule) Check(runner tflint.Runner) error { | ||
resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ | ||
Attributes: []hclext.AttributeSchema{{Name: r.attributeName}}, | ||
}, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, resource := range resources.Blocks { | ||
attribute, exists := resource.Body.Attributes[r.attributeName] | ||
if !exists { | ||
continue | ||
} | ||
|
||
err := runner.EvaluateExpr(attribute.Expr, func(val string) error { | ||
validateFunc := validation.StringInSlice([]string{"LINK_TYPE_ETHERNET_10G_LR", "LINK_TYPE_ETHERNET_100G_LR"}, false) | ||
|
||
_, errors := validateFunc(val, r.attributeName) | ||
for _, err := range errors { | ||
if err := runner.EmitIssue(r, err.Error(), attribute.Expr.Range()); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
}, nil) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
90 changes: 90 additions & 0 deletions
90
rules/magicmodules/google_compute_interconnect_invalid_name.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// This file is automatically generated by Magic Modules and manual | ||
// changes will be clobbered when the file is regenerated. | ||
// | ||
// Please read more about how to change this file in | ||
// .github/CONTRIBUTING.md. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
package magicmodules | ||
|
||
import ( | ||
"github.com/terraform-linters/tflint-plugin-sdk/hclext" | ||
"github.com/terraform-linters/tflint-plugin-sdk/tflint" | ||
) | ||
|
||
// GoogleComputeInterconnectInvalidNameRule checks the pattern is valid | ||
type GoogleComputeInterconnectInvalidNameRule struct { | ||
tflint.DefaultRule | ||
|
||
resourceType string | ||
attributeName string | ||
} | ||
|
||
// NewGoogleComputeInterconnectInvalidNameRule returns new rule with default attributes | ||
func NewGoogleComputeInterconnectInvalidNameRule() *GoogleComputeInterconnectInvalidNameRule { | ||
return &GoogleComputeInterconnectInvalidNameRule{ | ||
resourceType: "google_compute_interconnect", | ||
attributeName: "name", | ||
} | ||
} | ||
|
||
// Name returns the rule name | ||
func (r *GoogleComputeInterconnectInvalidNameRule) Name() string { | ||
return "google_compute_interconnect_invalid_name" | ||
} | ||
|
||
// Enabled returns whether the rule is enabled by default | ||
func (r *GoogleComputeInterconnectInvalidNameRule) Enabled() bool { | ||
return true | ||
} | ||
|
||
// Severity returns the rule severity | ||
func (r *GoogleComputeInterconnectInvalidNameRule) Severity() tflint.Severity { | ||
return tflint.ERROR | ||
} | ||
|
||
// Link returns the rule reference link | ||
func (r *GoogleComputeInterconnectInvalidNameRule) Link() string { | ||
return "" | ||
} | ||
|
||
// Check checks the pattern is valid | ||
func (r *GoogleComputeInterconnectInvalidNameRule) Check(runner tflint.Runner) error { | ||
resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ | ||
Attributes: []hclext.AttributeSchema{{Name: r.attributeName}}, | ||
}, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, resource := range resources.Blocks { | ||
attribute, exists := resource.Body.Attributes[r.attributeName] | ||
if !exists { | ||
continue | ||
} | ||
|
||
err := runner.EvaluateExpr(attribute.Expr, func(val string) error { | ||
validateFunc := validateRegexp(`^[a-z]([-a-z0-9]*[a-z0-9])?$`) | ||
|
||
_, errors := validateFunc(val, r.attributeName) | ||
for _, err := range errors { | ||
if err := runner.EmitIssue(r, err.Error(), attribute.Expr.Range()); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
}, nil) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.