Skip to content

Commit 25a423c

Browse files
authored
Enable custom endpoints for all DCL-based resources (#14778)
1 parent 485317a commit 25a423c

22 files changed

Lines changed: 169 additions & 140 deletions

mmv1/third_party/terraform/fwmodels/provider_model.go.tmpl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,9 @@ type ProviderModel struct {
5959
// dcl generated
6060
ApikeysCustomEndpoint types.String `tfsdk:"apikeys_custom_endpoint"`
6161
AssuredWorkloadsCustomEndpoint types.String `tfsdk:"assured_workloads_custom_endpoint"`
62-
CloudBuildWorkerPoolCustomEndpoint types.String `tfsdk:"cloud_build_worker_pool_custom_endpoint"`
6362
CloudResourceManagerCustomEndpoint types.String `tfsdk:"cloud_resource_manager_custom_endpoint"`
6463
FirebaserulesCustomEndpoint types.String `tfsdk:"firebaserules_custom_endpoint"`
6564
RecaptchaEnterpriseCustomEndpoint types.String `tfsdk:"recaptcha_enterprise_custom_endpoint"`
66-
67-
GkehubFeatureCustomEndpoint types.String `tfsdk:"gkehub_feature_custom_endpoint"`
6865
}
6966

7067
type ProviderBatching struct {

mmv1/third_party/terraform/fwprovider/framework_provider.go.tmpl

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
222222
},
223223
},
224224

225-
// dcl
225+
// DCL
226226
"container_aws_custom_endpoint": &schema.StringAttribute{
227227
Optional: true,
228228
Validators: []validator.String{
@@ -235,6 +235,36 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
235235
transport_tpg.CustomEndpointValidator(),
236236
},
237237
},
238+
"apikeys_custom_endpoint": &schema.StringAttribute{
239+
Optional: true,
240+
Validators: []validator.String{
241+
transport_tpg.CustomEndpointValidator(),
242+
},
243+
},
244+
"assured_workloads_custom_endpoint": &schema.StringAttribute{
245+
Optional: true,
246+
Validators: []validator.String{
247+
transport_tpg.CustomEndpointValidator(),
248+
},
249+
},
250+
"cloud_resource_manager_custom_endpoint": &schema.StringAttribute{
251+
Optional: true,
252+
Validators: []validator.String{
253+
transport_tpg.CustomEndpointValidator(),
254+
},
255+
},
256+
"firebaserules_custom_endpoint": &schema.StringAttribute{
257+
Optional: true,
258+
Validators: []validator.String{
259+
transport_tpg.CustomEndpointValidator(),
260+
},
261+
},
262+
"recaptcha_enterprise_custom_endpoint": &schema.StringAttribute{
263+
Optional: true,
264+
Validators: []validator.String{
265+
transport_tpg.CustomEndpointValidator(),
266+
},
267+
},
238268
},
239269
Blocks: map[string]schema.Block{
240270
"batching": schema.ListNestedBlock{
@@ -278,8 +308,6 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
278308
},
279309
},
280310
}
281-
282-
transport_tpg.ConfigureDCLCustomEndpointAttributesFramework(&resp.Schema)
283311
}
284312

285313
// Configure prepares the metadata/'meta' required for data sources and resources to function.

mmv1/third_party/terraform/provider/provider.go.tmpl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ func Provider() *schema.Provider {
197197
// dcl
198198
transport_tpg.ContainerAwsCustomEndpointEntryKey: transport_tpg.ContainerAwsCustomEndpointEntry,
199199
transport_tpg.ContainerAzureCustomEndpointEntryKey: transport_tpg.ContainerAzureCustomEndpointEntry,
200+
transport_tpg.ApikeysEndpointEntryKey: transport_tpg.ApikeysEndpointEntry,
201+
transport_tpg.AssuredWorkloadsEndpointEntryKey: transport_tpg.AssuredWorkloadsEndpointEntry,
202+
transport_tpg.CloudResourceManagerEndpointEntryKey: transport_tpg.CloudResourceManagerEndpointEntry,
203+
transport_tpg.FirebaserulesEndpointEntryKey: transport_tpg.FirebaserulesEndpointEntry,
204+
transport_tpg.RecaptchaEnterpriseEndpointEntryKey: transport_tpg.RecaptchaEnterpriseEndpointEntry,
200205
},
201206

202207
ProviderMetaSchema: map[string]*schema.Schema{
@@ -214,9 +219,6 @@ func Provider() *schema.Provider {
214219
provider.ConfigureContextFunc = func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
215220
return ProviderConfigure(ctx, d, provider)
216221
}
217-
{{ if ne $.Compiler "terraformgoogleconversion-codegen"}}
218-
transport_tpg.ConfigureDCLProvider(provider)
219-
{{ end }}
220222
return provider
221223
}
222224
{{ if ne $.Compiler "terraformgoogleconversion-codegen"}}
@@ -328,10 +330,6 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
328330
if v, ok := d.GetOk("universe_domain"); ok {
329331
config.UniverseDomain = v.(string)
330332
}
331-
{{ if ne $.Compiler "terraformgoogleconversion-codegen"}}
332-
// Configure DCL basePath
333-
transport_tpg.ProviderDCLConfigure(d, &config)
334-
{{- end }}
335333

336334
// Replace hostname by the universe_domain field.
337335
if config.UniverseDomain != "" && config.UniverseDomain != "googleapis.com" {
@@ -344,9 +342,6 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
344342
if err != nil {
345343
return nil, diag.FromErr(err)
346344
}
347-
{{- if ne $.Compiler "terraformgoogleconversion-codegen"}}
348-
transport_tpg.HandleDCLCustomEndpointDefaults(d)
349-
{{- end }}
350345

351346
// Given that impersonate_service_account is a secondary auth method, it has
352347
// no conflicts to worry about. We pull the env var in a DefaultFunc.
@@ -419,6 +414,11 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
419414
// dcl
420415
config.ContainerAwsBasePath = d.Get(transport_tpg.ContainerAwsCustomEndpointEntryKey).(string)
421416
config.ContainerAzureBasePath = d.Get(transport_tpg.ContainerAzureCustomEndpointEntryKey).(string)
417+
config.ApikeysBasePath = d.Get(transport_tpg.ApikeysEndpointEntryKey).(string)
418+
config.AssuredWorkloadsBasePath = d.Get(transport_tpg.AssuredWorkloadsEndpointEntryKey).(string)
419+
config.CloudResourceManagerBasePath = d.Get(transport_tpg.CloudResourceManagerEndpointEntryKey).(string)
420+
config.FirebaserulesBasePath = d.Get(transport_tpg.FirebaserulesEndpointEntryKey).(string)
421+
config.RecaptchaEnterpriseBasePath = d.Get(transport_tpg.RecaptchaEnterpriseEndpointEntryKey).(string)
422422

423423
stopCtx, ok := schema.StopContext(ctx)
424424
if !ok {

mmv1/third_party/terraform/transport/config.go.tmpl

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,6 @@ func ExpandExternalCredentialsConfig(v interface{}) (*ExternalCredentials, error
234234
// Config is the configuration structure used to instantiate the Google
235235
// provider.
236236
type Config struct {
237-
{{- if ne $.Compiler "terraformgoogleconversion-codegen"}}
238-
DCLConfig
239-
{{- end }}
240237
AccessToken string
241238
Credentials string
242239
ExternalCredentials *ExternalCredentials
@@ -280,9 +277,14 @@ type Config struct {
280277
BigtableAdminBasePath string
281278
TagsLocationBasePath string
282279

283-
// dcl
280+
// DCL
284281
ContainerAwsBasePath string
285282
ContainerAzureBasePath string
283+
ApikeysBasePath string
284+
AssuredWorkloadsBasePath string
285+
CloudResourceManagerBasePath string
286+
FirebaserulesBasePath string
287+
RecaptchaEnterpriseBasePath string
286288

287289
RequestBatcherServiceUsage *RequestBatcher
288290
RequestBatcherIam *RequestBatcher
@@ -318,9 +320,19 @@ var DefaultBasePaths = map[string]string{
318320
IamCredentialsBasePathKey : "https://iamcredentials.googleapis.com/v1/",
319321
ResourceManagerV3BasePathKey : "https://cloudresourcemanager.googleapis.com/v3/",
320322
BigtableAdminBasePathKey : "https://bigtableadmin.googleapis.com/v2/",
321-
ContainerAwsBasePathKey: "https://{{"{{"}}location{{"}}"}}-gkemulticloud.googleapis.com/v1/",
322-
ContainerAzureBasePathKey: "https://{{"{{"}}location{{"}}"}}-gkemulticloud.googleapis.com/v1/",
323323
TagsLocationBasePathKey: "https://{{"{{"}}location{{"}}"}}-cloudresourcemanager.googleapis.com/v3/",
324+
// DCL
325+
ContainerAwsBasePathKey: "https://{{"{{"}}location{{"}}"}}-gkemulticloud.googleapis.com/v1/",
326+
ContainerAzureBasePathKey: "https://{{"{{"}}location{{"}}"}}-gkemulticloud.googleapis.com/v1/",
327+
ApikeysEndpointEntryKey: "https://apikeys.googleapis.com/v2/",
328+
{{- if eq $.TargetVersionName "ga" }}
329+
AssuredWorkloadsEndpointEntryKey: "https://{{"{{"}}location{{"}}"}}-assuredworkloads.googleapis.com/v1beta1/",
330+
{{- else }}
331+
AssuredWorkloadsEndpointEntryKey: "https://{{"{{"}}location{{"}}"}}-assuredworkloads.googleapis.com/v1/",
332+
{{- end }}
333+
CloudResourceManagerEndpointEntryKey: "https://cloudresourcemanager.googleapis.com/",
334+
FirebaserulesEndpointEntryKey: "https://firebaserules.googleapis.com/v1/",
335+
RecaptchaEnterpriseEndpointEntryKey: "https://recaptchaenterprise.googleapis.com/v1/",
324336
}
325337

326338
var DefaultClientScopes = []string{
@@ -465,6 +477,9 @@ func SetEndpointDefaults(d *schema.ResourceData) error {
465477
}, DefaultBasePaths[TagsLocationBasePathKey]))
466478
}
467479

480+
// DCL endpoints - these are hardcoded as a workaround for the DCL not providing a way to
481+
// determine base paths at generation time.
482+
468483
if d.Get(ContainerAwsCustomEndpointEntryKey) == "" {
469484
d.Set(ContainerAwsCustomEndpointEntryKey, MultiEnvDefault([]string{
470485
"GOOGLE_CONTAINERAWS_CUSTOM_ENDPOINT",
@@ -476,6 +491,31 @@ func SetEndpointDefaults(d *schema.ResourceData) error {
476491
"GOOGLE_CONTAINERAZURE_CUSTOM_ENDPOINT",
477492
}, DefaultBasePaths[ContainerAzureBasePathKey]))
478493
}
494+
if d.Get(ApikeysEndpointEntryKey) == "" {
495+
d.Set(ApikeysEndpointEntryKey, MultiEnvDefault([]string{
496+
"GOOGLE_APIKEYS_CUSTOM_ENDPOINT",
497+
}, DefaultBasePaths[ApikeysEndpointEntryKey]))
498+
}
499+
if d.Get(AssuredWorkloadsEndpointEntryKey) == "" {
500+
d.Set(AssuredWorkloadsEndpointEntryKey, MultiEnvDefault([]string{
501+
"GOOGLE_ASSURED_WORKLOADS_CUSTOM_ENDPOINT",
502+
}, DefaultBasePaths[AssuredWorkloadsEndpointEntryKey]))
503+
}
504+
if d.Get(CloudResourceManagerEndpointEntryKey) == "" {
505+
d.Set(CloudResourceManagerEndpointEntryKey, MultiEnvDefault([]string{
506+
"GOOGLE_CLOUD_RESOURCE_MANAGER_CUSTOM_ENDPOINT",
507+
}, DefaultBasePaths[CloudResourceManagerEndpointEntryKey]))
508+
}
509+
if d.Get(FirebaserulesEndpointEntryKey) == "" {
510+
d.Set(FirebaserulesEndpointEntryKey, MultiEnvDefault([]string{
511+
"GOOGLE_FIREBASERULES_CUSTOM_ENDPOINT",
512+
}, DefaultBasePaths[FirebaserulesEndpointEntryKey]))
513+
}
514+
if d.Get(RecaptchaEnterpriseEndpointEntryKey) == "" {
515+
d.Set(RecaptchaEnterpriseEndpointEntryKey, MultiEnvDefault([]string{
516+
"GOOGLE_RECAPTCHA_ENTERPRISE_CUSTOM_ENDPOINT",
517+
}, DefaultBasePaths[RecaptchaEnterpriseEndpointEntryKey]))
518+
}
479519

480520
return nil
481521
}
@@ -1453,6 +1493,15 @@ func ConfigureBasePaths(c *Config) {
14531493
c.BigQueryBasePath = DefaultBasePaths[BigQueryBasePathKey]
14541494
c.BigtableAdminBasePath = DefaultBasePaths[BigtableAdminBasePathKey]
14551495
c.TagsLocationBasePath = DefaultBasePaths[TagsLocationBasePathKey]
1496+
1497+
// DCL
1498+
c.ContainerAwsBasePath = DefaultBasePaths[ContainerAwsBasePathKey]
1499+
c.ContainerAzureBasePath = DefaultBasePaths[ContainerAzureBasePathKey]
1500+
c.ApikeysBasePath = DefaultBasePaths[ApikeysEndpointEntryKey]
1501+
c.AssuredWorkloadsBasePath = DefaultBasePaths[AssuredWorkloadsEndpointEntryKey]
1502+
c.CloudResourceManagerBasePath = DefaultBasePaths[CloudResourceManagerEndpointEntryKey]
1503+
c.FirebaserulesBasePath = DefaultBasePaths[FirebaserulesEndpointEntryKey]
1504+
c.RecaptchaEnterpriseBasePath = DefaultBasePaths[RecaptchaEnterpriseEndpointEntryKey]
14561505
}
14571506

14581507
func GetCurrentUserEmail(config *Config, userAgent string) (string, error) {

mmv1/third_party/terraform/transport/provider_handwritten_endpoint.go.tmpl

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ var PrivatecaCertificateTemplateCustomEndpointEntry = &schema.Schema{
104104
}, DefaultBasePaths[PrivatecaBasePathKey]),
105105
}
106106

107+
var TagsLocationCustomEndpointEntryKey = "tags_location_custom_endpoint"
108+
var TagsLocationCustomEndpointEntry = &schema.Schema{
109+
Type: schema.TypeString,
110+
Optional: true,
111+
ValidateFunc: ValidateCustomEndpoint,
112+
}
113+
114+
// DCL
107115
var ContainerAwsCustomEndpointEntryKey = "container_aws_custom_endpoint"
108116
var ContainerAwsCustomEndpointEntry = &schema.Schema{
109117
Type: schema.TypeString,
@@ -117,12 +125,34 @@ var ContainerAzureCustomEndpointEntry = &schema.Schema{
117125
Optional: true,
118126
ValidateFunc: ValidateCustomEndpoint,
119127
}
128+
var ApikeysEndpointEntryKey = "apikeys_custom_endpoint"
129+
var ApikeysEndpointEntry = &schema.Schema{
130+
Type: schema.TypeString,
131+
Optional: true,
132+
}
120133

121-
var TagsLocationCustomEndpointEntryKey = "tags_location_custom_endpoint"
122-
var TagsLocationCustomEndpointEntry = &schema.Schema{
123-
Type: schema.TypeString,
124-
Optional: true,
125-
ValidateFunc: ValidateCustomEndpoint,
134+
var AssuredWorkloadsEndpointEntryKey = "assured_workloads_custom_endpoint"
135+
var AssuredWorkloadsEndpointEntry = &schema.Schema{
136+
Type: schema.TypeString,
137+
Optional: true,
138+
}
139+
140+
var CloudResourceManagerEndpointEntryKey = "cloud_resource_manager_custom_endpoint"
141+
var CloudResourceManagerEndpointEntry = &schema.Schema{
142+
Type: schema.TypeString,
143+
Optional: true,
144+
}
145+
146+
var FirebaserulesEndpointEntryKey = "firebaserules_custom_endpoint"
147+
var FirebaserulesEndpointEntry = &schema.Schema{
148+
Type: schema.TypeString,
149+
Optional: true,
150+
}
151+
152+
var RecaptchaEnterpriseEndpointEntryKey = "recaptcha_enterprise_custom_endpoint"
153+
var RecaptchaEnterpriseEndpointEntry = &schema.Schema{
154+
Type: schema.TypeString,
155+
Optional: true,
126156
}
127157

128158
func ValidateCustomEndpoint(v interface{}, k string) (ws []string, errors []error) {

mmv1/third_party/tgc/dcl.go

Lines changed: 0 additions & 3 deletions
This file was deleted.

tpgtools/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ func main() {
110110
}
111111

112112
// product specific generation
113-
generateProductsFile("provider_dcl_endpoints", productsForVersion)
114113
generateProductsFile("provider_dcl_client_creation", productsForVersion)
115114

116115
if oPath == nil || *oPath == "" {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- type: PRODUCT_BASE_PATH
2+
details:
3+
skip: true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- type: PRODUCT_BASE_PATH
2+
details:
3+
skip: true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- type: PRODUCT_BASE_PATH
2+
details:
3+
skip: true

0 commit comments

Comments
 (0)