Skip to content

Commit 7a91ac0

Browse files
modular-magicianrileykarson
authored andcommitted
[Terraform] Autogen resource manager operations (#3071)
<!-- This change is generated by MagicModules. --> /cc @rambleraptor
1 parent 81d23bd commit 7a91ac0

4 files changed

+67
-51
lines changed

google/resource_google_folder.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ func resourceGoogleFolderCreate(d *schema.ResourceData, meta interface{}) error
6363
return fmt.Errorf("Error creating folder '%s' in '%s': %s", displayName, parent, err)
6464
}
6565

66-
err = resourceManagerV2Beta1OperationWait(config.clientResourceManager, op, "creating folder")
66+
opV1 := make(map[string]interface{})
67+
waitErr := Convert(op, opV1)
68+
if waitErr != nil {
69+
return waitErr
70+
}
71+
72+
err = resourceManagerOperationWaitTime(config, opV1, "", "creating folder", int(d.Timeout(schema.TimeoutCreate).Minutes()))
6773

6874
if err != nil {
6975
return fmt.Errorf("Error creating folder '%s' in '%s': %s", displayName, parent, err)
@@ -132,7 +138,13 @@ func resourceGoogleFolderUpdate(d *schema.ResourceData, meta interface{}) error
132138
return fmt.Errorf("Error moving folder '%s' to '%s': %s", displayName, newParent, err)
133139
}
134140

135-
err = resourceManagerV2Beta1OperationWait(config.clientResourceManager, op, "move folder")
141+
opV1 := make(map[string]interface{})
142+
waitErr := Convert(op, opV1)
143+
if waitErr != nil {
144+
return waitErr
145+
}
146+
147+
err = resourceManagerOperationWaitTime(config, opV1, "", "move folder", int(d.Timeout(schema.TimeoutCreate).Minutes()))
136148
if err != nil {
137149
return fmt.Errorf("Error moving folder '%s' to '%s': %s", displayName, newParent, err)
138150
}

google/resource_google_project.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,13 @@ func resourceGoogleProjectCreate(d *schema.ResourceData, meta interface{}) error
227227
d.SetId(pid)
228228

229229
// Wait for the operation to complete
230-
waitErr := resourceManagerOperationWait(config.clientResourceManager, op, "project to create")
230+
opV1 := make(map[string]interface{})
231+
waitErr := Convert(op, opV1)
232+
if waitErr != nil {
233+
return waitErr
234+
}
235+
236+
waitErr = resourceManagerOperationWaitTime(config, opV1, "", "creating folder", int(d.Timeout(schema.TimeoutCreate).Minutes()))
231237
if waitErr != nil {
232238
// The resource wasn't actually created
233239
d.SetId("")

google/resource_manager_operation.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
package google
15+
16+
import (
17+
"fmt"
18+
)
19+
20+
type ResourceManagerOperationWaiter struct {
21+
Config *Config
22+
CommonOperationWaiter
23+
}
24+
25+
func (w *ResourceManagerOperationWaiter) QueryOp() (interface{}, error) {
26+
if w == nil {
27+
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
28+
}
29+
// Returns the proper get.
30+
url := fmt.Sprintf("https://cloudresourcemanager.googleapis.com/v1/%s", w.CommonOperationWaiter.Op.Name)
31+
return sendRequest(w.Config, "GET", url, nil)
32+
}
33+
34+
func resourceManagerOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
35+
if val, ok := op["name"]; !ok || val == "" {
36+
// This was a synchronous call - there is no operation to wait for.
37+
return nil
38+
}
39+
w := &ResourceManagerOperationWaiter{
40+
Config: config,
41+
}
42+
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
43+
return err
44+
}
45+
return OperationWait(w, activity, timeoutMinutes)
46+
}

google/resourcemanager_operation.go

-48
This file was deleted.

0 commit comments

Comments
 (0)