Skip to content

Commit ef7dced

Browse files
authored
Merge pull request #5 from terraform-linters/magic_modules
Autogenerate rules from Magic Modules
2 parents 86cf71d + ce25086 commit ef7dced

File tree

110 files changed

+8153
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+8153
-4
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "tools/magic-modules"]
2+
path = tools/magic-modules
3+
url = [email protected]:terraform-linters/magic-modules.git

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ go 1.13
44

55
require (
66
github.com/hashicorp/hcl/v2 v2.6.0
7+
github.com/hashicorp/terraform-plugin-sdk/v2 v2.0.3
78
github.com/terraform-linters/tflint-plugin-sdk v0.5.0
89
)

go.sum

Lines changed: 381 additions & 0 deletions
Large diffs are not rendered by default.

main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ package main
33
import (
44
"github.com/terraform-linters/tflint-plugin-sdk/plugin"
55
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
6+
"github.com/terraform-linters/tflint-ruleset-google/project"
67
"github.com/terraform-linters/tflint-ruleset-google/rules"
78
)
89

910
func main() {
1011
plugin.Serve(&plugin.ServeOpts{
1112
RuleSet: tflint.RuleSet{
1213
Name: "google",
13-
Version: "0.1.0",
14-
Rules: []tflint.Rule{
15-
rules.NewGoogleComputeInstanceExampleTypeRule(),
16-
},
14+
Version: project.Version,
15+
Rules: rules.Rules,
1716
},
1817
})
1918
}

project/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package project
2+
3+
import "fmt"
4+
5+
// Version is ruleset version
6+
const Version string = "0.1.0"
7+
8+
// ReferenceLink returns the rule reference link
9+
func ReferenceLink(name string) string {
10+
return fmt.Sprintf("https://github.com/terraform-linters/tflint-ruleset-google/blob/v%s/docs/rules/%s.md", Version, name)
11+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
15+
package magicmodules
16+
17+
import (
18+
hcl "github.com/hashicorp/hcl/v2"
19+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
20+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
21+
)
22+
23+
// GoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule checks the pattern is valid
24+
type GoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule struct {
25+
resourceType string
26+
attributeName string
27+
}
28+
29+
// NewGoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule returns new rule with default attributes
30+
func NewGoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule() *GoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule {
31+
return &GoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule{
32+
resourceType: "google_access_context_manager_service_perimeter",
33+
attributeName: "perimeter_type",
34+
}
35+
}
36+
37+
// Name returns the rule name
38+
func (r *GoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule) Name() string {
39+
return "google_access_context_manager_service_perimeter_invalid_perimeter_type"
40+
}
41+
42+
// Enabled returns whether the rule is enabled by default
43+
func (r *GoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule) Enabled() bool {
44+
return true
45+
}
46+
47+
// Severity returns the rule severity
48+
func (r *GoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule) Severity() string {
49+
return tflint.ERROR
50+
}
51+
52+
// Link returns the rule reference link
53+
func (r *GoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule) Link() string {
54+
return ""
55+
}
56+
57+
// Check checks the pattern is valid
58+
func (r *GoogleAccessContextManagerServicePerimeterInvalidPerimeterTypeRule) Check(runner tflint.Runner) error {
59+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
60+
var val string
61+
err := runner.EvaluateExpr(attribute.Expr, &val)
62+
63+
validateFunc := validation.StringInSlice([]string{"PERIMETER_TYPE_REGULAR", "PERIMETER_TYPE_BRIDGE", ""}, false)
64+
65+
return runner.EnsureNoError(err, func() error {
66+
_, errors := validateFunc(val, r.attributeName)
67+
for _, err := range errors {
68+
runner.EmitIssueOnExpr(r, err.Error(), attribute.Expr)
69+
}
70+
return nil
71+
})
72+
})
73+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
15+
package magicmodules
16+
17+
import (
18+
hcl "github.com/hashicorp/hcl/v2"
19+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
20+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
21+
)
22+
23+
// GoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule checks the pattern is valid
24+
type GoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule struct {
25+
resourceType string
26+
attributeName string
27+
}
28+
29+
// NewGoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule returns new rule with default attributes
30+
func NewGoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule() *GoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule {
31+
return &GoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule{
32+
resourceType: "google_active_directory_domain_trust",
33+
attributeName: "trust_direction",
34+
}
35+
}
36+
37+
// Name returns the rule name
38+
func (r *GoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule) Name() string {
39+
return "google_active_directory_domain_trust_invalid_trust_direction"
40+
}
41+
42+
// Enabled returns whether the rule is enabled by default
43+
func (r *GoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule) Enabled() bool {
44+
return true
45+
}
46+
47+
// Severity returns the rule severity
48+
func (r *GoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule) Severity() string {
49+
return tflint.ERROR
50+
}
51+
52+
// Link returns the rule reference link
53+
func (r *GoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule) Link() string {
54+
return ""
55+
}
56+
57+
// Check checks the pattern is valid
58+
func (r *GoogleActiveDirectoryDomainTrustInvalidTrustDirectionRule) Check(runner tflint.Runner) error {
59+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
60+
var val string
61+
err := runner.EvaluateExpr(attribute.Expr, &val)
62+
63+
validateFunc := validation.StringInSlice([]string{"INBOUND", "OUTBOUND", "BIDIRECTIONAL"}, false)
64+
65+
return runner.EnsureNoError(err, func() error {
66+
_, errors := validateFunc(val, r.attributeName)
67+
for _, err := range errors {
68+
runner.EmitIssueOnExpr(r, err.Error(), attribute.Expr)
69+
}
70+
return nil
71+
})
72+
})
73+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
15+
package magicmodules
16+
17+
import (
18+
hcl "github.com/hashicorp/hcl/v2"
19+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
20+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
21+
)
22+
23+
// GoogleActiveDirectoryDomainTrustInvalidTrustTypeRule checks the pattern is valid
24+
type GoogleActiveDirectoryDomainTrustInvalidTrustTypeRule struct {
25+
resourceType string
26+
attributeName string
27+
}
28+
29+
// NewGoogleActiveDirectoryDomainTrustInvalidTrustTypeRule returns new rule with default attributes
30+
func NewGoogleActiveDirectoryDomainTrustInvalidTrustTypeRule() *GoogleActiveDirectoryDomainTrustInvalidTrustTypeRule {
31+
return &GoogleActiveDirectoryDomainTrustInvalidTrustTypeRule{
32+
resourceType: "google_active_directory_domain_trust",
33+
attributeName: "trust_type",
34+
}
35+
}
36+
37+
// Name returns the rule name
38+
func (r *GoogleActiveDirectoryDomainTrustInvalidTrustTypeRule) Name() string {
39+
return "google_active_directory_domain_trust_invalid_trust_type"
40+
}
41+
42+
// Enabled returns whether the rule is enabled by default
43+
func (r *GoogleActiveDirectoryDomainTrustInvalidTrustTypeRule) Enabled() bool {
44+
return true
45+
}
46+
47+
// Severity returns the rule severity
48+
func (r *GoogleActiveDirectoryDomainTrustInvalidTrustTypeRule) Severity() string {
49+
return tflint.ERROR
50+
}
51+
52+
// Link returns the rule reference link
53+
func (r *GoogleActiveDirectoryDomainTrustInvalidTrustTypeRule) Link() string {
54+
return ""
55+
}
56+
57+
// Check checks the pattern is valid
58+
func (r *GoogleActiveDirectoryDomainTrustInvalidTrustTypeRule) Check(runner tflint.Runner) error {
59+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
60+
var val string
61+
err := runner.EvaluateExpr(attribute.Expr, &val)
62+
63+
validateFunc := validation.StringInSlice([]string{"FOREST", "EXTERNAL"}, false)
64+
65+
return runner.EnsureNoError(err, func() error {
66+
_, errors := validateFunc(val, r.attributeName)
67+
for _, err := range errors {
68+
runner.EmitIssueOnExpr(r, err.Error(), attribute.Expr)
69+
}
70+
return nil
71+
})
72+
})
73+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
15+
package magicmodules
16+
17+
import (
18+
hcl "github.com/hashicorp/hcl/v2"
19+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
20+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
21+
)
22+
23+
// GoogleAppEngineDomainMappingInvalidOverrideStrategyRule checks the pattern is valid
24+
type GoogleAppEngineDomainMappingInvalidOverrideStrategyRule struct {
25+
resourceType string
26+
attributeName string
27+
}
28+
29+
// NewGoogleAppEngineDomainMappingInvalidOverrideStrategyRule returns new rule with default attributes
30+
func NewGoogleAppEngineDomainMappingInvalidOverrideStrategyRule() *GoogleAppEngineDomainMappingInvalidOverrideStrategyRule {
31+
return &GoogleAppEngineDomainMappingInvalidOverrideStrategyRule{
32+
resourceType: "google_app_engine_domain_mapping",
33+
attributeName: "override_strategy",
34+
}
35+
}
36+
37+
// Name returns the rule name
38+
func (r *GoogleAppEngineDomainMappingInvalidOverrideStrategyRule) Name() string {
39+
return "google_app_engine_domain_mapping_invalid_override_strategy"
40+
}
41+
42+
// Enabled returns whether the rule is enabled by default
43+
func (r *GoogleAppEngineDomainMappingInvalidOverrideStrategyRule) Enabled() bool {
44+
return true
45+
}
46+
47+
// Severity returns the rule severity
48+
func (r *GoogleAppEngineDomainMappingInvalidOverrideStrategyRule) Severity() string {
49+
return tflint.ERROR
50+
}
51+
52+
// Link returns the rule reference link
53+
func (r *GoogleAppEngineDomainMappingInvalidOverrideStrategyRule) Link() string {
54+
return ""
55+
}
56+
57+
// Check checks the pattern is valid
58+
func (r *GoogleAppEngineDomainMappingInvalidOverrideStrategyRule) Check(runner tflint.Runner) error {
59+
return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
60+
var val string
61+
err := runner.EvaluateExpr(attribute.Expr, &val)
62+
63+
validateFunc := validation.StringInSlice([]string{"STRICT", "OVERRIDE", ""}, false)
64+
65+
return runner.EnsureNoError(err, func() error {
66+
_, errors := validateFunc(val, r.attributeName)
67+
for _, err := range errors {
68+
runner.EmitIssueOnExpr(r, err.Error(), attribute.Expr)
69+
}
70+
return nil
71+
})
72+
})
73+
}

0 commit comments

Comments
 (0)