Skip to content

Commit 247840d

Browse files
committed
Revise documentation
1 parent f12527f commit 247840d

11 files changed

+433
-13
lines changed

README.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
# WORKING IN PROGRESS AND MAINTAINER WANTED!
2-
3-
This project was started to make TFLint pluggable. Everything is working in progress and not available as a plugin.
4-
5-
AWS provider rules are currently integrated into the TFLint core. It will be cut out to this repository in the future, but it doesn't mean that limit the proposal of rules about AWS provider into the core repository.
6-
7-
The migration process will take a long time. Please open an issue to the core repository for the latest proposal.
8-
91
# TFLint Ruleset for terraform-provider-aws
102

113
TFLint ruleset plugin for Terraform AWS Provider
124

5+
This ruleset focus on possible errors and best practices about AWS resources. Many rules are enabled by default and warn against code that might fail when running `terraform apply`, or clearly unrecommened.
6+
137
## Requirements
148

15-
- TFLint v0.14+
16-
- Go v1.13
9+
- TFLint v0.23+
10+
- Go v1.15
1711

1812
## Installation
1913

@@ -25,11 +19,11 @@ plugin "aws" {
2519
}
2620
```
2721

22+
For more configuration about the plugin, see [Plugin Configuration](docs/configuration.md).
23+
2824
## Rules
2925

30-
|Name|Description|Severity|Enabled|Link|
31-
| --- | --- | --- | --- | --- |
32-
|aws_instance_example_type|Show instance type|ERROR|||
26+
700+ rules are available. See [Rules](docs/rules/README.md).
3327

3428
## Building the plugin
3529

docs/configuration.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Configuration
2+
3+
This plugin can take advantage of additional features by configure the `plugin` block. Currently, this configuration is only available for [Deep Checking](deep_checking.md).
4+
5+
Here's an example:
6+
7+
```hcl
8+
plugin "aws" {
9+
enabled = true
10+
11+
deep_check = false
12+
access_key = "AWS_ACCESS_KEY_ID"
13+
secret_key = "AWS_SECRET_ACCESS_KEY"
14+
region = "us-east-1"
15+
profile = "AWS_PROFILE"
16+
shared_credentials_file = "~/.aws/credentials"
17+
}
18+
```
19+
20+
## `enabled`
21+
22+
Default: false
23+
24+
Enable this plugin. This is the common option in all plugins.
25+
26+
## `deep_check`
27+
28+
Default: false
29+
30+
Enable [Deep Checking](deep_checking.md).
31+
32+
## `access_key`
33+
34+
Default: Credentials declared in the `provider` block or `AWS_ACCESS_KEY_ID` environment variables when the deep checking is enabled.
35+
36+
AWS access key used in the deep checking.
37+
38+
## `secret_key`
39+
40+
Default: Credentials declared in the `provider` block or `AWS_SECRET_ACCESS_KEY` environment variables when the deep checking is enabled.
41+
42+
AWS secret key used in the deep checking.
43+
44+
## `region`
45+
46+
Default: Region declared in the `provider` block or `AWS_REGION` environment variables when the deep checking is enabled.
47+
48+
AWS region used in the deep checking.
49+
50+
## `profile`
51+
52+
Default: Profile declared in the `provider` block or `AWS_PROFILE` environment variables when the deep checking is enabled.
53+
54+
AWS shared credentials profile name used in the deep checking.
55+
56+
## `shared_credentials_file`
57+
58+
Default: Profile declared in the `provider` block or `~/.aws/credentials` when the deep checking is enabled.
59+
60+
AWS shared credentials file path used in the deep checking.

docs/rules/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Rules
2+
3+
This documentation describes a list of rules available by enabling this ruleset.
4+
5+
### Possible Errors
6+
7+
These rules warn of possible errors that can occur at `terraform apply`. Rules marked with `Deep` are only used when enabling [Deep Checking](../deep_checking.md):
8+
9+
|Rule|Deep|
10+
| --- | --- |
11+
|aws_alb_invalid_security_group||
12+
|aws_alb_invalid_subnet||
13+
|aws_db_instance_invalid_db_subnet_group||
14+
|aws_db_instance_invalid_option_group||
15+
|aws_db_instance_invalid_parameter_group||
16+
|aws_db_instance_invalid_type||
17+
|aws_db_instance_invalid_vpc_security_group||
18+
|aws_elasticache_cluster_invalid_parameter_group||
19+
|aws_elasticache_cluster_invalid_security_group||
20+
|aws_elasticache_cluster_invalid_subnet_group||
21+
|aws_elasticache_cluster_invalid_type||
22+
|aws_elb_invalid_instance||
23+
|aws_elb_invalid_security_group||
24+
|aws_elb_invalid_subnet||
25+
|aws_instance_invalid_ami||
26+
|aws_instance_invalid_iam_profile||
27+
|aws_instance_invalid_key_name||
28+
|aws_instance_invalid_subnet||
29+
|aws_instance_invalid_vpc_security_group||
30+
|aws_launch_configuration_invalid_iam_profile||
31+
|aws_launch_configuration_invalid_image_id||
32+
|aws_route_invalid_egress_only_gateway||
33+
|aws_route_invalid_gateway||
34+
|aws_route_invalid_instance||
35+
|aws_route_invalid_nat_gateway||
36+
|aws_route_invalid_network_interface||
37+
|aws_route_invalid_route_table||
38+
|aws_route_invalid_vpc_peering_connection||
39+
|[aws_s3_bucket_name](aws_s3_bucket_name.md)||
40+
|[aws_route_not_specified_target](aws_route_not_specified_target.md)||
41+
|[aws_route_specified_multiple_targets](aws_route_specified_multiple_targets.md)||
42+
43+
#### SDK-based Validations
44+
45+
700+ rules based on the aws-sdk validations are also available. See [full list](../../rules/awsrules/models/).
46+
47+
### Best Practices
48+
49+
These rules suggest to better ways.
50+
51+
- [aws_instance_previous_type](aws_instance_previous_type.md)
52+
- [aws_db_instance_previous_type](aws_db_instance_previous_type.md)
53+
- [aws_db_instance_default_parameter_group](aws_db_instance_default_parameter_group.md)
54+
- [aws_elasticache_cluster_previous_type](aws_elasticache_cluster_previous_type.md)
55+
- [aws_elasticache_cluster_default_parameter_group](aws_elasticache_cluster_default_parameter_group.md)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# aws_db_instance_default_parameter_group
2+
3+
Disallow using default DB parameter group.
4+
5+
## Example
6+
7+
```hcl
8+
resource "aws_db_instance" "mysql" {
9+
identifier = "app"
10+
allocated_storage = 50
11+
storage_type = "gp2"
12+
engine = "mysql"
13+
engine_version = "5.7.11"
14+
instance_class = "db.m4.large"
15+
name = "app_db"
16+
port = 3306
17+
publicly_accessible = false
18+
vpc_security_group_ids = ["${aws_security_group.mysql.id}"]
19+
db_subnet_group_name = "app-subnet-group"
20+
parameter_group_name = "default.mysql5.7" // default DB parameter group!
21+
multi_az = true
22+
}
23+
```
24+
25+
```
26+
$ tflint
27+
1 issue(s) found:
28+
29+
Notice: "default.mysql5.7" is default parameter group. You cannot edit it. (aws_db_instance_default_parameter_group)
30+
31+
on template.tf line 13:
32+
13: parameter_group_name = "default.mysql5.7" // default DB parameter group!
33+
34+
```
35+
36+
## Why
37+
38+
You can modify parameter values in a custom DB parameter group, but you can't change the parameter values in a default DB parameter group.
39+
40+
## How To Fix
41+
42+
Create a new parameter group, and change the `parameter_group_name` to that.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# aws_db_instance_previous_type
2+
3+
Disallow using previous generation instance types.
4+
5+
## Example
6+
7+
```hcl
8+
resource "aws_db_instance" "default" {
9+
allocated_storage = 10
10+
engine = "mysql"
11+
engine_version = "5.6.17"
12+
instance_class = "db.t1.micro" // previous generation instance type!
13+
name = "mydb"
14+
username = "foo"
15+
password = "bar"
16+
db_subnet_group_name = "my_database_subnet_group"
17+
parameter_group_name = "default.mysql5.6"
18+
}
19+
```
20+
21+
```
22+
$ tflint
23+
1 issue(s) found:
24+
25+
Warning: "db.t1.micro" is previous generation instance type. (aws_db_instance_previous_type)
26+
27+
on template.tf line 5:
28+
5: instance_class = "db.t1.micro" // previous generation instance type!
29+
30+
```
31+
32+
## Why
33+
34+
Current generation instance types have better performance and lower cost than previous generations. Users should avoid previous generation instance types, especially for new instances.
35+
36+
## How To Fix
37+
38+
Select a current generation instance type according to the [upgrade paths](https://aws.amazon.com/rds/previous-generation/).
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# aws_elasticache_cluster_default_parameter_group
2+
3+
Disallow using default parameter group.
4+
5+
## Example
6+
7+
```hcl
8+
resource "aws_elasticache_cluster" "redis" {
9+
cluster_id = "app"
10+
engine = "redis"
11+
engine_version = "3.2.4"
12+
maintenance_window = "sun:00:00-sun:06:00"
13+
node_type = "cache.m4.large"
14+
num_cache_nodes = 1
15+
port = 6379
16+
parameter_group_name = "default.redis3.2" // default paramete group!
17+
subnet_group_name = "app-subnet-group"
18+
security_group_ids = ["${aws_security_group.redis.id}"]
19+
}
20+
```
21+
22+
```
23+
$ tflint
24+
1 issue(s) found:
25+
26+
Notice: "default.redis3.2" is default parameter group. You cannot edit it. (aws_elasticache_cluster_default_parameter_group)
27+
28+
on template.tf line 9:
29+
9: parameter_group_name = "default.redis3.2" // default paramete group!
30+
31+
```
32+
33+
## Why
34+
35+
You can modify parameter values in a custom parameter group, but you can't change the parameter values in a default parameter group.
36+
37+
## How To Fix
38+
39+
Create a new parameter group, and change the `parameter_group_name` to that.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# aws_elasticache_cluster_previous_type
2+
3+
Disallow using previous node types.
4+
5+
## Example
6+
7+
```hcl
8+
resource "aws_elasticache_cluster" "redis" {
9+
cluster_id = "app"
10+
engine = "redis"
11+
engine_version = "3.2.4"
12+
maintenance_window = "sun:00:00-sun:06:00"
13+
node_type = "cache.t1.micro" // previous node type!
14+
num_cache_nodes = 1
15+
port = 6379
16+
parameter_group_name = "default.redis3.2"
17+
subnet_group_name = "app-subnet-group"
18+
security_group_ids = ["${aws_security_group.redis.id}"]
19+
}
20+
```
21+
22+
```
23+
$ tflint
24+
1 issue(s) found:
25+
26+
Warning: "cache.t1.micro" is previous generation node type. (aws_elasticache_cluster_previous_type)
27+
28+
on template.tf line 6:
29+
6: node_type = "cache.t1.micro" // previous node type!
30+
31+
```
32+
33+
## Why
34+
35+
Previous node types are inferior to current generation in terms of performance and fee. Unless there is a special reason, you should avoid to use these ones.
36+
37+
## How To Fix
38+
39+
Select a current generation node type according to the [upgrade paths](https://aws.amazon.com/elasticache/previous-generation/).
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# aws_instance_previous_type
2+
3+
Disallow using previous generation instance types.
4+
5+
## Example
6+
7+
```hcl
8+
resource "aws_instance" "web" {
9+
ami = "ami-b73b63a0"
10+
instance_type = "t1.micro" # previous instance type!
11+
iam_instance_profile = "app-service"
12+
13+
tags {
14+
Name = "HelloWorld"
15+
}
16+
}
17+
```
18+
19+
```
20+
$ tflint
21+
1 issue(s) found:
22+
23+
Warning: "t1.micro" is previous generation instance type. (aws_instance_previous_type)
24+
25+
on template.tf line 3:
26+
3: instance_type = "t1.micro" # previous instance type!
27+
28+
```
29+
30+
## Why
31+
32+
Current generation instance types have better performance and lower cost than previous generations. Users should avoid previous generation instance types, especially for new instances.
33+
34+
## How To Fix
35+
36+
Select a current generation instance type according to the [upgrade paths](https://aws.amazon.com/ec2/previous-generation/).
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# aws_route_not_specified_target
2+
3+
Disallow routes that have no targets.
4+
5+
## Example
6+
7+
```hcl
8+
resource "aws_route" "foo" {
9+
route_table_id = "rtb-1234abcd"
10+
destination_cidr_block = "10.0.1.0/22"
11+
}
12+
```
13+
14+
```
15+
$ tflint
16+
1 issue(s) found:
17+
18+
Error: The routing target is not specified, each aws_route must contain either egress_only_gateway_id, gateway_id, instance_id, nat_gateway_id, network_interface_id, transit_gateway_id, vpc_peering_connection_id or vpc_endpoint_id. (aws_route_not_specified_target)
19+
20+
on template.tf line 1:
21+
1: resource "aws_route" "foo" {
22+
23+
```
24+
25+
## Why
26+
27+
It results in an error.
28+
29+
## How To Fix
30+
31+
Add a routing target. The [supported arguments](https://www.terraform.io/docs/providers/aws/r/route.html#argument-reference) are: `egress_only_gateway_id`, `gateway_id`, `instance_id`, `nat_gateway_id`, `network_interface_id`, `transit_gateway_id`, `vpc_peering_connection_id`.

0 commit comments

Comments
 (0)