Skip to content

Commit 273225e

Browse files
Merge pull request #1530 from snyk/feat/handle_gcp_missing_creds
Catch missing credentials error for GCP
2 parents 0aee331 + a455f99 commit 273225e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pkg/remote/google/init.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ func Init(version string, alerter *alerter.Alerter,
2828
if err != nil {
2929
return err
3030
}
31+
32+
err = provider.CheckCredentialsExist()
33+
if err != nil {
34+
return err
35+
}
36+
3137
err = provider.Init()
3238
if err != nil {
3339
return err

pkg/remote/google/provider.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package google
22

33
import (
4+
"context"
5+
"errors"
46
"os"
57

8+
asset "cloud.google.com/go/asset/apiv1"
69
"github.com/snyk/driftctl/pkg/output"
710
"github.com/snyk/driftctl/pkg/remote/google/config"
811
"github.com/snyk/driftctl/pkg/remote/terraform"
@@ -62,3 +65,13 @@ func (p *GCPTerraformProvider) GetConfig() config.GCPTerraformConfig {
6265
Zone: os.Getenv("CLOUDSDK_COMPUTE_ZONE"),
6366
}
6467
}
68+
69+
func (p *GCPTerraformProvider) CheckCredentialsExist() error {
70+
client, err := asset.NewClient(context.Background())
71+
if err != nil {
72+
return errors.New("Please use a Service Account to authenticate on GCP.\n" +
73+
"For more information: https://cloud.google.com/docs/authentication/production")
74+
}
75+
_ = client.Close()
76+
return nil
77+
}

0 commit comments

Comments
 (0)