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: Fallback to session-derived credentials #2883

Merged
merged 2 commits into from
Apr 4, 2018
Merged
Changes from all commits
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
27 changes: 19 additions & 8 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,27 @@ func (c *Config) Client() (interface{}, error) {
cp, err := creds.Get()
if err != nil {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "NoCredentialProviders" {
// If a profile wasn't specified then error out
// If a profile wasn't specified, the session may still be able to resolve credentials from shared config.
if c.Profile == "" {
return nil, errors.New(`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`)
sess, err := session.NewSession()
if err != nil {
return nil, errors.New(`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`)
}
_, err = sess.Config.Credentials.Get()
if err != nil {
return nil, errors.New(`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`)
}
log.Printf("[INFO] Using session-derived AWS Auth")
opt.Config.Credentials = sess.Config.Credentials
} else {
log.Printf("[INFO] AWS Auth using Profile: %q", c.Profile)
opt.Profile = c.Profile
opt.SharedConfigState = session.SharedConfigEnable
}
// add the profile and enable share config file usage
log.Printf("[INFO] AWS Auth using Profile: %q", c.Profile)
opt.Profile = c.Profile
opt.SharedConfigState = session.SharedConfigEnable
} else {
return nil, fmt.Errorf("Error loading credentials for AWS Provider: %s", err)
}
Expand Down