Skip to content

Commit

Permalink
Autogenerate rules from Magic Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed Sep 22, 2020
1 parent 86cf71d commit ce25086
Show file tree
Hide file tree
Showing 110 changed files with 8,153 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tools/magic-modules"]
path = tools/magic-modules
url = [email protected]:terraform-linters/magic-modules.git
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ go 1.13

require (
github.com/hashicorp/hcl/v2 v2.6.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.0.3
github.com/terraform-linters/tflint-plugin-sdk v0.5.0
)
381 changes: 381 additions & 0 deletions go.sum

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ package main
import (
"github.com/terraform-linters/tflint-plugin-sdk/plugin"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
"github.com/terraform-linters/tflint-ruleset-google/project"
"github.com/terraform-linters/tflint-ruleset-google/rules"
)

func main() {
plugin.Serve(&plugin.ServeOpts{
RuleSet: tflint.RuleSet{
Name: "google",
Version: "0.1.0",
Rules: []tflint.Rule{
rules.NewGoogleComputeInstanceExampleTypeRule(),
},
Version: project.Version,
Rules: rules.Rules,
},
})
}
11 changes: 11 additions & 0 deletions project/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package project

import "fmt"

// Version is ruleset version
const Version string = "0.1.0"

// ReferenceLink returns the rule reference link
func ReferenceLink(name string) string {
return fmt.Sprintf("https://github.com/terraform-linters/tflint-ruleset-google/blob/v%s/docs/rules/%s.md", Version, name)
}
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"
)

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

// NewGoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule returns new rule with default attributes
func NewGoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule() *GoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule {
return &GoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule{
resourceType: "google_access_context_manager_service_perimeter",
attributeName: "perimeter_type",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule) 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)

validateFunc := validation.StringInSlice([]string{"PERIMETER_TYPE_REGULAR", "PERIMETER_TYPE_BRIDGE", ""}, 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
})
})
}
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"
)

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

// NewGoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule returns new rule with default attributes
func NewGoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule() *GoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule {
return &GoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule{
resourceType: "google_active_directory_domain_trust",
attributeName: "trust_direction",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule) 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)

validateFunc := validation.StringInSlice([]string{"INBOUND", "OUTBOUND", "BIDIRECTIONAL"}, 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
})
})
}
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"
)

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

// NewGoogleActiveDirectoryDomainTrustInvalidTrustTypeRule returns new rule with default attributes
func NewGoogleActiveDirectoryDomainTrustInvalidTrustTypeRule() *GoogleActiveDirectoryDomainTrustInvalidTrustTypeRule {
return &GoogleActiveDirectoryDomainTrustInvalidTrustTypeRule{
resourceType: "google_active_directory_domain_trust",
attributeName: "trust_type",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GoogleActiveDirectoryDomainTrustInvalidTrustTypeRule) 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)

validateFunc := validation.StringInSlice([]string{"FOREST", "EXTERNAL"}, 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
})
})
}
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"
)

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

// NewGoogleAppEngineDomainMappingInvalidOverrideStrategyRule returns new rule with default attributes
func NewGoogleAppEngineDomainMappingInvalidOverrideStrategyRule() *GoogleAppEngineDomainMappingInvalidOverrideStrategyRule {
return &GoogleAppEngineDomainMappingInvalidOverrideStrategyRule{
resourceType: "google_app_engine_domain_mapping",
attributeName: "override_strategy",
}
}

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

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

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

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

// Check checks the pattern is valid
func (r *GoogleAppEngineDomainMappingInvalidOverrideStrategyRule) 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)

validateFunc := validation.StringInSlice([]string{"STRICT", "OVERRIDE", ""}, 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
})
})
}
Loading

0 comments on commit ce25086

Please sign in to comment.