Skip to content

Commit 725f7c4

Browse files
committed
Project tweaks
1 parent 29b8f69 commit 725f7c4

File tree

8 files changed

+457
-71
lines changed

8 files changed

+457
-71
lines changed

LICENSE

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

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ build:
88

99
install: build
1010
mkdir -p ~/.tflint.d/plugins
11-
mv ./tflint-ruleset-template ~/.tflint.d/plugins
11+
mv ./tflint-ruleset-google ~/.tflint.d/plugins

README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
# TFLint Ruleset Template
1+
# WORKING IN PROGRESS AND MAINTAINER WANTED!
22

3-
This is a template repository for building a custom ruleset. You can create a plugin repository from "Use this template".
3+
This project was started to support terraform-provider-google resources in TFLint. Everything is working in progress and not available as a plugin. If you are interested in this project, consider the following:
4+
5+
- Open an issue for the rule you want
6+
- Provider-specific knowledge is very important. Sharing the problems you faced will make it clear what we need to develop.
7+
- Write a rule and open a pull request
8+
- If you are already familiar with tflint rulesets, Writing rules to solve open issues helps all users of TFLint. If you are interested but are not familiar, please let us know. Support you as much as possible.
9+
- Make automatic rule generation system
10+
- In reality, it is impossible to manage rules for so many resources by hand. tflint has a mechanism to automatically generate AWS validation rules from aws-sdk (See [here](https://github.com/terraform-linters/tflint/blob/master/docs/DEVELOPING.md#sdk-based)). Building such a system can bring a lot of value at low cost.
11+
12+
See [terraform-lintes/tflint#606](https://github.com/terraform-linters/tflint/issues/606) for more details.
13+
14+
# TFLint Ruleset for terraform-provider-google
15+
16+
TFLint ruleset plugin for Terraform Google Cloud Platform provider
417

518
## Requirements
619

@@ -9,10 +22,10 @@ This is a template repository for building a custom ruleset. You can create a pl
922

1023
## Installation
1124

12-
Download the plugin and place it in `~/.tflint.d/plugins/tflint-ruleset-template` (or `./.tflint.d/plugins/tflint-ruleset-template`). When using the plugin, configure as follows in `.tflint.hcl`:
25+
Download the plugin and place it in `~/.tflint.d/plugins/tflint-ruleset-google` (or `./.tflint.d/plugins/tflint-ruleset-google`). When using the plugin, configure as follows in `.tflint.hcl`:
1326

1427
```hcl
15-
plugin "template" {
28+
plugin "google" {
1629
enabled = true
1730
}
1831
```
@@ -21,7 +34,7 @@ plugin "template" {
2134

2235
|Name|Description|Severity|Enabled|Link|
2336
| --- | --- | --- | --- | --- |
24-
|aws_instance_example_type|Show instance type|ERROR|||
37+
|google_compute_instance_example_type|Show machine type|ERROR|||
2538

2639
## Building the plugin
2740

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/terraform-linters/tflint-ruleset-template
1+
module github.com/terraform-linters/tflint-ruleset-google
22

33
go 1.13
44

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package main
22

33
import (
4-
"github.com/terraform-linters/tflint-ruleset-template/rules"
54
"github.com/terraform-linters/tflint-plugin-sdk/plugin"
65
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
6+
"github.com/terraform-linters/tflint-ruleset-google/rules"
77
)
88

99
func main() {
1010
plugin.Serve(&plugin.ServeOpts{
1111
RuleSet: tflint.RuleSet{
12-
Name: "template",
12+
Name: "google",
1313
Version: "0.1.0",
1414
Rules: []tflint.Rule{
15-
rules.NewAwsInstanceExampleTypeRule(),
15+
rules.NewGoogleComputeInstanceExampleTypeRule(),
1616
},
1717
},
1818
})

rules/aws_instance_example_type.go

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package rules
2+
3+
import (
4+
"fmt"
5+
6+
hcl "github.com/hashicorp/hcl/v2"
7+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
8+
)
9+
10+
// GoogleComputeInstanceExampleTypeRule checks whether ...
11+
type GoogleComputeInstanceExampleTypeRule struct{}
12+
13+
// NewGoogleComputeInstanceExampleTypeRule returns a new rule
14+
func NewGoogleComputeInstanceExampleTypeRule() *GoogleComputeInstanceExampleTypeRule {
15+
return &GoogleComputeInstanceExampleTypeRule{}
16+
}
17+
18+
// Name returns the rule name
19+
func (r *GoogleComputeInstanceExampleTypeRule) Name() string {
20+
return "google_compute_instance_example_type"
21+
}
22+
23+
// Enabled returns whether the rule is enabled by default
24+
func (r *GoogleComputeInstanceExampleTypeRule) Enabled() bool {
25+
return true
26+
}
27+
28+
// Severity returns the rule severity
29+
func (r *GoogleComputeInstanceExampleTypeRule) Severity() string {
30+
return tflint.ERROR
31+
}
32+
33+
// Link returns the rule reference link
34+
func (r *GoogleComputeInstanceExampleTypeRule) Link() string {
35+
return ""
36+
}
37+
38+
// Check checks whether ...
39+
func (r *GoogleComputeInstanceExampleTypeRule) Check(runner tflint.Runner) error {
40+
return runner.WalkResourceAttributes("google_compute_instance", "machine_type", func(attribute *hcl.Attribute) error {
41+
var machineType string
42+
err := runner.EvaluateExpr(attribute.Expr, &machineType)
43+
44+
return runner.EnsureNoError(err, func() error {
45+
return runner.EmitIssue(
46+
r,
47+
fmt.Sprintf("machine type is %s", machineType),
48+
attribute.Expr.Range(),
49+
tflint.Metadata{Expr: attribute.Expr},
50+
)
51+
})
52+
})
53+
}

rules/aws_instance_example_type_test.go renamed to rules/google_compute_instance_example_type_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/terraform-linters/tflint-plugin-sdk/helper"
88
)
99

10-
func Test_AwsInstanceExampleType(t *testing.T) {
10+
func Test_GoogleComputeInstanceExampleType(t *testing.T) {
1111
cases := []struct {
1212
Name string
1313
Content string
@@ -16,24 +16,24 @@ func Test_AwsInstanceExampleType(t *testing.T) {
1616
{
1717
Name: "issue found",
1818
Content: `
19-
resource "aws_instance" "web" {
20-
instance_type = "t2.micro"
19+
resource "google_compute_instance" "vm_instance" {
20+
machine_type = "f1-micro"
2121
}`,
2222
Expected: helper.Issues{
2323
{
24-
Rule: NewAwsInstanceExampleTypeRule(),
25-
Message: "instance type is t2.micro",
24+
Rule: NewGoogleComputeInstanceExampleTypeRule(),
25+
Message: "machine type is f1-micro",
2626
Range: hcl.Range{
2727
Filename: "resource.tf",
28-
Start: hcl.Pos{Line: 3, Column: 21},
29-
End: hcl.Pos{Line: 3, Column: 31},
28+
Start: hcl.Pos{Line: 3, Column: 20},
29+
End: hcl.Pos{Line: 3, Column: 30},
3030
},
3131
},
3232
},
3333
},
3434
}
3535

36-
rule := NewAwsInstanceExampleTypeRule()
36+
rule := NewGoogleComputeInstanceExampleTypeRule()
3737

3838
for _, tc := range cases {
3939
runner := helper.TestRunner(t, map[string]string{"resource.tf": tc.Content})

0 commit comments

Comments
 (0)