Skip to content

Commit 1776913

Browse files
Enable custom endpoints for all DCL-based resources (#14778) (#24005)
[upstream:25a423c917bb808023a8f9da7acc02e3318b4558] Signed-off-by: Modular Magician <[email protected]>
1 parent ac68af0 commit 1776913

File tree

7 files changed

+131
-213
lines changed

7 files changed

+131
-213
lines changed

google/fwmodels/provider_model.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,9 @@ type ProviderModel struct {
215215
// dcl generated
216216
ApikeysCustomEndpoint types.String `tfsdk:"apikeys_custom_endpoint"`
217217
AssuredWorkloadsCustomEndpoint types.String `tfsdk:"assured_workloads_custom_endpoint"`
218-
CloudBuildWorkerPoolCustomEndpoint types.String `tfsdk:"cloud_build_worker_pool_custom_endpoint"`
219218
CloudResourceManagerCustomEndpoint types.String `tfsdk:"cloud_resource_manager_custom_endpoint"`
220219
FirebaserulesCustomEndpoint types.String `tfsdk:"firebaserules_custom_endpoint"`
221220
RecaptchaEnterpriseCustomEndpoint types.String `tfsdk:"recaptcha_enterprise_custom_endpoint"`
222-
223-
GkehubFeatureCustomEndpoint types.String `tfsdk:"gkehub_feature_custom_endpoint"`
224221
}
225222

226223
type ProviderBatching struct {

google/fwprovider/framework_provider.go

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

1098-
// dcl
1098+
// DCL
10991099
"container_aws_custom_endpoint": &schema.StringAttribute{
11001100
Optional: true,
11011101
Validators: []validator.String{
@@ -1108,6 +1108,36 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
11081108
transport_tpg.CustomEndpointValidator(),
11091109
},
11101110
},
1111+
"apikeys_custom_endpoint": &schema.StringAttribute{
1112+
Optional: true,
1113+
Validators: []validator.String{
1114+
transport_tpg.CustomEndpointValidator(),
1115+
},
1116+
},
1117+
"assured_workloads_custom_endpoint": &schema.StringAttribute{
1118+
Optional: true,
1119+
Validators: []validator.String{
1120+
transport_tpg.CustomEndpointValidator(),
1121+
},
1122+
},
1123+
"cloud_resource_manager_custom_endpoint": &schema.StringAttribute{
1124+
Optional: true,
1125+
Validators: []validator.String{
1126+
transport_tpg.CustomEndpointValidator(),
1127+
},
1128+
},
1129+
"firebaserules_custom_endpoint": &schema.StringAttribute{
1130+
Optional: true,
1131+
Validators: []validator.String{
1132+
transport_tpg.CustomEndpointValidator(),
1133+
},
1134+
},
1135+
"recaptcha_enterprise_custom_endpoint": &schema.StringAttribute{
1136+
Optional: true,
1137+
Validators: []validator.String{
1138+
transport_tpg.CustomEndpointValidator(),
1139+
},
1140+
},
11111141
},
11121142
Blocks: map[string]schema.Block{
11131143
"batching": schema.ListNestedBlock{
@@ -1151,8 +1181,6 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
11511181
},
11521182
},
11531183
}
1154-
1155-
transport_tpg.ConfigureDCLCustomEndpointAttributesFramework(&resp.Schema)
11561184
}
11571185

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

google/provider/provider.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,11 @@ func Provider() *schema.Provider {
933933
// dcl
934934
transport_tpg.ContainerAwsCustomEndpointEntryKey: transport_tpg.ContainerAwsCustomEndpointEntry,
935935
transport_tpg.ContainerAzureCustomEndpointEntryKey: transport_tpg.ContainerAzureCustomEndpointEntry,
936+
transport_tpg.ApikeysEndpointEntryKey: transport_tpg.ApikeysEndpointEntry,
937+
transport_tpg.AssuredWorkloadsEndpointEntryKey: transport_tpg.AssuredWorkloadsEndpointEntry,
938+
transport_tpg.CloudResourceManagerEndpointEntryKey: transport_tpg.CloudResourceManagerEndpointEntry,
939+
transport_tpg.FirebaserulesEndpointEntryKey: transport_tpg.FirebaserulesEndpointEntry,
940+
transport_tpg.RecaptchaEnterpriseEndpointEntryKey: transport_tpg.RecaptchaEnterpriseEndpointEntry,
936941
},
937942

938943
ProviderMetaSchema: map[string]*schema.Schema{
@@ -949,9 +954,6 @@ func Provider() *schema.Provider {
949954
provider.ConfigureContextFunc = func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
950955
return ProviderConfigure(ctx, d, provider)
951956
}
952-
953-
transport_tpg.ConfigureDCLProvider(provider)
954-
955957
return provider
956958
}
957959

@@ -1052,9 +1054,6 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
10521054
config.UniverseDomain = v.(string)
10531055
}
10541056

1055-
// Configure DCL basePath
1056-
transport_tpg.ProviderDCLConfigure(d, &config)
1057-
10581057
// Replace hostname by the universe_domain field.
10591058
if config.UniverseDomain != "" && config.UniverseDomain != "googleapis.com" {
10601059
for key, basePath := range transport_tpg.DefaultBasePaths {
@@ -1066,7 +1065,6 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
10661065
if err != nil {
10671066
return nil, diag.FromErr(err)
10681067
}
1069-
transport_tpg.HandleDCLCustomEndpointDefaults(d)
10701068

10711069
// Given that impersonate_service_account is a secondary auth method, it has
10721070
// no conflicts to worry about. We pull the env var in a DefaultFunc.
@@ -1279,6 +1277,11 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
12791277
// dcl
12801278
config.ContainerAwsBasePath = d.Get(transport_tpg.ContainerAwsCustomEndpointEntryKey).(string)
12811279
config.ContainerAzureBasePath = d.Get(transport_tpg.ContainerAzureCustomEndpointEntryKey).(string)
1280+
config.ApikeysBasePath = d.Get(transport_tpg.ApikeysEndpointEntryKey).(string)
1281+
config.AssuredWorkloadsBasePath = d.Get(transport_tpg.AssuredWorkloadsEndpointEntryKey).(string)
1282+
config.CloudResourceManagerBasePath = d.Get(transport_tpg.CloudResourceManagerEndpointEntryKey).(string)
1283+
config.FirebaserulesBasePath = d.Get(transport_tpg.FirebaserulesEndpointEntryKey).(string)
1284+
config.RecaptchaEnterpriseBasePath = d.Get(transport_tpg.RecaptchaEnterpriseEndpointEntryKey).(string)
12821285

12831286
stopCtx, ok := schema.StopContext(ctx)
12841287
if !ok {

google/transport/config.go

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ func ExpandExternalCredentialsConfig(v interface{}) (*ExternalCredentials, error
228228
// Config is the configuration structure used to instantiate the Google
229229
// provider.
230230
type Config struct {
231-
DCLConfig
232231
AccessToken string
233232
Credentials string
234233
ExternalCredentials *ExternalCredentials
@@ -415,9 +414,14 @@ type Config struct {
415414
BigtableAdminBasePath string
416415
TagsLocationBasePath string
417416

418-
// dcl
419-
ContainerAwsBasePath string
420-
ContainerAzureBasePath string
417+
// DCL
418+
ContainerAwsBasePath string
419+
ContainerAzureBasePath string
420+
ApikeysBasePath string
421+
AssuredWorkloadsBasePath string
422+
CloudResourceManagerBasePath string
423+
FirebaserulesBasePath string
424+
RecaptchaEnterpriseBasePath string
421425

422426
RequestBatcherServiceUsage *RequestBatcher
423427
RequestBatcherIam *RequestBatcher
@@ -735,9 +739,15 @@ var DefaultBasePaths = map[string]string{
735739
IamCredentialsBasePathKey: "https://iamcredentials.googleapis.com/v1/",
736740
ResourceManagerV3BasePathKey: "https://cloudresourcemanager.googleapis.com/v3/",
737741
BigtableAdminBasePathKey: "https://bigtableadmin.googleapis.com/v2/",
738-
ContainerAwsBasePathKey: "https://{{location}}-gkemulticloud.googleapis.com/v1/",
739-
ContainerAzureBasePathKey: "https://{{location}}-gkemulticloud.googleapis.com/v1/",
740742
TagsLocationBasePathKey: "https://{{location}}-cloudresourcemanager.googleapis.com/v3/",
743+
// DCL
744+
ContainerAwsBasePathKey: "https://{{location}}-gkemulticloud.googleapis.com/v1/",
745+
ContainerAzureBasePathKey: "https://{{location}}-gkemulticloud.googleapis.com/v1/",
746+
ApikeysEndpointEntryKey: "https://apikeys.googleapis.com/v2/",
747+
AssuredWorkloadsEndpointEntryKey: "https://{{location}}-assuredworkloads.googleapis.com/v1beta1/",
748+
CloudResourceManagerEndpointEntryKey: "https://cloudresourcemanager.googleapis.com/",
749+
FirebaserulesEndpointEntryKey: "https://firebaserules.googleapis.com/v1/",
750+
RecaptchaEnterpriseEndpointEntryKey: "https://recaptchaenterprise.googleapis.com/v1/",
741751
}
742752

743753
var DefaultClientScopes = []string{
@@ -1597,6 +1607,9 @@ func SetEndpointDefaults(d *schema.ResourceData) error {
15971607
}, DefaultBasePaths[TagsLocationBasePathKey]))
15981608
}
15991609

1610+
// DCL endpoints - these are hardcoded as a workaround for the DCL not providing a way to
1611+
// determine base paths at generation time.
1612+
16001613
if d.Get(ContainerAwsCustomEndpointEntryKey) == "" {
16011614
d.Set(ContainerAwsCustomEndpointEntryKey, MultiEnvDefault([]string{
16021615
"GOOGLE_CONTAINERAWS_CUSTOM_ENDPOINT",
@@ -1608,6 +1621,31 @@ func SetEndpointDefaults(d *schema.ResourceData) error {
16081621
"GOOGLE_CONTAINERAZURE_CUSTOM_ENDPOINT",
16091622
}, DefaultBasePaths[ContainerAzureBasePathKey]))
16101623
}
1624+
if d.Get(ApikeysEndpointEntryKey) == "" {
1625+
d.Set(ApikeysEndpointEntryKey, MultiEnvDefault([]string{
1626+
"GOOGLE_APIKEYS_CUSTOM_ENDPOINT",
1627+
}, DefaultBasePaths[ApikeysEndpointEntryKey]))
1628+
}
1629+
if d.Get(AssuredWorkloadsEndpointEntryKey) == "" {
1630+
d.Set(AssuredWorkloadsEndpointEntryKey, MultiEnvDefault([]string{
1631+
"GOOGLE_ASSURED_WORKLOADS_CUSTOM_ENDPOINT",
1632+
}, DefaultBasePaths[AssuredWorkloadsEndpointEntryKey]))
1633+
}
1634+
if d.Get(CloudResourceManagerEndpointEntryKey) == "" {
1635+
d.Set(CloudResourceManagerEndpointEntryKey, MultiEnvDefault([]string{
1636+
"GOOGLE_CLOUD_RESOURCE_MANAGER_CUSTOM_ENDPOINT",
1637+
}, DefaultBasePaths[CloudResourceManagerEndpointEntryKey]))
1638+
}
1639+
if d.Get(FirebaserulesEndpointEntryKey) == "" {
1640+
d.Set(FirebaserulesEndpointEntryKey, MultiEnvDefault([]string{
1641+
"GOOGLE_FIREBASERULES_CUSTOM_ENDPOINT",
1642+
}, DefaultBasePaths[FirebaserulesEndpointEntryKey]))
1643+
}
1644+
if d.Get(RecaptchaEnterpriseEndpointEntryKey) == "" {
1645+
d.Set(RecaptchaEnterpriseEndpointEntryKey, MultiEnvDefault([]string{
1646+
"GOOGLE_RECAPTCHA_ENTERPRISE_CUSTOM_ENDPOINT",
1647+
}, DefaultBasePaths[RecaptchaEnterpriseEndpointEntryKey]))
1648+
}
16111649

16121650
return nil
16131651
}
@@ -2694,6 +2732,15 @@ func ConfigureBasePaths(c *Config) {
26942732
c.BigQueryBasePath = DefaultBasePaths[BigQueryBasePathKey]
26952733
c.BigtableAdminBasePath = DefaultBasePaths[BigtableAdminBasePathKey]
26962734
c.TagsLocationBasePath = DefaultBasePaths[TagsLocationBasePathKey]
2735+
2736+
// DCL
2737+
c.ContainerAwsBasePath = DefaultBasePaths[ContainerAwsBasePathKey]
2738+
c.ContainerAzureBasePath = DefaultBasePaths[ContainerAzureBasePathKey]
2739+
c.ApikeysBasePath = DefaultBasePaths[ApikeysEndpointEntryKey]
2740+
c.AssuredWorkloadsBasePath = DefaultBasePaths[AssuredWorkloadsEndpointEntryKey]
2741+
c.CloudResourceManagerBasePath = DefaultBasePaths[CloudResourceManagerEndpointEntryKey]
2742+
c.FirebaserulesBasePath = DefaultBasePaths[FirebaserulesEndpointEntryKey]
2743+
c.RecaptchaEnterpriseBasePath = DefaultBasePaths[RecaptchaEnterpriseEndpointEntryKey]
26972744
}
26982745

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

google/transport/provider_dcl_client_creation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func NewDCLCloudbuildClient(config *Config, userAgent, billingProject string, ti
8989
dcl.WithHTTPClient(config.Client),
9090
dcl.WithUserAgent(userAgent),
9191
dcl.WithLogger(dclLogger{}),
92-
dcl.WithBasePath(config.CloudBuildWorkerPoolBasePath),
92+
dcl.WithBasePath(config.CloudBuildBasePath),
9393
}
9494

9595
if timeout != 0 {
@@ -273,7 +273,7 @@ func NewDCLGkeHubClient(config *Config, userAgent, billingProject string, timeou
273273
dcl.WithHTTPClient(config.Client),
274274
dcl.WithUserAgent(userAgent),
275275
dcl.WithLogger(dclLogger{}),
276-
dcl.WithBasePath(config.GKEHubFeatureBasePath),
276+
dcl.WithBasePath(config.GKEHubBasePath),
277277
}
278278

279279
if timeout != 0 {

0 commit comments

Comments
 (0)