Skip to content

Commit 0ea90ef

Browse files
Move service operations to the the service packages (#7950) (#5699)
* Move compute_operation.go.erb to the compute package * Move appengine_operation.go to the appengine package * Move cloudfunctions_operation.go to the cloudfunctions package * Move composer_operation.go.erb to the composer package * Move container_attached_operation.go.erb to the containerattached package * Move container_operation.go.erb to the container package * Move dataproc_cluster_operation.go to the dataproc package * Move dataproc_job_operation.go to the dataproc package * Move datastream_operation.go to the datastream package * Fix import path * Add compute_operation.go.erb in the compute package to the converter * Fix common~copy * Move dialogflow_cx_operation.go to the service package * Move gkeonprem_operation.go to the service package * Move runadminv3_operation.go to the service package * Move service_networking_operation.go to the service package * Move serviceman_operation.go to the service package * Move sqladmin_operation.go to the service package * Move tags_location_operation.go to the service package * Move vertex_ai_operation.go to the service package * Move deployment_manager_operation.go to the service package * Add sql/sqladmin_operation.go to the converter copy list * Test 7982 * Skip build steps * Remove image test Signed-off-by: Modular Magician <[email protected]>
1 parent a0566e5 commit 0ea90ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1774
-1374
lines changed

.changelog/7950.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

google-beta/appengine_operation.go

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,20 @@
33
package google
44

55
import (
6-
"encoding/json"
7-
"fmt"
8-
"regexp"
96
"time"
107

11-
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
8+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/appengine"
129
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
13-
"github.com/hashicorp/terraform-provider-google-beta/google-beta/verify"
14-
15-
"google.golang.org/api/appengine/v1"
16-
)
17-
18-
var (
19-
appEngineOperationIdRegexp = regexp.MustCompile(fmt.Sprintf("apps/%s/operations/(.*)", verify.ProjectRegex))
2010
)
2111

22-
type AppEngineOperationWaiter struct {
23-
Service *appengine.APIService
24-
AppId string
25-
tpgresource.CommonOperationWaiter
26-
}
27-
28-
func (w *AppEngineOperationWaiter) QueryOp() (interface{}, error) {
29-
if w == nil {
30-
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
31-
}
32-
matches := appEngineOperationIdRegexp.FindStringSubmatch(w.Op.Name)
33-
if len(matches) != 2 {
34-
return nil, fmt.Errorf("Expected %d results of parsing operation name, got %d from %s", 2, len(matches), w.Op.Name)
35-
}
36-
return w.Service.Apps.Operations.Get(w.AppId, matches[1]).Do()
37-
}
38-
12+
// Deprecated: For backward compatibility AppEngineOperationWaitTimeWithResponse is still working,
13+
// but all new code should use AppEngineOperationWaitTimeWithResponse in the appengine package instead.
3914
func AppEngineOperationWaitTimeWithResponse(config *transport_tpg.Config, res interface{}, response *map[string]interface{}, appId, activity, userAgent string, timeout time.Duration) error {
40-
op := &appengine.Operation{}
41-
err := tpgresource.Convert(res, op)
42-
if err != nil {
43-
return err
44-
}
45-
46-
w := &AppEngineOperationWaiter{
47-
Service: config.NewAppEngineClient(userAgent),
48-
AppId: appId,
49-
}
50-
51-
if err := w.SetOp(op); err != nil {
52-
return err
53-
}
54-
if err := tpgresource.OperationWait(w, activity, timeout, config.PollInterval); err != nil {
55-
return err
56-
}
57-
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
15+
return appengine.AppEngineOperationWaitTimeWithResponse(config, res, response, appId, activity, userAgent, timeout)
5816
}
5917

18+
// Deprecated: For backward compatibility AppEngineOperationWaitTime is still working,
19+
// but all new code should use AppEngineOperationWaitTime in the appengine package instead.
6020
func AppEngineOperationWaitTime(config *transport_tpg.Config, res interface{}, appId, activity, userAgent string, timeout time.Duration) error {
61-
op := &appengine.Operation{}
62-
err := tpgresource.Convert(res, op)
63-
if err != nil {
64-
return err
65-
}
66-
67-
w := &AppEngineOperationWaiter{
68-
Service: config.NewAppEngineClient(userAgent),
69-
AppId: appId,
70-
}
71-
72-
if err := w.SetOp(op); err != nil {
73-
return err
74-
}
75-
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
21+
return appengine.AppEngineOperationWaitTime(config, res, appId, activity, userAgent, timeout)
7622
}

google-beta/bootstrap_test_utils.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
15+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/sql"
1516
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgiamresource"
1617
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
1718
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
@@ -652,7 +653,7 @@ func BootstrapSharedSQLInstanceBackupRun(t *testing.T) string {
652653
if err != nil {
653654
t.Fatalf("Error, failed to create instance %s: %s", bootstrapInstance.Name, err)
654655
}
655-
err = SqlAdminOperationWaitTime(config, op, project, "Create Instance", config.UserAgent, time.Duration(40)*time.Minute)
656+
err = sql.SqlAdminOperationWaitTime(config, op, project, "Create Instance", config.UserAgent, time.Duration(40)*time.Minute)
656657
if err != nil {
657658
t.Fatalf("Error, failed to create instance %s: %s", bootstrapInstance.Name, err)
658659
}
@@ -678,7 +679,7 @@ func BootstrapSharedSQLInstanceBackupRun(t *testing.T) string {
678679
if err != nil {
679680
t.Fatalf("Error, failed to create instance backup: %s", err)
680681
}
681-
err = SqlAdminOperationWaitTime(config, op, project, "Backup Instance", config.UserAgent, time.Duration(20)*time.Minute)
682+
err = sql.SqlAdminOperationWaitTime(config, op, project, "Backup Instance", config.UserAgent, time.Duration(20)*time.Minute)
682683
if err != nil {
683684
t.Fatalf("Error, failed to create instance backup: %s", err)
684685
}

google-beta/cloudfunctions_operation.go

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,21 @@
33
package google
44

55
import (
6-
"fmt"
76
"time"
87

9-
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
8+
tpgcloudfunctions "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/cloudfunctions"
109
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
1110
"google.golang.org/api/cloudfunctions/v1"
1211
)
1312

14-
type CloudFunctionsOperationWaiter struct {
15-
Service *cloudfunctions.Service
16-
tpgresource.CommonOperationWaiter
17-
}
18-
19-
func (w *CloudFunctionsOperationWaiter) QueryOp() (interface{}, error) {
20-
if w == nil {
21-
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
22-
}
23-
return w.Service.Operations.Get(w.Op.Name).Do()
24-
}
25-
13+
// Deprecated: For backward compatibility cloudFunctionsOperationWait is still working,
14+
// but all new code should use CloudFunctionsOperationWait in the tpgcloudfunctions package instead.
2615
func cloudFunctionsOperationWait(config *transport_tpg.Config, op *cloudfunctions.Operation, activity, userAgent string, timeout time.Duration) error {
27-
w := &CloudFunctionsOperationWaiter{
28-
Service: config.NewCloudFunctionsClient(userAgent),
29-
}
30-
if err := w.SetOp(op); err != nil {
31-
return err
32-
}
33-
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
16+
return tpgcloudfunctions.CloudFunctionsOperationWait(config, op, activity, userAgent, timeout)
3417
}
3518

19+
// Deprecated: For backward compatibility IsCloudFunctionsSourceCodeError is still working,
20+
// but all new code should use IsCloudFunctionsSourceCodeError in the tpgcloudfunctions package instead.
3621
func IsCloudFunctionsSourceCodeError(err error) (bool, string) {
37-
if operr, ok := err.(*tpgresource.CommonOpError); ok {
38-
if operr.Code == 3 && operr.Message == "Failed to retrieve function source code" {
39-
return true, fmt.Sprintf("Retry on Function failing to pull code from GCS")
40-
}
41-
}
42-
return false, ""
22+
return tpgcloudfunctions.IsCloudFunctionsSourceCodeError(err)
4323
}

google-beta/composer_operation.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,16 @@
33
package google
44

55
import (
6-
"fmt"
76
"time"
87

9-
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
8+
tpgcomposer "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/composer"
109
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
1110

1211
"google.golang.org/api/composer/v1beta1"
1312
)
1413

15-
type ComposerOperationWaiter struct {
16-
Service *composer.ProjectsLocationsService
17-
tpgresource.CommonOperationWaiter
18-
}
19-
20-
func (w *ComposerOperationWaiter) QueryOp() (interface{}, error) {
21-
if w == nil {
22-
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
23-
}
24-
return w.Service.Operations.Get(w.Op.Name).Do()
25-
}
26-
14+
// Deprecated: For backward compatibility ComposerOperationWaitTime is still working,
15+
// but all new code should use ComposerOperationWaitTime in the tpgcomposer package instead.
2716
func ComposerOperationWaitTime(config *transport_tpg.Config, op *composer.Operation, project, activity, userAgent string, timeout time.Duration) error {
28-
w := &ComposerOperationWaiter{
29-
Service: config.NewComposerClient(userAgent).Projects.Locations,
30-
}
31-
if err := w.SetOp(op); err != nil {
32-
return err
33-
}
34-
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
17+
return tpgcomposer.ComposerOperationWaitTime(config, op, project, activity, userAgent, timeout)
3518
}

0 commit comments

Comments
 (0)