Skip to content

Update Magic Modules #359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions rules/magicmodules/api_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var APIDefinition = map[string]string{
"google_compute_instance_group_membership": "compute.googleapis.com",
"google_compute_instance_group_named_port": "compute.googleapis.com",
"google_compute_instance_settings": "compute.googleapis.com",
"google_compute_interconnect": "compute.googleapis.com",
"google_compute_interconnect_attachment": "compute.googleapis.com",
"google_compute_managed_ssl_certificate": "compute.googleapis.com",
"google_compute_network": "compute.googleapis.com",
Expand Down Expand Up @@ -198,7 +199,10 @@ var APIDefinition = map[string]string{
"google_data_catalog_taxonomy": "datacatalog.googleapis.com",
"google_data_fusion_instance": "datafusion.googleapis.com",
"google_data_pipeline_pipeline": "datapipelines.googleapis.com",
"google_dataplex_aspect_type": "dataplex.googleapis.com",
"google_dataplex_datascan": "dataplex.googleapis.com",
"google_dataplex_entry_group": "dataplex.googleapis.com",
"google_dataplex_entry_type": "dataplex.googleapis.com",
"google_dataplex_task": "dataplex.googleapis.com",
"google_dataproc_autoscaling_policy": "dataproc.googleapis.com",
"google_datastore_index": "datastore.googleapis.com",
Expand Down Expand Up @@ -281,6 +285,7 @@ var APIDefinition = map[string]string{
"google_identity_platform_tenant_oauth_idp_config": "identitytoolkit.googleapis.com",
"google_integration_connectors_connection": "connectors.googleapis.com",
"google_integration_connectors_endpoint_attachment": "connectors.googleapis.com",
"google_integration_connectors_managed_zone": "connectors.googleapis.com",
"google_integrations_auth_config": "integrations.googleapis.com",
"google_integrations_client": "integrations.googleapis.com",
"google_kms_crypto_key": "cloudkms.googleapis.com",
Expand All @@ -296,6 +301,7 @@ var APIDefinition = map[string]string{
"google_logging_organization_settings": "logging.googleapis.com",
"google_looker_instance": "looker.googleapis.com",
"google_memcache_instance": "memcache.googleapis.com",
"google_dataproc_metastore_federation": "metastore.googleapis.com",
"google_dataproc_metastore_service": "metastore.googleapis.com",
"google_migration_center_group": "migrationcenter.googleapis.com",
"google_migration_center_preference_set": "migrationcenter.googleapis.com",
Expand Down Expand Up @@ -323,13 +329,20 @@ var APIDefinition = map[string]string{
"google_network_connectivity_service_connection_policy": "networkconnectivity.googleapis.com",
"google_network_management_connectivity_test_resource": "networkmanagement.googleapis.com",
"google_network_security_address_group": "networksecurity.googleapis.com",
"google_network_security_firewall_endpoint": "networksecurity.googleapis.com",
"google_network_security_firewall_endpoint_association": "networksecurity.googleapis.com",
"google_network_security_gateway_security_policy": "networksecurity.googleapis.com",
"google_network_security_gateway_security_policy_rule": "networksecurity.googleapis.com",
"google_network_security_security_profile": "networksecurity.googleapis.com",
"google_network_security_security_profile_group": "networksecurity.googleapis.com",
"google_network_security_tls_inspection_policy": "networksecurity.googleapis.com",
"google_network_security_url_lists": "networksecurity.googleapis.com",
"google_network_services_edge_cache_keyset": "networkservices.googleapis.com",
"google_network_services_edge_cache_origin": "networkservices.googleapis.com",
"google_network_services_edge_cache_service": "networkservices.googleapis.com",
"google_network_services_gateway": "networkservices.googleapis.com",
"google_network_services_lb_route_extension": "networkservices.googleapis.com",
"google_network_services_lb_traffic_extension": "networkservices.googleapis.com",
"google_notebooks_environment": "notebooks.googleapis.com",
"google_notebooks_instance": "notebooks.googleapis.com",
"google_notebooks_location": "notebooks.googleapis.com",
Expand All @@ -340,6 +353,7 @@ var APIDefinition = map[string]string{
"google_privateca_ca_pool": "privateca.googleapis.com",
"google_privateca_certificate": "privateca.googleapis.com",
"google_privateca_certificate_authority": "privateca.googleapis.com",
"google_privateca_certificate_template": "privateca.googleapis.com",
"google_public_ca_external_account_key": "publicca.googleapis.com",
"google_pubsub_schema": "pubsub.googleapis.com",
"google_pubsub_subscription": "pubsub.googleapis.com",
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"
)

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

resourceType string
attributeName string
}

// NewGoogleComputeInterconnectInvalidInterconnectTypeRule returns new rule with default attributes
func NewGoogleComputeInterconnectInvalidInterconnectTypeRule() *GoogleComputeInterconnectInvalidInterconnectTypeRule {
return &GoogleComputeInterconnectInvalidInterconnectTypeRule{
resourceType: "google_compute_interconnect",
attributeName: "interconnect_type",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GoogleComputeInterconnectInvalidInterconnectTypeRule) 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{"DEDICATED", "PARTNER", "IT_PRIVATE"}, 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"
)

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

resourceType string
attributeName string
}

// NewGoogleComputeInterconnectInvalidLinkTypeRule returns new rule with default attributes
func NewGoogleComputeInterconnectInvalidLinkTypeRule() *GoogleComputeInterconnectInvalidLinkTypeRule {
return &GoogleComputeInterconnectInvalidLinkTypeRule{
resourceType: "google_compute_interconnect",
attributeName: "link_type",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GoogleComputeInterconnectInvalidLinkTypeRule) 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{"LINK_TYPE_ETHERNET_10G_LR", "LINK_TYPE_ETHERNET_100G_LR"}, 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
}
90 changes: 90 additions & 0 deletions rules/magicmodules/google_compute_interconnect_invalid_name.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// ----------------------------------------------------------------------------
//
// *** 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/terraform-linters/tflint-plugin-sdk/hclext"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)

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

resourceType string
attributeName string
}

// NewGoogleComputeInterconnectInvalidNameRule returns new rule with default attributes
func NewGoogleComputeInterconnectInvalidNameRule() *GoogleComputeInterconnectInvalidNameRule {
return &GoogleComputeInterconnectInvalidNameRule{
resourceType: "google_compute_interconnect",
attributeName: "name",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GoogleComputeInterconnectInvalidNameRule) 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 := validateRegexp(`^[a-z]([-a-z0-9]*[a-z0-9])?$`)

_, 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
Loading