From 6ba347891a625b6ba0b96d88ff805ed95d6a4991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Respaut?= Date: Fri, 17 Feb 2023 11:18:13 +0100 Subject: [PATCH] AZ-989: Update all common files and `pre-commit` configs --- .config/terraform-docs.yml | 54 +++++++++++++++++++++++++++ .config/tflint.hcl | 66 +++++++++++++++++++++++++++++++++ .github/CODEOWNERS | 1 + .github/workflows/github-ci.yml | 5 +++ .pre-commit-config.yaml | 29 +++++++++++++++ CONTRIBUTING.md | 64 +++++++++++++++++++++++--------- LICENSE | 3 +- NOTICE | 2 +- README.md | 7 ++++ 9 files changed, 211 insertions(+), 20 deletions(-) create mode 100644 .config/terraform-docs.yml create mode 100644 .config/tflint.hcl create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/github-ci.yml create mode 100644 .pre-commit-config.yaml diff --git a/.config/terraform-docs.yml b/.config/terraform-docs.yml new file mode 100644 index 0000000..023b846 --- /dev/null +++ b/.config/terraform-docs.yml @@ -0,0 +1,54 @@ +--- +# This file is automatically maintained within this module repository -- DO NOT EDIT +formatter: "markdown" + +settings: + anchor: false + lockfile: false + +output: + file: "README.md" + +sections: + hide: [requirements] + +content: |- + ## Global versioning rule for Claranet Azure modules + + | Module version | Terraform version | AzureRM version | + | -------------- | ----------------- | --------------- | + | >= 7.x.x | 1.3.x | >= 3.0 | + | >= 6.x.x | 1.x | >= 3.0 | + | >= 5.x.x | 0.15.x | >= 2.0 | + | >= 4.x.x | 0.13.x / 0.14.x | >= 2.0 | + | >= 3.x.x | 0.12.x | >= 2.0 | + | >= 2.x.x | 0.12.x | < 2.0 | + | < 2.x.x | 0.11.x | < 2.0 | + + ## Contributing + + If you want to contribute to this repository, feel free to use our [pre-commit](https://pre-commit.com/) git hook configuration + which will help you automatically update and format some files for you by enforcing our Terraform code module best-practices. + + More details are available in the [CONTRIBUTING.md](./CONTRIBUTING.md#pull-request-process) file. + + ## Usage + + This module is optimized to work with the [Claranet terraform-wrapper](https://github.com/claranet/terraform-wrapper) tool + which set some terraform variables in the environment needed by this module. + More details about variables set by the `terraform-wrapper` available in the [documentation](https://github.com/claranet/terraform-wrapper#environment). + + ```hcl + {{ include "examples/main/modules.tf" }} + ``` + + {{ .Providers }} + + {{ .Modules }} + + {{ .Resources }} + + {{ .Inputs }} + + {{ .Outputs }} +... diff --git a/.config/tflint.hcl b/.config/tflint.hcl new file mode 100644 index 0000000..4e7a772 --- /dev/null +++ b/.config/tflint.hcl @@ -0,0 +1,66 @@ +plugin "azurerm" { + enabled = true + source = "github.com/terraform-linters/tflint-ruleset-azurerm" + version = "0.20.0" +} + +config { + module = true + force = false + disabled_by_default = false + + varfile = ["terraform.tfvars.ci"] +} + +rule "terraform_deprecated_interpolation" { + enabled = true +} + +rule "terraform_deprecated_index" { + enabled = true +} + +rule "terraform_unused_declarations" { + enabled = true +} + +rule "terraform_comment_syntax" { + enabled = true +} + +rule "terraform_documented_outputs" { + enabled = true +} + +rule "terraform_documented_variables" { + enabled = true +} + +rule "terraform_typed_variables" { + enabled = true +} + +rule "terraform_module_pinned_source" { + enabled = true +} + +rule "terraform_naming_convention" { + enabled = true +} + +rule "terraform_required_version" { + enabled = true +} + +rule "terraform_required_providers" { + enabled = true +} + +rule "terraform_unused_required_providers" { + enabled = true +} + +# Disabled since we have files like "variables-xxxx.tf" instead of a single "variables.tf" +rule "terraform_standard_module_structure" { + enabled = false +} diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..47e9ac6 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @bzspi @shr3ps @rossifumax @jmapro @maxpoullain diff --git a/.github/workflows/github-ci.yml b/.github/workflows/github-ci.yml new file mode 100644 index 0000000..fd0bc84 --- /dev/null +++ b/.github/workflows/github-ci.yml @@ -0,0 +1,5 @@ +name: CI +on: [push] +jobs: + ci: + uses: claranet/terraform-modules-ci/.github/workflows/ci-modules.yaml@main diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..b9aac5b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,29 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-json + - id: check-yaml + args: + - --unsafe + - id: check-symlinks + - id: check-added-large-files + - id: detect-private-key + +- repo: https://github.com/antonbabenko/pre-commit-terraform.git + rev: v1.77.1 + hooks: + - id: terraform_fmt + - id: terraform_docs + args: + - --args=--config=.config/terraform-docs.yml + - id: terraform_validate + exclude: ^examples + - id: terraform_tflint + exclude: ^examples + args: + - --args=--config=__GIT_WORKING_DIR__/.config/tflint.hcl + - --env-vars=TFLINT_LOG="info" + - id: terraform_tfsec diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 22ef8e1..46dd87b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,20 +1,50 @@ # Contributing -When contributing to this repository, please first discuss the change you wish to make via issue, -email, or any other method with the owners of this repository before making a change. +When contributing to this repository, please first discuss the change you wish to make via an issue, +an email, or any other method with the owners of this repository before making a change. Please note we have a code of conduct, please follow it in all your interactions with the project. ## Pull Request Process -1. Ensure any install or build dependencies are removed before the end of the layer when doing a - build. -2. Update the README.md with details of changes to the interface, this includes new environment - variables, exposed ports, useful file locations and container parameters. -3. Increase the version numbers in any examples files and the README.md to the new version that this - Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). -4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you - do not have permission to do that, you may request the second reviewer to merge it for you. +1. Ensure any installed or built dependencies are removed before the end of the layer when doing a + Pull Request. Ensure also that your code is clean and production ready. +2. Update the [README.md](./README.md) with details of changes to the module, including variables, outputs + or changes to [examples](./examples). +3. Update the [CHANGELOG.md](./CHANGELOG.md) with a new entry block starting with `# Unreleased` + followed by a description of your new feature, bug fix or change. +4. The Github Actions CI must pass. It ensures that our Terraform module codestyle rules are followed. +5. Please wait for maintainers to review your code, they will merge and release your changes once every + discussions or implementation details are satisfied. + +### Pre-commit usage + +We recommend using `pre-commit` ([the famous python git hooks tool](https://pre-commit.com/#intro)) +when you start a contribution. It will automatically trigger hooks which ensure our codestyle rules are followed, +files are formatted and linted, and that your README.md file is proprerly generated and updated. + +Installation on your local system: +```bash +$ pipx install pre-commit +``` +or +```bash +$ pip3 install pre-commit --user +``` + +and then, configure and enable our hooks: +```bash +$ cd path_to_the_git_cloned_module/ +$ pre-commit install +``` + +Do your changes as usual, hooks will be triggered by `pre-commit` every time you use the `git commit` command. + +To have all `pre-commit` hooks working you will have to setup thoses dependencies locally: +- latest version of [terraform](https://releases.hashicorp.com/terraform/) +- [tfdocs](https://github.com/terraform-docs/terraform-docs) +- [tflint](https://github.com/terraform-linters/tflint) +- [tfsec](https://github.com/aquasecurity/tfsec) ## Code of Conduct @@ -29,10 +59,10 @@ orientation. ### Our Standards -Examples of behavior that contributes to creating a positive environment +Examples of behavior that contribute to creating a positive environment include: -* Using welcoming and inclusive language +* Using a welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community @@ -40,7 +70,7 @@ include: Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or +* The use of sexualized language or imagery and unwelcome sexual attentions or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment @@ -52,13 +82,13 @@ advances ### Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. +behavior and are expected to take appropriate and fair corrective actions in +response to any instance of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, +that are not aligned to this Code of Conduct, to temporarily or permanently +ban any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ### Scope diff --git a/LICENSE b/LICENSE index 6ad2829..67aa702 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright (c) 2018 Claranet + Copyright (c) 2018-2023 Claranet Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -199,4 +199,3 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - diff --git a/NOTICE b/NOTICE index 3238949..9218d8b 100644 --- a/NOTICE +++ b/NOTICE @@ -1,4 +1,4 @@ -Copyright (c) 2018-2019 Claranet +Copyright (c) 2018-2023 Claranet Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 2f0574c..52e6da1 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,13 @@ This module must be used within a [Virtual Network](https://docs.microsoft.com/e | >= 2.x.x | 0.12.x | < 2.0 | | < 2.x.x | 0.11.x | < 2.0 | +## Contributing + +If you want to contribute to this repository, feel free to use our [pre-commit](https://pre-commit.com/) git hook configuration +which will help you automatically update and format some files for you by enforcing our Terraform code module best-practices. + +More details are available in the [CONTRIBUTING.md](./CONTRIBUTING.md#pull-request-process) file. + ## Usage This module is optimized to work with the [Claranet terraform-wrapper](https://github.com/claranet/terraform-wrapper) tool