@@ -329,34 +329,27 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
329329 })
330330 }
331331
332- // The mtls service client gives the type of endpoint (mtls/regular)
333- // at client creation. Since we use a shared client for requests we must
334- // rewrite the endpoints to be mtls endpoints for the scenario where
335- // mtls is enabled.
336- if isMtls() {
337- // if mtls is enabled switch all default endpoints to use the mtls endpoint
338- for key, bp := range transport_tpg.DefaultBasePaths {
339- transport_tpg.DefaultBasePaths [key] = getMtlsEndpoint(bp)
332+ config.CustomEndpoints = map[string]string{}
333+ for _, p := range registry.ListProducts () {
334+ customEndpoint := " "
335+ if v := d.Get (p.CustomEndpointField ). (string); v != " " {
336+ customEndpoint = v
337+ } else if v = transport_tpg.MultiEnvSearch ([]string{p.CustomEndpointEnvVar }); v != " " {
338+ customEndpoint = v
339+ }
340+ if customEndpoint != " " {
341+ config.CustomEndpoints [p.CustomEndpointField ] = customEndpoint
340342 }
341343 }
344+
345+ // Detect whether this is running in an mTLS context.
346+ config.IsMtls = transport_tpg.IsMtls ()
342347
343348 // Set the universe domain to the configured value, if any
344349 if v, ok := d.GetOk (" universe_domain" ); ok {
345350 config.UniverseDomain = v. (string)
346351 }
347352
348- // Replace hostname by the universe_domain field.
349- if config.UniverseDomain != " " && config.UniverseDomain != " googleapis.com" {
350- for key, basePath := range transport_tpg.DefaultBasePaths {
351- transport_tpg.DefaultBasePaths [key] = strings.ReplaceAll (basePath, " googleapis.com" , config.UniverseDomain )
352- }
353- }
354-
355- err = transport_tpg.SetEndpointDefaults (d)
356- if err != nil {
357- return nil , diag.FromErr (err)
358- }
359-
360353 // Given that impersonate_service_account is a secondary auth method, it has
361354 // no conflicts to worry about. We pull the env var in a DefaultFunc.
362355 if v, ok := d.GetOk (" impersonate_service_account" ); ok {
@@ -405,14 +398,36 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
405398 }
406399 config.BatchingConfig = batchCfg
407400
408- // Generated products
401+ // Registered products
409402 {{- range $product := $ .Products }}
410- config. {{ $product .Name }}BasePath = d .Get ( " {{ underscore $product.Name }}_custom_endpoint " ) . (string )
403+ config. {{ $product .Name }}BasePath = transport_tpg .BaseUrl (registry .GetProduct ( " {{ lower $product.Name }}" ), &config )
411404 {{- if $product .Version.RepEnabled }}
412- config. {{ $product .Name }}RepBasePath = " {{ $product.Version.RepUrl }}"
405+ config. {{ $product .Name }}RepBasePath = registry .GetProduct ( " {{ lower $product.Name }}" ) .RepUrl
413406 {{- end -}}
414407 {{- end }}
415408
409+ // Legacy logic for non-registered products
410+ // The mtls service client gives the type of endpoint (mtls/regular)
411+ // at client creation. Since we use a shared client for requests we must
412+ // rewrite the endpoints to be mtls endpoints for the scenario where
413+ // mtls is enabled.
414+ if config.IsMtls {
415+ // if mtls is enabled switch all default endpoints to use the mtls endpoint
416+ for key, bp := range transport_tpg.DefaultBasePaths {
417+ transport_tpg.DefaultBasePaths [key] = transport_tpg.GetMtlsEndpoint (bp)
418+ }
419+ }
420+ // Replace hostname by the universe_domain field.
421+ if config.UniverseDomain != " " && config.UniverseDomain != " googleapis.com" {
422+ for key, basePath := range transport_tpg.DefaultBasePaths {
423+ transport_tpg.DefaultBasePaths [key] = strings.ReplaceAll (basePath, " googleapis.com" , config.UniverseDomain )
424+ }
425+ }
426+ err = transport_tpg.SetEndpointDefaults (d)
427+ if err != nil {
428+ return nil , diag.FromErr (err)
429+ }
430+
416431 // Handwritten Products / Versioned / Atypical Entries
417432 config.DataflowBasePath = d.Get (transport_tpg.DataflowCustomEndpointEntryKey ). (string)
418433 config.IamCredentialsBasePath = d.Get (transport_tpg.IamCredentialsCustomEndpointEntryKey ). (string)
0 commit comments