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

Comply with the Google Cloud impersonate library #2052

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions remote/remote_state_gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/sirupsen/logrus"
"golang.org/x/oauth2"
"golang.org/x/oauth2/jwt"
impersonate "google.golang.org/api/impersonate"
"google.golang.org/api/option"
)

Expand Down Expand Up @@ -460,9 +461,16 @@ func CreateGCSClient(gcsConfigRemote RemoteStateConfigGCS) (*storage.Client, err
}

if gcsConfigRemote.ImpersonateServiceAccount != "" {
opts = append(opts, option.ImpersonateCredentials(
gcsConfigRemote.ImpersonateServiceAccount,
gcsConfigRemote.ImpersonateServiceAccountDelegates...))
ts, err := impersonate.CredentialsTokenSource(context.Background(), impersonate.CredentialsConfig{
TargetPrincipal: gcsConfigRemote.ImpersonateServiceAccount,
// As for Terraform, hard-code the access scope: https://github.com/hashicorp/terraform/blob/032a4d083722da4369c03cc1e8dc5ae87b407e52/internal/backend/remote-state/gcs/backend.go#L169
Scopes: []string{storage.ScopeReadWrite},
Delegates: gcsConfigRemote.ImpersonateServiceAccountDelegates,
})
if err != nil {
return nil, err
}
opts = append(opts, option.WithTokenSource(ts))
}

client, err := storage.NewClient(ctx, opts...)
Expand Down