Skip to content

Commit 156f733

Browse files
authored
Merge pull request #4 from terraform-linters/add_configuration_doc
Add documentation for deep checking
2 parents a24cae6 + 76466b0 commit 156f733

File tree

2 files changed

+123
-20
lines changed

2 files changed

+123
-20
lines changed

aws/client.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package aws
22

33
import (
4-
"errors"
54
"log"
6-
"strings"
75

86
"github.com/aws/aws-sdk-go/service/ec2"
97
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
@@ -67,7 +65,7 @@ func NewClient(creds Credentials) (*Client, error) {
6765

6866
s, err := awsbase.GetSession(config)
6967
if err != nil {
70-
return nil, formatBaseConfigError(err)
68+
return nil, err
7169
}
7270

7371
return &Client{
@@ -88,26 +86,20 @@ func getBaseConfig(creds Credentials) (*awsbase.Config, error) {
8886
}
8987

9088
return &awsbase.Config{
91-
AccessKey: creds.AccessKey,
92-
AssumeRoleARN: creds.AssumeRoleARN,
93-
AssumeRoleExternalID: creds.AssumeRoleExternalID,
94-
AssumeRolePolicy: creds.AssumeRolePolicy,
95-
AssumeRoleSessionName: creds.AssumeRoleSessionName,
96-
SecretKey: creds.SecretKey,
97-
Profile: creds.Profile,
98-
CredsFilename: expandedCredsFile,
99-
Region: creds.Region,
89+
AccessKey: creds.AccessKey,
90+
AssumeRoleARN: creds.AssumeRoleARN,
91+
AssumeRoleExternalID: creds.AssumeRoleExternalID,
92+
AssumeRolePolicy: creds.AssumeRolePolicy,
93+
AssumeRoleSessionName: creds.AssumeRoleSessionName,
94+
SecretKey: creds.SecretKey,
95+
Profile: creds.Profile,
96+
CredsFilename: expandedCredsFile,
97+
Region: creds.Region,
98+
CallerName: "tflint-ruleset-aws",
99+
CallerDocumentationURL: "https://github.com/terraform-linters/tflint-ruleset-aws/blob/master/docs/deep_checking.md",
100100
}, nil
101101
}
102102

103-
// @see https://github.com/hashicorp/aws-sdk-go-base/blob/v0.3.0/session.go#L87
104-
func formatBaseConfigError(err error) error {
105-
if strings.Contains(err.Error(), "No valid credential sources found for AWS Provider") {
106-
return errors.New("No valid credential sources found")
107-
}
108-
return err
109-
}
110-
111103
// Merge returns a merged credentials
112104
func (c Credentials) Merge(other Credentials) Credentials {
113105
if other.AccessKey != "" {

docs/deep_checking.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Deep Checking
2+
3+
Deep Checking uses your provider's credentials to perform a more strict inspection.
4+
5+
For example, if the IAM profile references something that doesn't exist, terraform apply will fail, which can't be found by general validation. Deep Checking solves this problem.
6+
7+
```console
8+
$ tflint
9+
2 issue(s) found:
10+
11+
Error: instance_type is not a valid value (aws_instance_invalid_type)
12+
13+
on template.tf line 3:
14+
3: instance_type = "t1.2xlarge"
15+
16+
Error: "invalid_profile" is invalid IAM profile name. (aws_instance_invalid_iam_profile)
17+
18+
on template.tf line 4:
19+
4: iam_instance_profile = "invalid_profile"
20+
21+
```
22+
23+
You can enable Deep Checking by changing the plugin configuration.
24+
25+
```hcl
26+
plugin "aws" {
27+
enabled = true
28+
29+
deep_check = true
30+
}
31+
```
32+
33+
## Credentials
34+
35+
Credentials can be set in several ways. Each is referenced in the following order:
36+
37+
- Static credentials
38+
- Static credentials (Terraform)
39+
- Environment variables
40+
- Shared credentials
41+
- Shared credentials (Terraform)
42+
- ECS and CodeBuild task roles
43+
- EC2 role
44+
45+
46+
### Static credentials
47+
48+
If you have an access key and a secret key, you can pass these keys like the following:
49+
50+
```hcl
51+
plugin "aws" {
52+
enabled = true
53+
54+
deep_check = true
55+
access_key = "AWS_ACCESS_KEY_ID"
56+
secret_key = "AWS_SECRET_ACCESS_KEY"
57+
region = "us-east-1"
58+
}
59+
```
60+
61+
Although there is not recommended, if an access key is hard-coded in a provider configuration, they will also be taken into account. However, aliases are not supported. The priority is higher than the environment variable and lower than the above way.
62+
63+
```hcl
64+
provider "aws" {
65+
region = "us-west-2"
66+
access_key = "my-access-key"
67+
secret_key = "my-secret-key"
68+
}
69+
```
70+
71+
### Shared credentials
72+
73+
If you have [shared credentials](https://aws.amazon.com/jp/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks/), you can pass a profile name and credentials file path. If omitted, these will be `default` and `~/.aws/credentials`.
74+
75+
```hcl
76+
plugin "aws" {
77+
enabled = true
78+
79+
deep_check = true
80+
region = "us-east-1"
81+
shared_credentials_file = "~/.aws/myapp"
82+
profile = "AWS_PROFILE"
83+
}
84+
```
85+
86+
If these configurations are defined in the provider block, they will also be taken into account. But the priority is lower than the above way.
87+
88+
```hcl
89+
provider "aws" {
90+
region = "us-west-2"
91+
shared_credentials_file = "/Users/tf_user/.aws/creds"
92+
profile = "customprofile"
93+
}
94+
```
95+
96+
### Environment variables
97+
98+
This plugin looks up `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`, `AWS_REGION` environment variables. This is useful when you don't want to explicitly pass credentials.
99+
100+
```
101+
$ export AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY
102+
$ export AWS_SECRET_ACCESS_KEY=AWS_SECRET_KEY
103+
```
104+
105+
### Role-based authentication
106+
107+
This plugin fetches credentials in the same way as Terraform. See [this documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#codebuild-ecs-and-eks-roles) for the role-based authentication.
108+
109+
### Assume role
110+
111+
This plugin can assume a role in the same way as Terraform. See [this documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#assume-role).

0 commit comments

Comments
 (0)