Skip to content

Commit

Permalink
Update Magic Modules (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 authored Nov 12, 2023
1 parent 7507382 commit af0f1ab
Show file tree
Hide file tree
Showing 30 changed files with 1,731 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,44 @@ import (
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)

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

resourceType string
attributeName string
}

// NewGoogleCloudiotRegistryInvalidLogLevelRule returns new rule with default attributes
func NewGoogleCloudiotRegistryInvalidLogLevelRule() *GoogleCloudiotRegistryInvalidLogLevelRule {
return &GoogleCloudiotRegistryInvalidLogLevelRule{
resourceType: "google_cloudiot_registry",
attributeName: "log_level",
// 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 *GoogleCloudiotRegistryInvalidLogLevelRule) Name() string {
return "google_cloudiot_registry_invalid_log_level"
func (r *GoogleAlloydbBackupInvalidTypeRule) Name() string {
return "google_alloydb_backup_invalid_type"
}

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

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

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

// Check checks the pattern is valid
func (r *GoogleCloudiotRegistryInvalidLogLevelRule) Check(runner tflint.Runner) error {
func (r *GoogleAlloydbBackupInvalidTypeRule) Check(runner tflint.Runner) error {
resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{
Attributes: []hclext.AttributeSchema{{Name: r.attributeName}},
}, nil)
Expand All @@ -72,7 +72,7 @@ func (r *GoogleCloudiotRegistryInvalidLogLevelRule) Check(runner tflint.Runner)
}

err := runner.EvaluateExpr(attribute.Expr, func(val string) error {
validateFunc := validation.StringInSlice([]string{"NONE", "ERROR", "INFO", "DEBUG", ""}, false)
validateFunc := validation.StringInSlice([]string{"TYPE_UNSPECIFIED", "ON_DEMAND", "AUTOMATED", "CONTINUOUS", ""}, false)

_, errors := validateFunc(val, r.attributeName)
for _, err := range errors {
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (r *GoogleComputeRouterNatInvalidNatIpAllocateOptionRule) Check(runner tfli
}

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

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

0 comments on commit af0f1ab

Please sign in to comment.