From 7d57a87b217c2461ca8c1d6a2384a17aeaf19f49 Mon Sep 17 00:00:00 2001 From: Kazuma Watanabe Date: Sat, 5 Jun 2021 23:54:37 +0900 Subject: [PATCH] Update Magic Modules (#98) --- ...erconnect_attachment_invalid_encryption.go | 73 +++++++++++++++++++ .../google_pubsub_schema_invalid_type.go | 73 +++++++++++++++++++ rules/magicmodules/product.go | 10 +++ rules/magicmodules/provider.go | 2 + tools/magic-modules | 2 +- 5 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 rules/magicmodules/google_compute_interconnect_attachment_invalid_encryption.go create mode 100644 rules/magicmodules/google_pubsub_schema_invalid_type.go diff --git a/rules/magicmodules/google_compute_interconnect_attachment_invalid_encryption.go b/rules/magicmodules/google_compute_interconnect_attachment_invalid_encryption.go new file mode 100644 index 0000000..90387b3 --- /dev/null +++ b/rules/magicmodules/google_compute_interconnect_attachment_invalid_encryption.go @@ -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 + }) + }) +} diff --git a/rules/magicmodules/google_pubsub_schema_invalid_type.go b/rules/magicmodules/google_pubsub_schema_invalid_type.go new file mode 100644 index 0000000..bb0aa5e --- /dev/null +++ b/rules/magicmodules/google_pubsub_schema_invalid_type.go @@ -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 + }) + }) +} diff --git a/rules/magicmodules/product.go b/rules/magicmodules/product.go index 6aece03..fa10586 100644 --- a/rules/magicmodules/product.go +++ b/rules/magicmodules/product.go @@ -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{}, }, @@ -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/"}, diff --git a/rules/magicmodules/provider.go b/rules/magicmodules/provider.go index 7e97d75..e138cd3 100644 --- a/rules/magicmodules/provider.go +++ b/rules/magicmodules/provider.go @@ -60,6 +60,7 @@ var Rules = []tflint.Rule{ NewGoogleComputeGlobalForwardingRuleInvalidLoadBalancingSchemeRule(), NewGoogleComputeGlobalNetworkEndpointGroupInvalidNetworkEndpointTypeRule(), NewGoogleComputeInterconnectAttachmentInvalidBandwidthRule(), + NewGoogleComputeInterconnectAttachmentInvalidEncryptionRule(), NewGoogleComputeInterconnectAttachmentInvalidNameRule(), NewGoogleComputeInterconnectAttachmentInvalidTypeRule(), NewGoogleComputeManagedSslCertificateInvalidTypeRule(), @@ -114,6 +115,7 @@ var Rules = []tflint.Rule{ NewGoogleNotebooksInstanceInvalidDataDiskTypeRule(), NewGoogleNotebooksInstanceInvalidDiskEncryptionRule(), NewGoogleOsConfigPatchDeploymentInvalidPatchDeploymentIdRule(), + NewGooglePubsubSchemaInvalidTypeRule(), NewGoogleRedisInstanceInvalidConnectModeRule(), NewGoogleRedisInstanceInvalidNameRule(), NewGoogleRedisInstanceInvalidTierRule(), diff --git a/tools/magic-modules b/tools/magic-modules index 32cc57f..a3f1295 160000 --- a/tools/magic-modules +++ b/tools/magic-modules @@ -1 +1 @@ -Subproject commit 32cc57fb2fcafd14b0d5601b23594c2bdbaa387e +Subproject commit a3f1295bcc10a4bca8fb40afc921d9e2ead00602