Skip to content

Commit

Permalink
add iamcredentialsbasepath support for plugin framework (GoogleCloudP…
Browse files Browse the repository at this point in the history
  • Loading branch information
BBBmau committed Nov 5, 2024
1 parent 8242932 commit 5c45337
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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

0 comments on commit 5c45337

Please sign in to comment.