Skip to content

Commit

Permalink
Update Magic Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed Nov 12, 2023
1 parent 7507382 commit 6b4edc2
Show file tree
Hide file tree
Showing 30 changed files with 1,885 additions and 32 deletions.
91 changes: 91 additions & 0 deletions rules/magicmodules/google_alloydb_backup_invalid_type.go
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"
)

// GoogleAlloydbBackupInvalidTypeRule checks the pattern is valid
type GoogleAlloydbBackupInvalidTypeRule struct {
tflint.DefaultRule

resourceType string
attributeName string
}

// NewGoogleAlloydbBackupInvalidTypeRule returns new rule with default attributes
func NewGoogleAlloydbBackupInvalidTypeRule() *GoogleAlloydbBackupInvalidTypeRule {
return &GoogleAlloydbBackupInvalidTypeRule{
resourceType: "google_alloydb_backup",
attributeName: "type",
}
}

// Name returns the rule name
func (r *GoogleAlloydbBackupInvalidTypeRule) Name() string {
return "google_alloydb_backup_invalid_type"
}

// Enabled returns whether the rule is enabled by default
func (r *GoogleAlloydbBackupInvalidTypeRule) Enabled() bool {
return true
}

// Severity returns the rule severity
func (r *GoogleAlloydbBackupInvalidTypeRule) Severity() tflint.Severity {
return tflint.ERROR
}

// Link returns the rule reference link
func (r *GoogleAlloydbBackupInvalidTypeRule) Link() string {
return ""
}

// Check checks the pattern is valid
func (r *GoogleAlloydbBackupInvalidTypeRule) 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{"TYPE_UNSPECIFIED", "ON_DEMAND", "AUTOMATED", "CONTINUOUS", ""}, 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 rules/magicmodules/google_alloydb_cluster_invalid_cluster_type.go
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"
)

// GoogleAlloydbClusterInvalidClusterTypeRule checks the pattern is valid
type GoogleAlloydbClusterInvalidClusterTypeRule struct {
tflint.DefaultRule

resourceType string
attributeName string
}

// NewGoogleAlloydbClusterInvalidClusterTypeRule returns new rule with default attributes
func NewGoogleAlloydbClusterInvalidClusterTypeRule() *GoogleAlloydbClusterInvalidClusterTypeRule {
return &GoogleAlloydbClusterInvalidClusterTypeRule{
resourceType: "google_alloydb_cluster",
attributeName: "cluster_type",
}
}

// Name returns the rule name
func (r *GoogleAlloydbClusterInvalidClusterTypeRule) Name() string {
return "google_alloydb_cluster_invalid_cluster_type"
}

// Enabled returns whether the rule is enabled by default
func (r *GoogleAlloydbClusterInvalidClusterTypeRule) Enabled() bool {
return true
}

// Severity returns the rule severity
func (r *GoogleAlloydbClusterInvalidClusterTypeRule) Severity() tflint.Severity {
return tflint.ERROR
}

// Link returns the rule reference link
func (r *GoogleAlloydbClusterInvalidClusterTypeRule) Link() string {
return ""
}

// Check checks the pattern is valid
func (r *GoogleAlloydbClusterInvalidClusterTypeRule) 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{"PRIMARY", "SECONDARY", ""}, 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (r *GoogleAlloydbInstanceInvalidInstanceTypeRule) Check(runner tflint.Runne
}

err := runner.EvaluateExpr(attribute.Expr, func(val string) error {
validateFunc := validation.StringInSlice([]string{"PRIMARY", "READ_POOL"}, false)
validateFunc := validation.StringInSlice([]string{"PRIMARY", "READ_POOL", "SECONDARY"}, false)

_, errors := validateFunc(val, r.attributeName)
for _, err := range errors {
Expand Down
91 changes: 91 additions & 0 deletions rules/magicmodules/google_alloydb_user_invalid_user_type.go
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"
)

// GoogleAlloydbUserInvalidUserTypeRule checks the pattern is valid
type GoogleAlloydbUserInvalidUserTypeRule struct {
tflint.DefaultRule

resourceType string
attributeName string
}

// NewGoogleAlloydbUserInvalidUserTypeRule returns new rule with default attributes
func NewGoogleAlloydbUserInvalidUserTypeRule() *GoogleAlloydbUserInvalidUserTypeRule {
return &GoogleAlloydbUserInvalidUserTypeRule{
resourceType: "google_alloydb_user",
attributeName: "user_type",
}
}

// Name returns the rule name
func (r *GoogleAlloydbUserInvalidUserTypeRule) Name() string {
return "google_alloydb_user_invalid_user_type"
}

// Enabled returns whether the rule is enabled by default
func (r *GoogleAlloydbUserInvalidUserTypeRule) Enabled() bool {
return true
}

// Severity returns the rule severity
func (r *GoogleAlloydbUserInvalidUserTypeRule) Severity() tflint.Severity {
return tflint.ERROR
}

// Link returns the rule reference link
func (r *GoogleAlloydbUserInvalidUserTypeRule) Link() string {
return ""
}

// Check checks the pattern is valid
func (r *GoogleAlloydbUserInvalidUserTypeRule) 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{"ALLOYDB_BUILT_IN", "ALLOYDB_IAM_USER"}, 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 rules/magicmodules/google_apigee_environment_invalid_type.go
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"
)

// GoogleApigeeEnvironmentInvalidTypeRule checks the pattern is valid
type GoogleApigeeEnvironmentInvalidTypeRule struct {
tflint.DefaultRule

resourceType string
attributeName string
}

// NewGoogleApigeeEnvironmentInvalidTypeRule returns new rule with default attributes
func NewGoogleApigeeEnvironmentInvalidTypeRule() *GoogleApigeeEnvironmentInvalidTypeRule {
return &GoogleApigeeEnvironmentInvalidTypeRule{
resourceType: "google_apigee_environment",
attributeName: "type",
}
}

// Name returns the rule name
func (r *GoogleApigeeEnvironmentInvalidTypeRule) Name() string {
return "google_apigee_environment_invalid_type"
}

// Enabled returns whether the rule is enabled by default
func (r *GoogleApigeeEnvironmentInvalidTypeRule) Enabled() bool {
return true
}

// Severity returns the rule severity
func (r *GoogleApigeeEnvironmentInvalidTypeRule) Severity() tflint.Severity {
return tflint.ERROR
}

// Link returns the rule reference link
func (r *GoogleApigeeEnvironmentInvalidTypeRule) Link() string {
return ""
}

// Check checks the pattern is valid
func (r *GoogleApigeeEnvironmentInvalidTypeRule) 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{"ENVIRONMENT_TYPE_UNSPECIFIED", "BASE", "INTERMEDIATE", "COMPREHENSIVE", ""}, 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (r *GoogleBigQueryRoutineInvalidRoutineTypeRule) Check(runner tflint.Runner
}

err := runner.EvaluateExpr(attribute.Expr, func(val string) error {
validateFunc := validation.StringInSlice([]string{"SCALAR_FUNCTION", "PROCEDURE", "TABLE_VALUED_FUNCTION", ""}, false)
validateFunc := validation.StringInSlice([]string{"SCALAR_FUNCTION", "PROCEDURE", "TABLE_VALUED_FUNCTION"}, false)

_, errors := validateFunc(val, r.attributeName)
for _, err := range errors {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (r *GoogleComputeNetworkEndpointGroupInvalidNetworkEndpointTypeRule) Check(
}

err := runner.EvaluateExpr(attribute.Expr, func(val string) error {
validateFunc := validation.StringInSlice([]string{"GCE_VM_IP", "GCE_VM_IP_PORT", "NON_GCP_PRIVATE_IP_PORT", ""}, false)
validateFunc := validation.StringInSlice([]string{"GCE_VM_IP", "GCE_VM_IP_PORT", "NON_GCP_PRIVATE_IP_PORT", "INTERNET_IP_PORT", "INTERNET_FQDN_PORT", "SERVERLESS", "PRIVATE_SERVICE_CONNECT", ""}, false)

_, errors := validateFunc(val, r.attributeName)
for _, err := range errors {
Expand Down
Loading

0 comments on commit 6b4edc2

Please sign in to comment.