Skip to content

Commit 29e2c5a

Browse files
committed
Introduce "preset" config
1 parent 7b44938 commit 29e2c5a

28 files changed

+373
-40
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ plugin "terraform" {
3232
}
3333
```
3434

35+
For more configuration about the plugin, see [Plugin Configuration](docs/configuration.md).
36+
3537
## Rules
3638

3739
See [Rules](docs/rules/README.md).

docs/configuration.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Configuration
2+
3+
This plugin can take advantage of additional features by configuring the plugin block. Currently, this configuration is only available for preset.
4+
5+
Here's an example:
6+
7+
```hcl
8+
plugin "terraform" {
9+
// Plugin common attributes
10+
11+
preset = "recommended"
12+
}
13+
```
14+
15+
## `preset`
16+
17+
Default: `all` (`recommended` for the bundled plugin)
18+
19+
Enable multiple rules at once. Please see [Rules](rules/README.md) for details. Possible values are `recommended` and `all`.
20+
21+
When using the bundled plugin built into TFLint, you can use this plugin without declaring a "plugin" block. In this case the default is `recommeneded`.

docs/rules/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
# Rules
22

3-
Terraform language rules implement recommendations from the [Terraform language documentation](https://www.terraform.io/language). If you want to enforce additional usage and style conventions in your configuration, you can author your own ruleset plugin.
3+
Terraform Language rules implement recommendations from the [Terraform Language documentation](https://www.terraform.io/language).
44

5-
Below is a list of available rules.
5+
All rules are enabled by default, but by setting `preset = "recommended"`, you can enable only the rules marked "Recommended" among the following rules. See [Configuration](../configuration.md) for details.
66

7-
|Rule|Description|Enabled|
7+
|Rule|Description|Recommended|
88
| --- | --- | --- |
99
|[terraform_comment_syntax](terraform_comment_syntax.md)|Disallow `//` comments in favor of `#`||
10-
|[terraform_deprecated_index](terraform_deprecated_index.md)|Disallow legacy dot index syntax||
10+
|[terraform_deprecated_index](terraform_deprecated_index.md)|Disallow legacy dot index syntax||
1111
|[terraform_deprecated_interpolation](terraform_deprecated_interpolation.md)|Disallow deprecated (0.11-style) interpolation||
1212
|[terraform_documented_outputs](terraform_documented_outputs.md)|Disallow `output` declarations without description||
1313
|[terraform_documented_variables](terraform_documented_variables.md)|Disallow `variable` declarations without description||
14-
|[terraform_empty_list_equality](terraform_empty_list_equality.md)|Disallow comparisons with `[]` when checking if a collection is empty||
14+
|[terraform_empty_list_equality](terraform_empty_list_equality.md)|Disallow comparisons with `[]` when checking if a collection is empty||
1515
|[terraform_module_pinned_source](terraform_module_pinned_source.md)|Disallow specifying a git or mercurial repository as a module source without pinning to a version||
1616
|[terraform_module_version](terraform_module_version.md)|Checks that Terraform modules sourced from a registry specify a version||
1717
|[terraform_naming_convention](terraform_naming_convention.md)|Enforces naming conventions for resources, data sources, etc||
18-
|[terraform_required_providers](terraform_required_providers.md)|Require that all providers have version constraints through required_providers||
19-
|[terraform_required_version](terraform_required_version.md)|Disallow `terraform` declarations without require_version||
18+
|[terraform_required_providers](terraform_required_providers.md)|Require that all providers have version constraints through required_providers||
19+
|[terraform_required_version](terraform_required_version.md)|Disallow `terraform` declarations without require_version||
2020
|[terraform_standard_module_structure](terraform_standard_module_structure.md)|Ensure that a module complies with the Terraform Standard Module Structure||
21-
|[terraform_typed_variables](terraform_typed_variables.md)|Disallow `variable` declarations without type||
22-
|[terraform_unused_declarations](terraform_unused_declarations.md)|Disallow variables, data sources, and locals that are declared but never used||
21+
|[terraform_typed_variables](terraform_typed_variables.md)|Disallow `variable` declarations without type||
22+
|[terraform_unused_declarations](terraform_unused_declarations.md)|Disallow variables, data sources, and locals that are declared but never used||
2323
|[terraform_unused_required_providers](terraform_unused_required_providers.md)|Check that all `required_providers` are used in the module||
2424
|[terraform_workspace_remote](terraform_workspace_remote.md)|`terraform.workspace` should not be used with a "remote" backend with remote execution||

docs/rules/terraform_deprecated_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Disallow legacy dot index syntax.
44

5+
> This rule is enabled by "recommended" preset.
6+
57
## Example
68

79
```hcl

docs/rules/terraform_deprecated_interpolation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Disallow deprecated (0.11-style) interpolation
44

5+
> This rule is enabled by "recommended" preset.
6+
57
## Example
68

79
```hcl

docs/rules/terraform_empty_list_equality.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Disallow comparisons with `[]` when checking if a collection is empty.
44

5+
> This rule is enabled by "recommended" preset.
6+
57
## Example
68

79
```hcl

docs/rules/terraform_module_pinned_source.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Disallow specifying a git or mercurial repository as a module source without pinning to a version.
44

5+
> This rule is enabled by "recommended" preset.
6+
57
## Configuration
68

79
Name | Default | Value

docs/rules/terraform_module_version.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Ensure that all modules sourced from a [Terraform Registry](https://www.terraform.io/docs/language/modules/sources.html#terraform-registry) specify a `version`.
44

5+
> This rule is enabled by "recommended" preset.
6+
57
## Configuration
68

79
Name | Description | Default | Type

docs/rules/terraform_required_providers.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Require that all providers have version constraints through `required_providers`.
44

5+
> This rule is enabled by "recommended" preset.
6+
57
## Configuration
68

79
```hcl

docs/rules/terraform_required_version.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Disallow `terraform` declarations without `required_version`.
44

5+
> This rule is enabled by "recommended" preset.
6+
57
## Configuration
68

79
```hcl

docs/rules/terraform_typed_variables.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Disallow `variable` declarations without type.
44

5+
> This rule is enabled by "recommended" preset.
6+
57
## Example
68

79
```hcl

docs/rules/terraform_unused_declarations.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Disallow variables, data sources, and locals that are declared but never used.
44

5+
> This rule is enabled by "recommended" preset.
6+
57
## Example
68

79
```hcl

docs/rules/terraform_workspace_remote.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ rule "terraform_workspace_remote" {
1010
}
1111
```
1212

13+
> This rule is enabled by "recommended" preset.
14+
1315
## Example
1416

1517
```hcl

main.go

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,47 @@ import (
44
"github.com/terraform-linters/tflint-plugin-sdk/plugin"
55
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
66
"github.com/terraform-linters/tflint-ruleset-terraform/rules"
7+
"github.com/terraform-linters/tflint-ruleset-terraform/terraform"
78
)
89

910
func main() {
1011
plugin.Serve(&plugin.ServeOpts{
11-
RuleSet: &tflint.BuiltinRuleSet{
12-
Name: "terraform",
13-
Version: "0.1.0",
14-
Rules: []tflint.Rule{
15-
rules.NewTerraformCommentSyntaxRule(),
16-
rules.NewTerraformDeprecatedIndexRule(),
17-
rules.NewTerraformDeprecatedInterpolationRule(),
18-
rules.NewTerraformDocumentedOutputsRule(),
19-
rules.NewTerraformDocumentedVariablesRule(),
20-
rules.NewTerraformEmptyListEqualityRule(),
21-
rules.NewTerraformModulePinnedSourceRule(),
22-
rules.NewTerraformModuleVersionRule(),
23-
rules.NewTerraformNamingConventionRule(),
24-
rules.NewTerraformRequiredProvidersRule(),
25-
rules.NewTerraformRequiredVersionRule(),
26-
rules.NewTerraformStandardModuleStructureRule(),
27-
rules.NewTerraformTypedVariablesRule(),
28-
rules.NewTerraformUnusedDeclarationsRule(),
29-
rules.NewTerraformUnusedRequiredProvidersRule(),
30-
rules.NewTerraformWorkspaceRemoteRule(),
12+
RuleSet: &terraform.RuleSet{
13+
BuiltinRuleSet: tflint.BuiltinRuleSet{
14+
Name: "terraform",
15+
Version: "0.1.0",
16+
},
17+
PresetRules: map[string][]tflint.Rule{
18+
"all": {
19+
rules.NewTerraformCommentSyntaxRule(),
20+
rules.NewTerraformDeprecatedIndexRule(),
21+
rules.NewTerraformDeprecatedInterpolationRule(),
22+
rules.NewTerraformDocumentedOutputsRule(),
23+
rules.NewTerraformDocumentedVariablesRule(),
24+
rules.NewTerraformEmptyListEqualityRule(),
25+
rules.NewTerraformModulePinnedSourceRule(),
26+
rules.NewTerraformModuleVersionRule(),
27+
rules.NewTerraformNamingConventionRule(),
28+
rules.NewTerraformRequiredProvidersRule(),
29+
rules.NewTerraformRequiredVersionRule(),
30+
rules.NewTerraformStandardModuleStructureRule(),
31+
rules.NewTerraformTypedVariablesRule(),
32+
rules.NewTerraformUnusedDeclarationsRule(),
33+
rules.NewTerraformUnusedRequiredProvidersRule(),
34+
rules.NewTerraformWorkspaceRemoteRule(),
35+
},
36+
"recommended": {
37+
rules.NewTerraformDeprecatedIndexRule(),
38+
rules.NewTerraformDeprecatedInterpolationRule(),
39+
rules.NewTerraformEmptyListEqualityRule(),
40+
rules.NewTerraformModulePinnedSourceRule(),
41+
rules.NewTerraformModuleVersionRule(),
42+
rules.NewTerraformRequiredProvidersRule(),
43+
rules.NewTerraformRequiredVersionRule(),
44+
rules.NewTerraformTypedVariablesRule(),
45+
rules.NewTerraformUnusedDeclarationsRule(),
46+
rules.NewTerraformWorkspaceRemoteRule(),
47+
},
3148
},
3249
},
3350
})

rules/terraform_comment_syntax.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (r *TerraformCommentSyntaxRule) Name() string {
2626

2727
// Enabled returns whether the rule is enabled by default
2828
func (r *TerraformCommentSyntaxRule) Enabled() bool {
29-
return false
29+
return true
3030
}
3131

3232
// Severity returns the rule severity

rules/terraform_deprecated_index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (r *TerraformDeprecatedIndexRule) Name() string {
2424

2525
// Enabled returns whether the rule is enabled by default
2626
func (r *TerraformDeprecatedIndexRule) Enabled() bool {
27-
return false
27+
return true
2828
}
2929

3030
// Severity returns the rule severity

rules/terraform_documented_outputs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (r *TerraformDocumentedOutputsRule) Name() string {
2626

2727
// Enabled returns whether the rule is enabled by default
2828
func (r *TerraformDocumentedOutputsRule) Enabled() bool {
29-
return false
29+
return true
3030
}
3131

3232
// Severity returns the rule severity

rules/terraform_documented_variables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (r *TerraformDocumentedVariablesRule) Name() string {
2626

2727
// Enabled returns whether the rule is enabled by default
2828
func (r *TerraformDocumentedVariablesRule) Enabled() bool {
29-
return false
29+
return true
3030
}
3131

3232
// Severity returns the rule severity

rules/terraform_naming_convention.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (r *TerraformNamingConventionRule) Name() string {
6161

6262
// Enabled returns whether the rule is enabled by default
6363
func (r *TerraformNamingConventionRule) Enabled() bool {
64-
return false
64+
return true
6565
}
6666

6767
// Severity returns the rule severity

rules/terraform_required_providers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (r *TerraformRequiredProvidersRule) Name() string {
2828

2929
// Enabled returns whether the rule is enabled by default
3030
func (r *TerraformRequiredProvidersRule) Enabled() bool {
31-
return false
31+
return true
3232
}
3333

3434
// Severity returns the rule severity

rules/terraform_required_version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (r *TerraformRequiredVersionRule) Name() string {
2424

2525
// Enabled returns whether the rule is enabled by default
2626
func (r *TerraformRequiredVersionRule) Enabled() bool {
27-
return false
27+
return true
2828
}
2929

3030
// Severity returns the rule severity

rules/terraform_standard_module_structure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (r *TerraformStandardModuleStructureRule) Name() string {
3333

3434
// Enabled returns whether the rule is enabled by default
3535
func (r *TerraformStandardModuleStructureRule) Enabled() bool {
36-
return false
36+
return true
3737
}
3838

3939
// Severity returns the rule severity

rules/terraform_typed_variables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (r *TerraformTypedVariablesRule) Name() string {
2525

2626
// Enabled returns whether the rule is enabled by default
2727
func (r *TerraformTypedVariablesRule) Enabled() bool {
28-
return false
28+
return true
2929
}
3030

3131
// Severity returns the rule severity

rules/terraform_unused_declaration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (r *TerraformUnusedDeclarationsRule) Name() string {
3232

3333
// Enabled returns whether the rule is enabled by default
3434
func (r *TerraformUnusedDeclarationsRule) Enabled() bool {
35-
return false
35+
return true
3636
}
3737

3838
// Severity returns the rule severity

rules/terraform_unused_required_providers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (r *TerraformUnusedRequiredProvidersRule) Name() string {
2525

2626
// Enabled returns whether the rule is enabled by default
2727
func (r *TerraformUnusedRequiredProvidersRule) Enabled() bool {
28-
return false
28+
return true
2929
}
3030

3131
// Severity returns the rule severity

terraform/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package terraform
2+
3+
// Config is the configuration for the ruleset.
4+
type Config struct {
5+
Preset string `hclext:"preset,optional"`
6+
}

0 commit comments

Comments
 (0)