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

Add terraform_standard_module_structure rule #801

Merged

Conversation

bendrucker
Copy link
Member

This PR creates a rule that enforces the Terraform standard module structure:

https://www.terraform.io/docs/modules/index.html#standard-module-structure

The rule itself ensures that main, variables, and outputs file are created. It also ensures that variable/output blocks are included in the corresponding file. File checks are skipped for JSON-only projects and block checks are skipped when the declaration was in a JSON file.

Outside of the rule implementation, I've also added logic to TestRunnerWithConfig that detects the directory so that rules can test configuration that is in a directory other than ..

@bendrucker bendrucker force-pushed the tf-standard-module-structure branch from dc50da6 to ea103d3 Compare June 17, 2020 03:24
@bendrucker bendrucker changed the title create terraform_recommended_filenames rule Add terraform_standard_module_structure rule Jun 17, 2020
@mveitas
Copy link
Contributor

mveitas commented Jun 17, 2020

The standard module structure also enforces that a readme exist within the module (README or README.md). Thoughts on including this?

@bendrucker bendrucker force-pushed the tf-standard-module-structure branch from de9b46a to f793e61 Compare June 17, 2020 14:03
@bendrucker
Copy link
Member Author

I did think about that but chose to skip it:

  • Validating non-Terraform files would be new and possibly unexpected
  • Readmes are optional for nested modules and TFLint cannot distinguish a nested module if it is called directly on it (cd modules/foo && tflint .)

@bendrucker
Copy link
Member Author

Other related ideas here:

  • Rule for community filename conventions for root modules (providers.tf, backend.tf)
  • Config for required_version/required_providers rules allowing them to enforce the conventional filename (versions.tf)

@bendrucker bendrucker requested a review from wata727 June 17, 2020 17:10
Copy link
Member

@wata727 wata727 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bendrucker bendrucker merged commit 02f8c30 into terraform-linters:master Jun 18, 2020
@bendrucker bendrucker deleted the tf-standard-module-structure branch June 18, 2020 20:16
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.

None yet

3 participants