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

add iamcredentialsbasepath support for plugin framework #11947

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type FrameworkProviderConfig struct {
DefaultLabels types.Map

// paths for client setup
IAMCredentialsBasePath string // TODO: This will be removed once we resove the muxing issues
{{- range $product := $.Products }}
{{ $product.Name }}BasePath string
{{- end }}
Expand Down Expand Up @@ -99,6 +100,7 @@ func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context,

// Setup Base Paths for clients
// Generated products
p.IAMCredentialsBasePath = data.IamCredentialsCustomEndpoint.ValueString() // TODO: This will be removed once we resove the muxing issues
{{- range $product := $.Products }}
p.{{ $product.Name }}BasePath = data.{{ $product.Name }}CustomEndpoint.ValueString()
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package fwtransport

import (
"fmt"
"log"
"strings"

"google.golang.org/api/dns/v1"
{{- if ne $.TargetVersionName "ga" }}
firebase "google.golang.org/api/firebase/v1beta1"
{{- end }}
"google.golang.org/api/option"
iamcredentials "google.golang.org/api/iamcredentials/v1"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-log/tflog"
Expand Down Expand Up @@ -37,6 +39,20 @@ func (p *FrameworkProviderConfig) NewDnsClient(userAgent string, diags *diag.Dia
return clientDns
}

func (p *FrameworkProviderConfig) NewIamCredentialsClient(userAgent string) *iamcredentials.Service {
iamCredentialsClientBasePath := transport_tpg.RemoveBasePathVersion(p.IAMCredentialsBasePath)
log.Printf("[INFO] Instantiating Google Cloud IAMCredentials client for path %s", iamCredentialsClientBasePath)
clientIamCredentials, err := iamcredentials.NewService(p.Context, option.WithHTTPClient(p.Client))
if err != nil {
log.Printf("[WARN] Error creating client iam credentials: %s", err)
return nil
}
clientIamCredentials.UserAgent = userAgent
clientIamCredentials.BasePath = iamCredentialsClientBasePath

return clientIamCredentials
}

{{ if ne $.TargetVersionName `ga` -}}
func (p *FrameworkProviderConfig) NewFirebaseClient(userAgent string, diags *diag.Diagnostics) *firebase.Service {
firebaseClientBasePath := transport_tpg.RemoveBasePathVersion(p.FirebaseBasePath)
Expand Down