Skip to content
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

plugin: Switch internal Terraform rules to the bundled plugin #1496

Merged
merged 1 commit into from Sep 7, 2022

Conversation

wata727
Copy link
Member

@wata727 wata727 commented Aug 28, 2022

Fixes #1352
Fixes #1056
See https://github.com/terraform-linters/tflint-ruleset-terraform

This PR cuts out the Terraform rules built directly into TFLint into a plugin for historical reasons. The plugin is bundled in the TFLint core as a bundled plugin so that if the plugin is not explicitly enabled, it will be automatically enabled. This allows end-users to use Terraform rules almost the same as before.

All rules are available if the plugin is enabled, but due to how this bundled plugin works, the "recommended" preset is automatically set when enabled automatically. This means that the following configuration is automatically inserted:

plugin "terraform" {
  enabled = true
  preset  = "recommended"
}

https://github.com/terraform-linters/tflint-ruleset-terraform/blob/1891988f8797be2006a30702505d7e00774ad3c0/docs/configuration.md

Please note that the "recommended" preset is different from the current default rules. The following rules are added to the rules enabled by default:

  • terraform_deprecated_index
  • terraform_required_providers
  • terraform_required_version
  • terraform_typed_variables
  • terraform_unused_declarations

This behavior can be changed by explicitly declaring a "terraform" plugin block. For example, the following declaration will enable all rules instead of the "recommended".

plugin "terraform" {
  enabled = true
}

As with any plugin, you can enable a different version of the plugin than the bundled plugin by declaring the version and source. In this case, you need to run tflint --init.

plugin "terraform" {
  enabled = true

  version = "0.1.0"
  source  = "github.com/terraform-linters/tflint-ruleset-terraform"
}

TODO

  • Move cli_test.go to integration tests
  • Add integration tests for the bundled plugin
  • Add unit tests for the bundled plugin config
  • Concerns about terraform_required_version rules running in non-Terraform workspaces
  • Revise documentations

@wata727 wata727 force-pushed the bundle_terraform_ruleset branch 2 times, most recently from 7babc1e to c5e6c91 Compare August 28, 2022 15:31
@wata727 wata727 force-pushed the bundle_terraform_ruleset branch 4 times, most recently from d62bf5c to 607e1e9 Compare September 3, 2022 16:33
@wata727 wata727 marked this pull request as ready for review September 3, 2022 16:39
@wata727 wata727 merged commit 3e1d0a5 into master Sep 7, 2022
@wata727 wata727 deleted the bundle_terraform_ruleset branch September 7, 2022 15:25
@wata727 wata727 mentioned this pull request Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Cut out Terraform rules into a ruleset plugin Is there a way to use all existing rules
1 participant