Skip to content

Commit

Permalink
Update Magic Modules (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed Jun 5, 2021
1 parent 77affcf commit 7d57a87
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// 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 (
hcl "github.com/hashicorp/hcl/v2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)

// GoogleComputeInterconnectAttachmentInvalidEncryptionRule checks the pattern is valid
type GoogleComputeInterconnectAttachmentInvalidEncryptionRule struct {
resourceType string
attributeName string
}

// NewGoogleComputeInterconnectAttachmentInvalidEncryptionRule returns new rule with default attributes
func NewGoogleComputeInterconnectAttachmentInvalidEncryptionRule() *GoogleComputeInterconnectAttachmentInvalidEncryptionRule {
return &GoogleComputeInterconnectAttachmentInvalidEncryptionRule{
resourceType: "google_compute_interconnect_attachment",
attributeName: "encryption",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GoogleComputeInterconnectAttachmentInvalidEncryptionRule) Check(runner tflint.Runner) error {
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
var val string
err := runner.EvaluateExpr(attribute.Expr, &val, nil)

validateFunc := validation.StringInSlice([]string{"NONE", "IPSEC", ""}, false)

return runner.EnsureNoError(err, func() error {
_, errors := validateFunc(val, r.attributeName)
for _, err := range errors {
runner.EmitIssueOnExpr(r, err.Error(), attribute.Expr)
}
return nil
})
})
}
73 changes: 73 additions & 0 deletions rules/magicmodules/google_pubsub_schema_invalid_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// 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 (
hcl "github.com/hashicorp/hcl/v2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)

// GooglePubsubSchemaInvalidTypeRule checks the pattern is valid
type GooglePubsubSchemaInvalidTypeRule struct {
resourceType string
attributeName string
}

// NewGooglePubsubSchemaInvalidTypeRule returns new rule with default attributes
func NewGooglePubsubSchemaInvalidTypeRule() *GooglePubsubSchemaInvalidTypeRule {
return &GooglePubsubSchemaInvalidTypeRule{
resourceType: "google_pubsub_schema",
attributeName: "type",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GooglePubsubSchemaInvalidTypeRule) Check(runner tflint.Runner) error {
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
var val string
err := runner.EvaluateExpr(attribute.Expr, &val, nil)

validateFunc := validation.StringInSlice([]string{"TYPE_UNSPECIFIED", "PROTOCOL_BUFFER", "AVRO", ""}, false)

return runner.EnsureNoError(err, func() error {
_, errors := validateFunc(val, r.attributeName)
for _, err := range errors {
runner.EmitIssueOnExpr(r, err.Error(), attribute.Expr)
}
return nil
})
})
}
10 changes: 10 additions & 0 deletions rules/magicmodules/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ var Products = map[string]Product{
{Name: "Dialogflow API", URL: "https://console.cloud.google.com/apis/library/dialogflow.googleapis.com"},
},
},
"google_dialogflow_fulfillment": {
APIsRequired: []APIReference{
{Name: "Dialogflow API", URL: "https://console.cloud.google.com/apis/library/dialogflow.googleapis.com"},
},
},
"google_firestore_index": {
APIsRequired: []APIReference{},
},
Expand Down Expand Up @@ -775,6 +780,11 @@ var Products = map[string]Product{
{Name: "Cloud Pub/Sub API", URL: "https://console.cloud.google.com/apis/library/pubsub.googleapis.com/"},
},
},
"google_pubsub_schema": {
APIsRequired: []APIReference{
{Name: "Cloud Pub/Sub API", URL: "https://console.cloud.google.com/apis/library/pubsub.googleapis.com/"},
},
},
"google_spanner_instance": {
APIsRequired: []APIReference{
{Name: "Cloud Spanner API", URL: "https://console.cloud.google.com/apis/library/spanner.googleapis.com/"},
Expand Down
2 changes: 2 additions & 0 deletions rules/magicmodules/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var Rules = []tflint.Rule{
NewGoogleComputeGlobalForwardingRuleInvalidLoadBalancingSchemeRule(),
NewGoogleComputeGlobalNetworkEndpointGroupInvalidNetworkEndpointTypeRule(),
NewGoogleComputeInterconnectAttachmentInvalidBandwidthRule(),
NewGoogleComputeInterconnectAttachmentInvalidEncryptionRule(),
NewGoogleComputeInterconnectAttachmentInvalidNameRule(),
NewGoogleComputeInterconnectAttachmentInvalidTypeRule(),
NewGoogleComputeManagedSslCertificateInvalidTypeRule(),
Expand Down Expand Up @@ -114,6 +115,7 @@ var Rules = []tflint.Rule{
NewGoogleNotebooksInstanceInvalidDataDiskTypeRule(),
NewGoogleNotebooksInstanceInvalidDiskEncryptionRule(),
NewGoogleOsConfigPatchDeploymentInvalidPatchDeploymentIdRule(),
NewGooglePubsubSchemaInvalidTypeRule(),
NewGoogleRedisInstanceInvalidConnectModeRule(),
NewGoogleRedisInstanceInvalidNameRule(),
NewGoogleRedisInstanceInvalidTierRule(),
Expand Down
2 changes: 1 addition & 1 deletion tools/magic-modules
Submodule magic-modules updated 137 files

0 comments on commit 7d57a87

Please sign in to comment.