Skip to content

Commit 2f894ff

Browse files
Add resource Dataproc batch (#11750) (#8306)
[upstream:a0b7099e82cb2d112518628de9032ab92754838b] Signed-off-by: Modular Magician <[email protected]>
1 parent 0891323 commit 2f894ff

11 files changed

+3472
-7
lines changed

Diff for: .changelog/11750.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:new-resource
2+
`google_dataproc_batch`
3+
```
4+
```release-note:enhancement
5+
dataproc: switched to the v1 API for `google_dataproc_autoscaling_policy` resource (beta)
6+
```

Diff for: google-beta/acctest/bootstrap_test_utils.go

+25-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"fmt"
88
"log"
9+
"maps"
910
"os"
1011
"strings"
1112
"testing"
@@ -912,7 +913,25 @@ func BootstrapSharedCaPoolInLocation(t *testing.T, location string) string {
912913
return poolName
913914
}
914915

916+
func BootstrapSubnetForDataprocBatches(t *testing.T, subnetName string, networkName string) string {
917+
subnetOptions := map[string]interface{}{
918+
"privateIpGoogleAccess": true,
919+
}
920+
return BootstrapSubnetWithOverrides(t, subnetName, networkName, subnetOptions)
921+
}
922+
915923
func BootstrapSubnet(t *testing.T, subnetName string, networkName string) string {
924+
return BootstrapSubnetWithOverrides(t, subnetName, networkName, make(map[string]interface{}))
925+
}
926+
927+
func BootstrapSubnetWithFirewallForDataprocBatches(t *testing.T, testId string, subnetName string) string {
928+
networkName := BootstrapSharedTestNetwork(t, testId)
929+
subnetworkName := BootstrapSubnetForDataprocBatches(t, subnetName, networkName)
930+
BootstrapFirewallForDataprocSharedNetwork(t, subnetName, networkName)
931+
return subnetworkName
932+
}
933+
934+
func BootstrapSubnetWithOverrides(t *testing.T, subnetName string, networkName string, subnetOptions map[string]interface{}) string {
916935
projectID := envvar.GetTestProjectFromEnv()
917936
region := envvar.GetTestRegionFromEnv()
918937

@@ -934,20 +953,24 @@ func BootstrapSubnet(t *testing.T, subnetName string, networkName string) string
934953
networkUrl := fmt.Sprintf("%sprojects/%s/global/networks/%s", config.ComputeBasePath, projectID, networkName)
935954
url := fmt.Sprintf("%sprojects/%s/regions/%s/subnetworks", config.ComputeBasePath, projectID, region)
936955

937-
subnetObj := map[string]interface{}{
956+
defaultSubnetObj := map[string]interface{}{
938957
"name": subnetName,
939958
"region ": region,
940959
"network": networkUrl,
941960
"ipCidrRange": "10.77.0.0/20",
942961
}
943962

963+
if len(subnetOptions) != 0 {
964+
maps.Copy(defaultSubnetObj, subnetOptions)
965+
}
966+
944967
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
945968
Config: config,
946969
Method: "POST",
947970
Project: projectID,
948971
RawURL: url,
949972
UserAgent: config.UserAgent,
950-
Body: subnetObj,
973+
Body: defaultSubnetObj,
951974
Timeout: 4 * time.Minute,
952975
})
953976

Diff for: google-beta/provider/provider_mmv1_resources.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
486486
}
487487

488488
// Resources
489-
// Generated resources: 529
489+
// Generated resources: 530
490490
// Generated IAM resources: 291
491-
// Total generated resources: 820
491+
// Total generated resources: 821
492492
var generatedResources = map[string]*schema.Resource{
493493
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
494494
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
@@ -864,6 +864,7 @@ var generatedResources = map[string]*schema.Resource{
864864
"google_dataproc_autoscaling_policy_iam_binding": tpgiamresource.ResourceIamBinding(dataproc.DataprocAutoscalingPolicyIamSchema, dataproc.DataprocAutoscalingPolicyIamUpdaterProducer, dataproc.DataprocAutoscalingPolicyIdParseFunc),
865865
"google_dataproc_autoscaling_policy_iam_member": tpgiamresource.ResourceIamMember(dataproc.DataprocAutoscalingPolicyIamSchema, dataproc.DataprocAutoscalingPolicyIamUpdaterProducer, dataproc.DataprocAutoscalingPolicyIdParseFunc),
866866
"google_dataproc_autoscaling_policy_iam_policy": tpgiamresource.ResourceIamPolicy(dataproc.DataprocAutoscalingPolicyIamSchema, dataproc.DataprocAutoscalingPolicyIamUpdaterProducer, dataproc.DataprocAutoscalingPolicyIdParseFunc),
867+
"google_dataproc_batch": dataproc.ResourceDataprocBatch(),
867868
"google_dataproc_metastore_federation": dataprocmetastore.ResourceDataprocMetastoreFederation(),
868869
"google_dataproc_metastore_federation_iam_binding": tpgiamresource.ResourceIamBinding(dataprocmetastore.DataprocMetastoreFederationIamSchema, dataprocmetastore.DataprocMetastoreFederationIamUpdaterProducer, dataprocmetastore.DataprocMetastoreFederationIdParseFunc),
869870
"google_dataproc_metastore_federation_iam_member": tpgiamresource.ResourceIamMember(dataprocmetastore.DataprocMetastoreFederationIamSchema, dataprocmetastore.DataprocMetastoreFederationIamUpdaterProducer, dataprocmetastore.DataprocMetastoreFederationIdParseFunc),

Diff for: google-beta/services/dataproc/dataproc_operation.go

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
// ----------------------------------------------------------------------------
5+
//
6+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
7+
//
8+
// ----------------------------------------------------------------------------
9+
//
10+
// This file is automatically generated by Magic Modules and manual
11+
// changes will be clobbered when the file is regenerated.
12+
//
13+
// Please read more about how to change this file in
14+
// .github/CONTRIBUTING.md.
15+
//
16+
// ----------------------------------------------------------------------------
17+
18+
package dataproc
19+
20+
import (
21+
"encoding/json"
22+
"errors"
23+
"fmt"
24+
"time"
25+
26+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
27+
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
28+
)
29+
30+
type DataprocOperationWaiter struct {
31+
Config *transport_tpg.Config
32+
UserAgent string
33+
Project string
34+
tpgresource.CommonOperationWaiter
35+
}
36+
37+
func (w *DataprocOperationWaiter) QueryOp() (interface{}, error) {
38+
if w == nil {
39+
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
40+
}
41+
// Returns the proper get.
42+
url := fmt.Sprintf("%s%s", w.Config.DataprocBasePath, w.CommonOperationWaiter.Op.Name)
43+
44+
return transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
45+
Config: w.Config,
46+
Method: "GET",
47+
Project: w.Project,
48+
RawURL: url,
49+
UserAgent: w.UserAgent,
50+
})
51+
}
52+
53+
func createDataprocWaiter(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string) (*DataprocOperationWaiter, error) {
54+
w := &DataprocOperationWaiter{
55+
Config: config,
56+
UserAgent: userAgent,
57+
Project: project,
58+
}
59+
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
60+
return nil, err
61+
}
62+
return w, nil
63+
}
64+
65+
// nolint: deadcode,unused
66+
func DataprocOperationWaitTimeWithResponse(config *transport_tpg.Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
67+
w, err := createDataprocWaiter(config, op, project, activity, userAgent)
68+
if err != nil {
69+
return err
70+
}
71+
if err := tpgresource.OperationWait(w, activity, timeout, config.PollInterval); err != nil {
72+
return err
73+
}
74+
rawResponse := []byte(w.CommonOperationWaiter.Op.Response)
75+
if len(rawResponse) == 0 {
76+
return errors.New("`resource` not set in operation response")
77+
}
78+
return json.Unmarshal(rawResponse, response)
79+
}
80+
81+
func DataprocOperationWaitTime(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
82+
if val, ok := op["name"]; !ok || val == "" {
83+
// This was a synchronous call - there is no operation to wait for.
84+
return nil
85+
}
86+
w, err := createDataprocWaiter(config, op, project, activity, userAgent)
87+
if err != nil {
88+
// If w is nil, the op was synchronous.
89+
return err
90+
}
91+
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
92+
}

Diff for: google-beta/services/dataproc/resource_dataproc_autoscaling_policy_sweeper.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func testSweepDataprocAutoscalingPolicy(region string) error {
6464
},
6565
}
6666

67-
listTemplate := strings.Split("https://dataproc.googleapis.com/v1beta2/projects/{{project}}/locations/{{location}}/autoscalingPolicies", "?")[0]
67+
listTemplate := strings.Split("https://dataproc.googleapis.com/v1/projects/{{project}}/locations/{{location}}/autoscalingPolicies", "?")[0]
6868
listUrl, err := tpgresource.ReplaceVars(d, config, listTemplate)
6969
if err != nil {
7070
log.Printf("[INFO][SWEEPER_LOG] error preparing sweeper list url: %s", err)
@@ -112,7 +112,7 @@ func testSweepDataprocAutoscalingPolicy(region string) error {
112112
continue
113113
}
114114

115-
deleteTemplate := "https://dataproc.googleapis.com/v1beta2/projects/{{project}}/locations/{{location}}/autoscalingPolicies/{{policy_id}}"
115+
deleteTemplate := "https://dataproc.googleapis.com/v1/projects/{{project}}/locations/{{location}}/autoscalingPolicies/{{policy_id}}"
116116
deleteUrl, err := tpgresource.ReplaceVars(d, config, deleteTemplate)
117117
if err != nil {
118118
log.Printf("[INFO][SWEEPER_LOG] error preparing delete url: %s", err)

0 commit comments

Comments
 (0)