Skip to content

Commit

Permalink
[DataprocGdc] Add Terraform support for Dataproc on GDC resources (#1…
Browse files Browse the repository at this point in the history
…1989) (#8591)

[upstream:198e6d59c30908e12bbc92cb4e98ac6a2a0d7a6c]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Nov 1, 2024
1 parent 6d34cca commit 2dd0fd6
Show file tree
Hide file tree
Showing 13 changed files with 1,217 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/11989.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_dataproc_gdc_service_instance`
```
1 change: 1 addition & 0 deletions google-beta/fwmodels/provider_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type ProviderModel struct {
DataPipelineCustomEndpoint types.String `tfsdk:"data_pipeline_custom_endpoint"`
DataplexCustomEndpoint types.String `tfsdk:"dataplex_custom_endpoint"`
DataprocCustomEndpoint types.String `tfsdk:"dataproc_custom_endpoint"`
DataprocGdcCustomEndpoint types.String `tfsdk:"dataproc_gdc_custom_endpoint"`
DataprocMetastoreCustomEndpoint types.String `tfsdk:"dataproc_metastore_custom_endpoint"`
DatastreamCustomEndpoint types.String `tfsdk:"datastream_custom_endpoint"`
DeploymentManagerCustomEndpoint types.String `tfsdk:"deployment_manager_custom_endpoint"`
Expand Down
6 changes: 6 additions & 0 deletions google-beta/fwprovider/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,12 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
transport_tpg.CustomEndpointValidator(),
},
},
"dataproc_gdc_custom_endpoint": &schema.StringAttribute{
Optional: true,
Validators: []validator.String{
transport_tpg.CustomEndpointValidator(),
},
},
"dataproc_metastore_custom_endpoint": &schema.StringAttribute{
Optional: true,
Validators: []validator.String{
Expand Down
10 changes: 10 additions & 0 deletions google-beta/fwtransport/framework_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type FrameworkProviderConfig struct {
DataPipelineBasePath string
DataplexBasePath string
DataprocBasePath string
DataprocGdcBasePath string
DataprocMetastoreBasePath string
DatastreamBasePath string
DeploymentManagerBasePath string
Expand Down Expand Up @@ -293,6 +294,7 @@ func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context,
p.DataPipelineBasePath = data.DataPipelineCustomEndpoint.ValueString()
p.DataplexBasePath = data.DataplexCustomEndpoint.ValueString()
p.DataprocBasePath = data.DataprocCustomEndpoint.ValueString()
p.DataprocGdcBasePath = data.DataprocGdcCustomEndpoint.ValueString()
p.DataprocMetastoreBasePath = data.DataprocMetastoreCustomEndpoint.ValueString()
p.DatastreamBasePath = data.DatastreamCustomEndpoint.ValueString()
p.DeploymentManagerBasePath = data.DeploymentManagerCustomEndpoint.ValueString()
Expand Down Expand Up @@ -923,6 +925,14 @@ func (p *FrameworkProviderConfig) HandleDefaults(ctx context.Context, data *fwmo
data.DataprocCustomEndpoint = types.StringValue(customEndpoint.(string))
}
}
if data.DataprocGdcCustomEndpoint.IsNull() {
customEndpoint := transport_tpg.MultiEnvDefault([]string{
"GOOGLE_DATAPROC_GDC_CUSTOM_ENDPOINT",
}, transport_tpg.DefaultBasePaths[transport_tpg.DataprocGdcBasePathKey])
if customEndpoint != nil {
data.DataprocGdcCustomEndpoint = types.StringValue(customEndpoint.(string))
}
}
if data.DataprocMetastoreCustomEndpoint.IsNull() {
customEndpoint := transport_tpg.MultiEnvDefault([]string{
"GOOGLE_DATAPROC_METASTORE_CUSTOM_ENDPOINT",
Expand Down
6 changes: 6 additions & 0 deletions google-beta/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ func Provider() *schema.Provider {
Optional: true,
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
},
"dataproc_gdc_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
},
"dataproc_metastore_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1087,6 +1092,7 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.DataPipelineBasePath = d.Get("data_pipeline_custom_endpoint").(string)
config.DataplexBasePath = d.Get("dataplex_custom_endpoint").(string)
config.DataprocBasePath = d.Get("dataproc_custom_endpoint").(string)
config.DataprocGdcBasePath = d.Get("dataproc_gdc_custom_endpoint").(string)
config.DataprocMetastoreBasePath = d.Get("dataproc_metastore_custom_endpoint").(string)
config.DatastreamBasePath = d.Get("datastream_custom_endpoint").(string)
config.DeploymentManagerBasePath = d.Get("deployment_manager_custom_endpoint").(string)
Expand Down
6 changes: 4 additions & 2 deletions google-beta/provider/provider_mmv1_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import (
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/datapipeline"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/dataplex"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/dataproc"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/dataprocgdc"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/dataprocmetastore"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/datastream"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/deploymentmanager"
Expand Down Expand Up @@ -499,9 +500,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
}

// Resources
// Generated resources: 546
// Generated resources: 547
// Generated IAM resources: 291
// Total generated resources: 837
// Total generated resources: 838
var generatedResources = map[string]*schema.Resource{
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
Expand Down Expand Up @@ -885,6 +886,7 @@ var generatedResources = map[string]*schema.Resource{
"google_dataproc_autoscaling_policy_iam_member": tpgiamresource.ResourceIamMember(dataproc.DataprocAutoscalingPolicyIamSchema, dataproc.DataprocAutoscalingPolicyIamUpdaterProducer, dataproc.DataprocAutoscalingPolicyIdParseFunc),
"google_dataproc_autoscaling_policy_iam_policy": tpgiamresource.ResourceIamPolicy(dataproc.DataprocAutoscalingPolicyIamSchema, dataproc.DataprocAutoscalingPolicyIamUpdaterProducer, dataproc.DataprocAutoscalingPolicyIdParseFunc),
"google_dataproc_batch": dataproc.ResourceDataprocBatch(),
"google_dataproc_gdc_service_instance": dataprocgdc.ResourceDataprocGdcServiceInstance(),
"google_dataproc_metastore_federation": dataprocmetastore.ResourceDataprocMetastoreFederation(),
"google_dataproc_metastore_federation_iam_binding": tpgiamresource.ResourceIamBinding(dataprocmetastore.DataprocMetastoreFederationIamSchema, dataprocmetastore.DataprocMetastoreFederationIamUpdaterProducer, dataprocmetastore.DataprocMetastoreFederationIdParseFunc),
"google_dataproc_metastore_federation_iam_member": tpgiamresource.ResourceIamMember(dataprocmetastore.DataprocMetastoreFederationIamSchema, dataprocmetastore.DataprocMetastoreFederationIamUpdaterProducer, dataprocmetastore.DataprocMetastoreFederationIdParseFunc),
Expand Down
92 changes: 92 additions & 0 deletions google-beta/services/dataprocgdc/dataproc_gdc_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------

package dataprocgdc

import (
"encoding/json"
"errors"
"fmt"
"time"

"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

type DataprocGdcOperationWaiter struct {
Config *transport_tpg.Config
UserAgent string
Project string
tpgresource.CommonOperationWaiter
}

func (w *DataprocGdcOperationWaiter) QueryOp() (interface{}, error) {
if w == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
// Returns the proper get.
url := fmt.Sprintf("%s%s", w.Config.DataprocGdcBasePath, w.CommonOperationWaiter.Op.Name)

return transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: w.Config,
Method: "GET",
Project: w.Project,
RawURL: url,
UserAgent: w.UserAgent,
})
}

func createDataprocGdcWaiter(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string) (*DataprocGdcOperationWaiter, error) {
w := &DataprocGdcOperationWaiter{
Config: config,
UserAgent: userAgent,
Project: project,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return nil, err
}
return w, nil
}

// nolint: deadcode,unused
func DataprocGdcOperationWaitTimeWithResponse(config *transport_tpg.Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
w, err := createDataprocGdcWaiter(config, op, project, activity, userAgent)
if err != nil {
return err
}
if err := tpgresource.OperationWait(w, activity, timeout, config.PollInterval); err != nil {
return err
}
rawResponse := []byte(w.CommonOperationWaiter.Op.Response)
if len(rawResponse) == 0 {
return errors.New("`resource` not set in operation response")
}
return json.Unmarshal(rawResponse, response)
}

func DataprocGdcOperationWaitTime(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil
}
w, err := createDataprocGdcWaiter(config, op, project, activity, userAgent)
if err != nil {
// If w is nil, the op was synchronous.
return err
}
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
}
Loading

0 comments on commit 2dd0fd6

Please sign in to comment.