Skip to content

Commit

Permalink
Update Magic Modules (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 authored Jun 25, 2023
1 parent 75a16eb commit 149ffc2
Show file tree
Hide file tree
Showing 13 changed files with 800 additions and 273 deletions.
2 changes: 1 addition & 1 deletion rules/magicmodules/generated_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ resource "google_cloud_asset_folder_feed" "main" {
Expected: helper.Issues{
{
Rule: NewGoogleCloudAssetFolderFeedInvalidContentTypeRule(),
Message: `expected content_type to be one of [CONTENT_TYPE_UNSPECIFIED RESOURCE IAM_POLICY ORG_POLICY ACCESS_POLICY ], got INVALID`,
Message: `expected content_type to be one of [CONTENT_TYPE_UNSPECIFIED RESOURCE IAM_POLICY ORG_POLICY OS_INVENTORY ACCESS_POLICY ], got INVALID`,
Range: hcl.Range{
Filename: "resource.tf",
Start: hcl.Pos{Line: 3, Column: 18},
Expand Down
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"
)

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

resourceType string
attributeName string
}

// NewGoogleCertificateManagerCertificateIssuanceConfigInvalidKeyAlgorithmRule returns new rule with default attributes
func NewGoogleCertificateManagerCertificateIssuanceConfigInvalidKeyAlgorithmRule() *GoogleCertificateManagerCertificateIssuanceConfigInvalidKeyAlgorithmRule {
return &GoogleCertificateManagerCertificateIssuanceConfigInvalidKeyAlgorithmRule{
resourceType: "google_certificate_manager_certificate_issuance_config",
attributeName: "key_algorithm",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GoogleCertificateManagerCertificateIssuanceConfigInvalidKeyAlgorithmRule) 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{"RSA_2048", "ECDSA_P256"}, 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 *GoogleCloudAssetFolderFeedInvalidContentTypeRule) Check(runner tflint.R
}

err := runner.EvaluateExpr(attribute.Expr, func(val string) error {
validateFunc := validation.StringInSlice([]string{"CONTENT_TYPE_UNSPECIFIED", "RESOURCE", "IAM_POLICY", "ORG_POLICY", "ACCESS_POLICY", ""}, false)
validateFunc := validation.StringInSlice([]string{"CONTENT_TYPE_UNSPECIFIED", "RESOURCE", "IAM_POLICY", "ORG_POLICY", "OS_INVENTORY", "ACCESS_POLICY", ""}, 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 *GoogleCloudAssetOrganizationFeedInvalidContentTypeRule) Check(runner tf
}

err := runner.EvaluateExpr(attribute.Expr, func(val string) error {
validateFunc := validation.StringInSlice([]string{"CONTENT_TYPE_UNSPECIFIED", "RESOURCE", "IAM_POLICY", "ORG_POLICY", "ACCESS_POLICY", ""}, false)
validateFunc := validation.StringInSlice([]string{"CONTENT_TYPE_UNSPECIFIED", "RESOURCE", "IAM_POLICY", "ORG_POLICY", "OS_INVENTORY", "ACCESS_POLICY", ""}, 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 *GoogleCloudAssetProjectFeedInvalidContentTypeRule) Check(runner tflint.
}

err := runner.EvaluateExpr(attribute.Expr, func(val string) error {
validateFunc := validation.StringInSlice([]string{"CONTENT_TYPE_UNSPECIFIED", "RESOURCE", "IAM_POLICY", "ORG_POLICY", "ACCESS_POLICY", ""}, false)
validateFunc := validation.StringInSlice([]string{"CONTENT_TYPE_UNSPECIFIED", "RESOURCE", "IAM_POLICY", "ORG_POLICY", "OS_INVENTORY", "ACCESS_POLICY", ""}, false)

_, errors := validateFunc(val, r.attributeName)
for _, err := range errors {
Expand Down
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"
)

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

resourceType string
attributeName string
}

// NewGoogleComputeRegionCommitmentInvalidCategoryRule returns new rule with default attributes
func NewGoogleComputeRegionCommitmentInvalidCategoryRule() *GoogleComputeRegionCommitmentInvalidCategoryRule {
return &GoogleComputeRegionCommitmentInvalidCategoryRule{
resourceType: "google_compute_region_commitment",
attributeName: "category",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GoogleComputeRegionCommitmentInvalidCategoryRule) 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{"LICENSE", "MACHINE", ""}, 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 @@ -20,44 +20,44 @@ import (
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)

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

resourceType string
attributeName string
}

// NewGoogleKmsCryptoKeyInvalidPurposeRule returns new rule with default attributes
func NewGoogleKmsCryptoKeyInvalidPurposeRule() *GoogleKmsCryptoKeyInvalidPurposeRule {
return &GoogleKmsCryptoKeyInvalidPurposeRule{
resourceType: "google_kms_crypto_key",
attributeName: "purpose",
// NewGoogleComputeRegionCommitmentInvalidPlanRule returns new rule with default attributes
func NewGoogleComputeRegionCommitmentInvalidPlanRule() *GoogleComputeRegionCommitmentInvalidPlanRule {
return &GoogleComputeRegionCommitmentInvalidPlanRule{
resourceType: "google_compute_region_commitment",
attributeName: "plan",
}
}

// Name returns the rule name
func (r *GoogleKmsCryptoKeyInvalidPurposeRule) Name() string {
return "google_kms_crypto_key_invalid_purpose"
func (r *GoogleComputeRegionCommitmentInvalidPlanRule) Name() string {
return "google_compute_region_commitment_invalid_plan"
}

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

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

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

// Check checks the pattern is valid
func (r *GoogleKmsCryptoKeyInvalidPurposeRule) Check(runner tflint.Runner) error {
func (r *GoogleComputeRegionCommitmentInvalidPlanRule) 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 *GoogleKmsCryptoKeyInvalidPurposeRule) Check(runner tflint.Runner) error
}

err := runner.EvaluateExpr(attribute.Expr, func(val string) error {
validateFunc := validation.StringInSlice([]string{"ENCRYPT_DECRYPT", "ASYMMETRIC_SIGN", "ASYMMETRIC_DECRYPT", "MAC", ""}, false)
validateFunc := validation.StringInSlice([]string{"TWELVE_MONTH", "THIRTY_SIX_MONTH"}, 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 *GoogleSqlSourceRepresentationInstanceInvalidDatabaseVersionRule) Check(
}

err := runner.EvaluateExpr(attribute.Expr, func(val string) error {
validateFunc := validation.StringInSlice([]string{"MYSQL_5_5", "MYSQL_5_6", "MYSQL_5_7", "MYSQL_8_0"}, false)
validateFunc := validation.StringInSlice([]string{"MYSQL_5_6", "MYSQL_5_7", "MYSQL_8_0", "POSTGRES_9_6", "POSTGRES_10", "POSTGRES_11", "POSTGRES_12", "POSTGRES_13", "POSTGRES_14"}, false)

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

0 comments on commit 149ffc2

Please sign in to comment.