Skip to content

Commit

Permalink
Move service operations to the the service packages (#7950) (#5699)
Browse files Browse the repository at this point in the history
* 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 <magic-modules@google.com>
  • Loading branch information
modular-magician authored May 31, 2023
1 parent a0566e5 commit 0ea90ef
Show file tree
Hide file tree
Showing 43 changed files with 1,774 additions and 1,374 deletions.
3 changes: 3 additions & 0 deletions .changelog/7950.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
68 changes: 7 additions & 61 deletions google-beta/appengine_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,20 @@
package google

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

"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/appengine"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/verify"

"google.golang.org/api/appengine/v1"
)

var (
appEngineOperationIdRegexp = regexp.MustCompile(fmt.Sprintf("apps/%s/operations/(.*)", verify.ProjectRegex))
)

type AppEngineOperationWaiter struct {
Service *appengine.APIService
AppId string
tpgresource.CommonOperationWaiter
}

func (w *AppEngineOperationWaiter) QueryOp() (interface{}, error) {
if w == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
matches := appEngineOperationIdRegexp.FindStringSubmatch(w.Op.Name)
if len(matches) != 2 {
return nil, fmt.Errorf("Expected %d results of parsing operation name, got %d from %s", 2, len(matches), w.Op.Name)
}
return w.Service.Apps.Operations.Get(w.AppId, matches[1]).Do()
}

// Deprecated: For backward compatibility AppEngineOperationWaitTimeWithResponse is still working,
// but all new code should use AppEngineOperationWaitTimeWithResponse in the appengine package instead.
func AppEngineOperationWaitTimeWithResponse(config *transport_tpg.Config, res interface{}, response *map[string]interface{}, appId, activity, userAgent string, timeout time.Duration) error {
op := &appengine.Operation{}
err := tpgresource.Convert(res, op)
if err != nil {
return err
}

w := &AppEngineOperationWaiter{
Service: config.NewAppEngineClient(userAgent),
AppId: appId,
}

if err := w.SetOp(op); err != nil {
return err
}
if err := tpgresource.OperationWait(w, activity, timeout, config.PollInterval); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
return appengine.AppEngineOperationWaitTimeWithResponse(config, res, response, appId, activity, userAgent, timeout)
}

// Deprecated: For backward compatibility AppEngineOperationWaitTime is still working,
// but all new code should use AppEngineOperationWaitTime in the appengine package instead.
func AppEngineOperationWaitTime(config *transport_tpg.Config, res interface{}, appId, activity, userAgent string, timeout time.Duration) error {
op := &appengine.Operation{}
err := tpgresource.Convert(res, op)
if err != nil {
return err
}

w := &AppEngineOperationWaiter{
Service: config.NewAppEngineClient(userAgent),
AppId: appId,
}

if err := w.SetOp(op); err != nil {
return err
}
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
return appengine.AppEngineOperationWaitTime(config, res, appId, activity, userAgent, timeout)
}
5 changes: 3 additions & 2 deletions google-beta/bootstrap_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/sql"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgiamresource"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
Expand Down Expand Up @@ -652,7 +653,7 @@ func BootstrapSharedSQLInstanceBackupRun(t *testing.T) string {
if err != nil {
t.Fatalf("Error, failed to create instance %s: %s", bootstrapInstance.Name, err)
}
err = SqlAdminOperationWaitTime(config, op, project, "Create Instance", config.UserAgent, time.Duration(40)*time.Minute)
err = sql.SqlAdminOperationWaitTime(config, op, project, "Create Instance", config.UserAgent, time.Duration(40)*time.Minute)
if err != nil {
t.Fatalf("Error, failed to create instance %s: %s", bootstrapInstance.Name, err)
}
Expand All @@ -678,7 +679,7 @@ func BootstrapSharedSQLInstanceBackupRun(t *testing.T) string {
if err != nil {
t.Fatalf("Error, failed to create instance backup: %s", err)
}
err = SqlAdminOperationWaitTime(config, op, project, "Backup Instance", config.UserAgent, time.Duration(20)*time.Minute)
err = sql.SqlAdminOperationWaitTime(config, op, project, "Backup Instance", config.UserAgent, time.Duration(20)*time.Minute)
if err != nil {
t.Fatalf("Error, failed to create instance backup: %s", err)
}
Expand Down
34 changes: 7 additions & 27 deletions google-beta/cloudfunctions_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,21 @@
package google

import (
"fmt"
"time"

"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
tpgcloudfunctions "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/cloudfunctions"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
"google.golang.org/api/cloudfunctions/v1"
)

type CloudFunctionsOperationWaiter struct {
Service *cloudfunctions.Service
tpgresource.CommonOperationWaiter
}

func (w *CloudFunctionsOperationWaiter) QueryOp() (interface{}, error) {
if w == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
return w.Service.Operations.Get(w.Op.Name).Do()
}

// Deprecated: For backward compatibility cloudFunctionsOperationWait is still working,
// but all new code should use CloudFunctionsOperationWait in the tpgcloudfunctions package instead.
func cloudFunctionsOperationWait(config *transport_tpg.Config, op *cloudfunctions.Operation, activity, userAgent string, timeout time.Duration) error {
w := &CloudFunctionsOperationWaiter{
Service: config.NewCloudFunctionsClient(userAgent),
}
if err := w.SetOp(op); err != nil {
return err
}
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
return tpgcloudfunctions.CloudFunctionsOperationWait(config, op, activity, userAgent, timeout)
}

// Deprecated: For backward compatibility IsCloudFunctionsSourceCodeError is still working,
// but all new code should use IsCloudFunctionsSourceCodeError in the tpgcloudfunctions package instead.
func IsCloudFunctionsSourceCodeError(err error) (bool, string) {
if operr, ok := err.(*tpgresource.CommonOpError); ok {
if operr.Code == 3 && operr.Message == "Failed to retrieve function source code" {
return true, fmt.Sprintf("Retry on Function failing to pull code from GCS")
}
}
return false, ""
return tpgcloudfunctions.IsCloudFunctionsSourceCodeError(err)
}
25 changes: 4 additions & 21 deletions google-beta/composer_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,16 @@
package google

import (
"fmt"
"time"

"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
tpgcomposer "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/composer"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"

"google.golang.org/api/composer/v1beta1"
)

type ComposerOperationWaiter struct {
Service *composer.ProjectsLocationsService
tpgresource.CommonOperationWaiter
}

func (w *ComposerOperationWaiter) QueryOp() (interface{}, error) {
if w == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
return w.Service.Operations.Get(w.Op.Name).Do()
}

// Deprecated: For backward compatibility ComposerOperationWaitTime is still working,
// but all new code should use ComposerOperationWaitTime in the tpgcomposer package instead.
func ComposerOperationWaitTime(config *transport_tpg.Config, op *composer.Operation, project, activity, userAgent string, timeout time.Duration) error {
w := &ComposerOperationWaiter{
Service: config.NewComposerClient(userAgent).Projects.Locations,
}
if err := w.SetOp(op); err != nil {
return err
}
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
return tpgcomposer.ComposerOperationWaitTime(config, op, project, activity, userAgent, timeout)
}
Loading

0 comments on commit 0ea90ef

Please sign in to comment.