-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from padok-team/feat/tooling
feat(tooling): init
- Loading branch information
Showing
3 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Useful tooling for Terragrunt/Terraform | ||
|
||
The goal of this page is to list some useful tooling for Terragrunt/Terraform. | ||
|
||
- [Useful tooling for Terragrunt/Terraform](#useful-tooling-for-terragruntterraform) | ||
- [Code quality](#code-quality) | ||
- [Code security](#code-security) | ||
- [Documentation](#documentation) | ||
- [Readability of plan and apply](#readability-of-plan-and-apply) | ||
- [How to operate this tools](#how-to-operate-this-tools) | ||
|
||
## Code quality | ||
|
||
> Good code quality is a must-have for any project | ||
- [tflint](tflint.md) ✨ - Linter for Terraform | ||
- [Default configuration](tflint.md#default-configuration) | ||
- We recommend this one because it can check a wide range of cloud providers as well as Terraform code | ||
- [terraform fmt](https://developer.hashicorp.com/terraform/cli/commands/fmt) - Rewrites all Terraform configuration files to a canonical format | ||
- Example usage : `terraform fmt -recursive -diff -write=true` | ||
- [terragrunt hclfmt](https://terragrunt.gruntwork.io/docs/reference/cli-options/#hclfmt) - Rewrites all Terragrunt configuration files to a canonical format | ||
- Example usage : `terragrunt hclfmt` | ||
|
||
## Code security | ||
|
||
> Left shift security related tasks as much as possible | ||
- [checkov](https://github.com/bridgecrewio/checkov) ✨ - Static code analysis tool for infrastructure-as-code | ||
- Example : `checkov -d . --framework terraform --skip-file baseline.skip` | ||
- We recommend this one because it can check a wide range of cloud providers as well as Terraform code | ||
- [tfsec](https://github.com/aquasecurity/tfsec) - Static analysis powered security scanner for your terraform code | ||
- Example : `tfsec .` | ||
- [terrascan](https://runterrascan.io/) - Detect compliance and security violations across Infrastructure as Code to mitigate risk before provisioning cloud native infrastructure | ||
- Example : `terrascan scan -i terraform -d .` | ||
|
||
## Documentation | ||
|
||
> Documentation is a must-have for any project | ||
- [terraform-docs](https://github.com/terraform-docs/terraform-docs) - Generate documentation from Terraform modules in various output formats | ||
- Example : `terraform-docs markdown .` | ||
|
||
## Readability of plan and apply | ||
|
||
> When working with Terraform and even more so for Terragrunt, reading plan can be a pain. | ||
> Terraform is not fixing it any time soon : [Github issue on concise plan](https://github.com/hashicorp/terraform/issues/10507) | ||
- grep ✨ | ||
- `terraform plan -no-color | grep -E '(^.*[#~+-] .*|^[[:punct:]]|Plan|Changes)'` | ||
- We recommend this one because it's simple and efficient | ||
- [tfnotify](https://github.com/mercari/tfnotify) | ||
- [tftools](https://github.com/containerscrew/tftools) | ||
- [tf-summarize](https://github.com/dineshba/tf-summarize) | ||
|
||
## How to operate this tools | ||
|
||
- [pre-commit](https://pre-commit.com/) - A framework for managing and maintaining multi-language pre-commit hooks | ||
|
||
For terraform fmt, terragrunt hcl and checkov you can use the following configuration : | ||
|
||
```yaml | ||
repos: | ||
- repo: https://github.com/antonbabenko/pre-commit-terraform | ||
rev: v1.77.0 | ||
hooks: | ||
- id: terraform_fmt | ||
- id: terragrunt_fmt | ||
- id: terraform_checkov | ||
args: | ||
- --args=--quiet | ||
- --args=--framework=terraform | ||
- id: terraform_providers_lock | ||
args: | ||
- --hook-config=--mode=only-check-is-current-lockfile-cross-platform | ||
``` | ||
For tflint check [here](tflint.md#how-to-use-it) | ||
- [CI/CD](tbd) - Run these tools in your CI/CD pipeline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Tflint | ||
|
||
The goal of this page is to list some useful information about [tflint](https://github.com/terraform-linters/tflint) | ||
|
||
## Default configuration | ||
|
||
Within the `.tflint.hcl` file, you can define a default configuration for all your projects. | ||
|
||
```hcl | ||
plugin "terraform" { | ||
enabled = true | ||
source = "github.com/terraform-linters/tflint-ruleset-terraform" | ||
preset = "all" | ||
} | ||
rule "terraform_naming_convention" { | ||
enabled = true | ||
} | ||
# Change it depending on your cloud providers | ||
plugin "aws" { | ||
enabled = true | ||
source = "github.com/terraform-linters/tflint-ruleset-aws" | ||
} | ||
``` | ||
|
||
- [AWS](https://github.com/terraform-linters/tflint-ruleset-aws) | ||
- [Azure](https://github.com/terraform-linters/tflint-ruleset-azurerm) | ||
- [GCP](https://github.com/terraform-linters/tflint-ruleset-google) | ||
|
||
## How to use it | ||
|
||
- In the console : `tflint --recursive -f compact` | ||
- In terragrunt | ||
- Create an after_hook script for the validate command (Example below 👇) | ||
- Run `terragrunt run-all validate` | ||
|
||
```hcl | ||
terraform { | ||
after_hook "validate_tflint" { | ||
commands = ["validate"] | ||
execute = [ | ||
"sh", "-c", <<EOT | ||
echo "Run tflint for layer '${path_relative_to_include()}'..." | ||
(tflint --config="${get_repo_root()}/.tflint.hcl" --force --color -f compact) | ||
error_code=$? | ||
echo "Run tflint for layer '${path_relative_to_include()}'...DONE\n" | ||
exit $error_code | ||
EOT | ||
] | ||
} | ||
} | ||
``` |