@@ -3,7 +3,9 @@ package aws
3
3
import (
4
4
"github.com/aws/aws-sdk-go/aws/credentials"
5
5
"github.com/aws/aws-sdk-go/aws/session"
6
+ "github.com/aws/aws-sdk-go/service/sts"
6
7
"github.com/pkg/errors"
8
+ "github.com/sirupsen/logrus"
7
9
"github.com/snyk/driftctl/pkg/output"
8
10
"github.com/snyk/driftctl/pkg/remote/terraform"
9
11
tf "github.com/snyk/driftctl/pkg/terraform"
@@ -30,10 +32,10 @@ type awsConfig struct {
30
32
IgnoreTagsConfig map [string ]string
31
33
Insecure bool
32
34
33
- SkipCredsValidation bool
35
+ SkipCredsValidation bool `cty:"skip_credentials_validation"`
34
36
SkipGetEC2Platforms bool
35
37
SkipRegionValidation bool
36
- SkipRequestingAccountId bool
38
+ SkipRequestingAccountId bool `cty:"skip_requesting_account_id"`
37
39
SkipMetadataApiCheck bool
38
40
S3ForcePathStyle bool
39
41
}
@@ -69,7 +71,12 @@ func NewAWSTerraformProvider(version string, progress output.Progress, configDir
69
71
DefaultAlias : * p .session .Config .Region ,
70
72
GetProviderConfig : func (alias string ) interface {} {
71
73
return awsConfig {
72
- Region : alias ,
74
+ Region : alias ,
75
+ // Those two parameters are used to make sure that the credentials are not validated when calling
76
+ // Configure(). Credentials validation is now handled directly in driftctl
77
+ SkipCredsValidation : true ,
78
+ SkipRequestingAccountId : true ,
79
+
73
80
MaxRetries : 10 , // TODO make this configurable
74
81
}
75
82
},
@@ -99,5 +106,14 @@ func (p *AWSTerraformProvider) CheckCredentialsExist() error {
99
106
if err != nil {
100
107
return err
101
108
}
109
+ // This call is to make sure that the credentials are valid
110
+ // A more complex logic exist in terraform provider, but it's probably not worth to implement it
111
+ // https://github.com/hashicorp/terraform-provider-aws/blob/e3959651092864925045a6044961a73137095798/aws/auth_helpers.go#L111
112
+ _ , err = sts .New (p .session ).GetCallerIdentity (& sts.GetCallerIdentityInput {})
113
+ if err != nil {
114
+ logrus .Debug (err )
115
+ return errors .New ("Could not authenticate successfully on AWS with the provided credentials.\n " +
116
+ "Please refer to the AWS documentation: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html\n " )
117
+ }
102
118
return nil
103
119
}
0 commit comments