Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: Provide a better message if no AWS creds are found #4869

Merged
merged 2 commits into from
Jan 29, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion builtin/providers/aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ func (c *Config) Client() (interface{}, error) {
// error, and we can present it nicely to the user
_, err = creds.Get()
if err != nil {
errs = append(errs, fmt.Errorf("Error loading credentials for AWS Provider: %s", err))
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "NoCredentialProviders" {
errs = append(errs, fmt.Errorf(`No valid credential sources found for AWS Provider.
Please see https://terraform.io/docs/providers/aws/index.html for more information on
providing credentials for the AWS Provider`))
} else {
errs = append(errs, fmt.Errorf("Error loading credentials for AWS Provider: %s", err))
}
return nil, &multierror.Error{Errors: errs}
}
awsConfig := &aws.Config{
Expand Down
17 changes: 17 additions & 0 deletions website/source/docs/providers/aws/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ resource "aws_instance" "web" {
}
```

## Authentication

The AWS provider offers flexible means of providing credentials for
authentication. Included is support including hard coded credentials,
environment variables, and shared credential files, in that order of precedence.

Terraform will first attempt to use an `access_key` and `secret_key` provided in
the `provider` block (shown in the example above). If those are omitted, it will
attempt to discover those values by referencing the `AWS_ACCESS_KEY_ID` and
`AWS_SECRET_ACCESS_KEY` environment variables. Lastly, if those are not found
it will look for credentials in the default location for a credentials file, or
the file path specified in the `shared_credentials_file` attribute of the
`provider` block.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shared credentials path can be overridden with AWS_SHARED_CREDENTIALS_FILE

And the creds file can have multiple profiles, which can be selected via profile, which can also be set via AWS_PROFILE.

https://github.com/aws/aws-sdk-go/blob/87b1e60a50b09e4812dee560b33a238f67305804/aws/credentials/shared_credentials_provider.go#L25-L36

I wonder if this would look clearer as a numbered list of "things we check in this order" than a prose paragraph?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this would look clearer as a numbered list of "things we check in this order" than a prose paragraph?

probably, will do


See the argument reference below for information on which attributes to specify
to use a corresponding credential provider.

## Argument Reference

The following arguments are supported in the `provider` block:
Expand Down