Skip to content

Commit

Permalink
Update Magic Modules (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed May 5, 2024
1 parent 6ae027b commit 8a8388e
Show file tree
Hide file tree
Showing 17 changed files with 1,524 additions and 348 deletions.
716 changes: 370 additions & 346 deletions rules/magicmodules/api_definition.go

Large diffs are not rendered by default.

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"
)

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

resourceType string
attributeName string
}

// NewGoogleBigqueryRoutineInvalidDataGovernanceTypeRule returns new rule with default attributes
func NewGoogleBigqueryRoutineInvalidDataGovernanceTypeRule() *GoogleBigqueryRoutineInvalidDataGovernanceTypeRule {
return &GoogleBigqueryRoutineInvalidDataGovernanceTypeRule{
resourceType: "google_bigquery_routine",
attributeName: "data_governance_type",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GoogleBigqueryRoutineInvalidDataGovernanceTypeRule) 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{"DATA_MASKING", ""}, 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
@@ -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"
)

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

resourceType string
attributeName string
}

// NewGoogleBillingBudgetInvalidOwnershipScopeRule returns new rule with default attributes
func NewGoogleBillingBudgetInvalidOwnershipScopeRule() *GoogleBillingBudgetInvalidOwnershipScopeRule {
return &GoogleBillingBudgetInvalidOwnershipScopeRule{
resourceType: "google_billing_budget",
attributeName: "ownership_scope",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GoogleBillingBudgetInvalidOwnershipScopeRule) 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{"OWNERSHIP_SCOPE_UNSPECIFIED", "ALL_USERS", "BILLING_ACCOUNT", ""}, 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
@@ -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"
)

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

resourceType string
attributeName string
}

// NewGoogleCertificateManagerDnsAuthorizationInvalidTypeRule returns new rule with default attributes
func NewGoogleCertificateManagerDnsAuthorizationInvalidTypeRule() *GoogleCertificateManagerDnsAuthorizationInvalidTypeRule {
return &GoogleCertificateManagerDnsAuthorizationInvalidTypeRule{
resourceType: "google_certificate_manager_dns_authorization",
attributeName: "type",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GoogleCertificateManagerDnsAuthorizationInvalidTypeRule) 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{"FIXED_RECORD", "PER_PROJECT_RECORD", ""}, 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
@@ -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"
)

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

resourceType string
attributeName string
}

// NewGoogleCloudQuotasQuotaPreferenceInvalidIgnoreSafetyChecksRule returns new rule with default attributes
func NewGoogleCloudQuotasQuotaPreferenceInvalidIgnoreSafetyChecksRule() *GoogleCloudQuotasQuotaPreferenceInvalidIgnoreSafetyChecksRule {
return &GoogleCloudQuotasQuotaPreferenceInvalidIgnoreSafetyChecksRule{
resourceType: "google_cloud_quotas_quota_preference",
attributeName: "ignore_safety_checks",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GoogleCloudQuotasQuotaPreferenceInvalidIgnoreSafetyChecksRule) 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{"QUOTA_SAFETY_CHECK_UNSPECIFIED", "QUOTA_DECREASE_BELOW_USAGE", "QUOTA_DECREASE_PERCENTAGE_TOO_HIGH", ""}, 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
}
Loading

0 comments on commit 8a8388e

Please sign in to comment.