tflint
plugin¶
Installation¶
This plugin depends on tflint. If you use tflint
version 0.29 or newer, you can leverage the tflint --init
command to automatically install the plugin. Otherwise, you will need to download the tflint-ruleset-aws-serverless
binary corresponding to your system from the releases page.
You can enable the Serverless Rules plugin by adding a plugin section in the .tflint.hcl
file in your project:
1 2 3 4 5 |
|
Usage¶
You can now run the tflint
command, which will automatically use the Serverless Rules plugin:
1 |
|
You can also try with a Terraform example provided in this repository. From the root folder of the repository, you can run:
1 2 |
|
Sample outputs¶
If the Terraform configuration files fulfill the requirements for all the rules, tflint
will return an empty output. Otherwise, tflint
will output recommendations.
1 2 |
|
1 2 3 4 5 6 7 8 |
|
Ignoring rules¶
Serverless Rules is a set of recommended practices.
We recommend you to keep Error-level rules enabled. Non-error rules, for example Lambda Tracing, contain detailed scenarios on when it’s safe to ignore them.
When needed, you can ignore any specific rule that doesn’t match your environment.
Rules in tflint
can be disabled either through the --disable-rule
command-line argument or with the .tflint.hcl
configuration file in the current working directory. See the tflint
user guide for more information.
1 2 |
|
1 2 3 4 5 6 7 8 9 10 |
|
Continuous integration¶
You can use Serverless Rules and tflint
with your continuous integration tool to automatically check CloudFormation templates with rules from this project. For example, you can validate on pull requests, merge to your main branch, or before deploying to production.
If there are any issues with your template, tflint
will return a non-zero error code.
AWS CodeBuild¶
Assuming that you are storing your terraform configuration files and a .tflint.hcl
file at the root of your repository, you can create a buildspec file such as this one.
Important
Make sure that you include the aws-serverless plugin into your .tflint.hcl
configuration file, otherwise tflint will not install this ruleset. See Installation for more information.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
GitHub Actions¶
Assuming that you are storing your terraform configuration files and a .tflint.hcl
file at the root of your repository, and that you are using main
as your target branch for pull requests, you can create a GitHub actions workflow file such as this one:
Important
Make sure that you include the aws-serverless plugin into your .tflint.hcl
configuration file, otherwise tflint will not install this ruleset. See Installation for more information.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
GitLab¶
Assuming that you are storing your terraform configuration files and a .tflint.hcl
file at the root of your repository, you can create a .gitlab-ci.yml
file such as this one:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|