Skip to content

Commit d00e55f

Browse files
authored
check for done operations before waiting on them (#1632)
1 parent e5e7f05 commit d00e55f

12 files changed

+91
-2
lines changed

google/appengine_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ func appEngineOperationWait(client *appengine.APIService, op *appengine.Operatio
5959
}
6060

6161
func appEngineOperationWaitTime(client *appengine.APIService, op *appengine.Operation, appId, activity string, timeoutMin int) error {
62+
if op.Done {
63+
if op.Error != nil {
64+
return AppEngineOperationError(*op.Error)
65+
}
66+
return nil
67+
}
68+
6269
w := &AppEngineOperationWaiter{
6370
Service: client,
6471
Op: op,

google/cloudfunctions_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ func cloudFunctionsOperationWait(client *cloudfunctions.Service,
4747

4848
func cloudFunctionsOperationWaitTime(client *cloudfunctions.Service, op *cloudfunctions.Operation,
4949
activity string, timeoutMin int) error {
50+
if op.Done {
51+
if op.Error != nil {
52+
return fmt.Errorf(op.Error.Message)
53+
}
54+
return nil
55+
}
56+
5057
w := &CloudFunctionsOperationWaiter{
5158
Service: client,
5259
Op: op,

google/compute_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ func computeOperationWait(client *compute.Service, op *compute.Operation, projec
6767
}
6868

6969
func computeOperationWaitTime(client *compute.Service, op *compute.Operation, project, activity string, timeoutMin int) error {
70+
if op.Status == "DONE" {
71+
if op.Error != nil {
72+
return ComputeOperationError(*op.Error)
73+
}
74+
return nil
75+
}
76+
7077
w := &ComputeOperationWaiter{
7178
Service: client,
7279
Op: op,

google/container_operation.go

+14
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ func (w *ContainerBetaOperationWaiter) RefreshFunc() resource.StateRefreshFunc {
8080
}
8181

8282
func containerOperationWait(config *Config, op *container.Operation, project, zone, activity string, timeoutMinutes, minTimeoutSeconds int) error {
83+
if op.Status == "DONE" {
84+
if op.StatusMessage != "" {
85+
return fmt.Errorf(op.StatusMessage)
86+
}
87+
return nil
88+
}
89+
8390
w := &ContainerOperationWaiter{
8491
Service: config.clientContainer,
8592
Op: op,
@@ -92,6 +99,13 @@ func containerOperationWait(config *Config, op *container.Operation, project, zo
9299
}
93100

94101
func containerBetaOperationWait(config *Config, op *containerBeta.Operation, project, location, activity string, timeoutMinutes, minTimeoutSeconds int) error {
102+
if op.Status == "DONE" {
103+
if op.StatusMessage != "" {
104+
return fmt.Errorf(op.StatusMessage)
105+
}
106+
return nil
107+
}
108+
95109
w := &ContainerBetaOperationWaiter{
96110
Service: config.clientContainerBeta,
97111
Op: op,

google/dataproc_cluster_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ func (w *DataprocClusterOperationWaiter) RefreshFunc() resource.StateRefreshFunc
3737
}
3838

3939
func dataprocClusterOperationWait(config *Config, op *dataproc.Operation, activity string, timeoutMinutes, minTimeoutSeconds int) error {
40+
if op.Done {
41+
if op.Error != nil {
42+
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
43+
}
44+
return nil
45+
}
46+
4047
w := &DataprocClusterOperationWaiter{
4148
Service: config.clientDataproc,
4249
Op: op,

google/dns_operation.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package google
22

33
import (
44
"fmt"
5-
"github.com/hashicorp/terraform/helper/resource"
6-
"google.golang.org/api/dns/v1beta2"
75
"log"
86
"time"
7+
8+
"github.com/hashicorp/terraform/helper/resource"
9+
"google.golang.org/api/dns/v1beta2"
910
)
1011

1112
type DnsOperationWaiter struct {
@@ -48,6 +49,10 @@ func dnsOperationWait(service *dns.Service, op *dns.Operation, project, activity
4849
}
4950

5051
func dnsOperationWaitTime(service *dns.Service, op *dns.Operation, project, activity string, timeoutMin int) error {
52+
if op.Status == "done" {
53+
return nil
54+
}
55+
5156
w := &DnsOperationWaiter{
5257
Service: service.ManagedZoneOperations,
5358
Op: op,

google/resourcemanager_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ func resourceManagerOperationWait(service *cloudresourcemanager.Service, op *clo
4242
}
4343

4444
func resourceManagerOperationWaitTime(service *cloudresourcemanager.Service, op *cloudresourcemanager.Operation, activity string, timeoutMin int) error {
45+
if op.Done {
46+
if op.Error != nil {
47+
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
48+
}
49+
return nil
50+
}
51+
4552
w := &ResourceManagerOperationWaiter{
4653
Service: service,
4754
Op: op,

google/serviceman_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ func serviceManagementOperationWait(config *Config, op *servicemanagement.Operat
4545
}
4646

4747
func serviceManagementOperationWaitTime(config *Config, op *servicemanagement.Operation, activity string, timeoutMin int) (googleapi.RawMessage, error) {
48+
if op.Done {
49+
if op.Error != nil {
50+
return nil, fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
51+
}
52+
return op.Response, nil
53+
}
54+
4855
w := &ServiceManagementOperationWaiter{
4956
Service: config.clientServiceMan,
5057
Op: op,

google/serviceusage_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ func serviceUsageOperationWait(config *Config, op *serviceusage.Operation, activ
4545
}
4646

4747
func serviceUsageOperationWaitTime(config *Config, op *serviceusage.Operation, activity string, timeoutMin int) (googleapi.RawMessage, error) {
48+
if op.Done {
49+
if op.Error != nil {
50+
return nil, fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
51+
}
52+
return op.Response, nil
53+
}
54+
4855
w := &serviceUsageOperationWaiter{
4956
Service: config.clientServiceUsage,
5057
Op: op,

google/spanner_database_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ func (w *SpannerDatabaseOperationWaiter) RefreshFunc() resource.StateRefreshFunc
3838
}
3939

4040
func spannerDatabaseOperationWait(config *Config, op *spanner.Operation, activity string, timeoutMin int) error {
41+
if op.Done {
42+
if op.Error != nil {
43+
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
44+
}
45+
return nil
46+
}
47+
4148
w := &SpannerDatabaseOperationWaiter{
4249
Service: config.clientSpanner,
4350
Op: op,

google/spanner_instance_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ func (w *SpannerInstanceOperationWaiter) RefreshFunc() resource.StateRefreshFunc
3838
}
3939

4040
func spannerInstanceOperationWait(config *Config, op *spanner.Operation, activity string, timeoutMin int) error {
41+
if op.Done {
42+
if op.Error != nil {
43+
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
44+
}
45+
return nil
46+
}
47+
4148
w := &SpannerInstanceOperationWaiter{
4249
Service: config.clientSpanner,
4350
Op: op,

google/sqladmin_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ func sqladminOperationWait(config *Config, op *sqladmin.Operation, project, acti
6161
}
6262

6363
func sqladminOperationWaitTime(config *Config, op *sqladmin.Operation, project, activity string, timeoutMinutes int) error {
64+
if op.Status == "DONE" {
65+
if op.Error != nil {
66+
return SqlAdminOperationError(*op.Error)
67+
}
68+
return nil
69+
}
70+
6471
w := &SqlAdminOperationWaiter{
6572
Service: config.clientSqlAdmin,
6673
Op: op,

0 commit comments

Comments
 (0)