Skip to content

Commit 25f5080

Browse files
authored
Merge pull request #1515 from snyk/feat/handle_aws_missing_creds
feat: Display better message when AWS credentials missing
2 parents 0786e71 + f9ce34d commit 25f5080

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pkg/remote/aws/init.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ func Init(version string, alerter *alerter.Alerter,
2929
if err != nil {
3030
return err
3131
}
32+
err = provider.CheckCredentialsExist()
33+
if err != nil {
34+
return err
35+
}
3236
err = provider.Init()
3337
if err != nil {
3438
return err

pkg/remote/aws/provider.go

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

33
import (
4+
"github.com/aws/aws-sdk-go/aws/credentials"
45
"github.com/aws/aws-sdk-go/aws/session"
6+
"github.com/pkg/errors"
57
"github.com/snyk/driftctl/pkg/output"
68
"github.com/snyk/driftctl/pkg/remote/terraform"
79
tf "github.com/snyk/driftctl/pkg/terraform"
@@ -86,3 +88,16 @@ func (a *AWSTerraformProvider) Name() string {
8688
func (p *AWSTerraformProvider) Version() string {
8789
return p.version
8890
}
91+
92+
func (p *AWSTerraformProvider) CheckCredentialsExist() error {
93+
_, err := p.session.Config.Credentials.Get()
94+
if err == credentials.ErrNoValidProvidersFoundInChain {
95+
return errors.New("Could not find a way to authenticate on AWS!\n" +
96+
"Please refer to AWS documentation: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html\n\n" +
97+
"To use a different cloud provider, use --to=\"tf+gcp\" for GCP or --to=\"tf+azure\" for Azure.")
98+
}
99+
if err != nil {
100+
return err
101+
}
102+
return nil
103+
}

0 commit comments

Comments
 (0)