Skip to content

Commit

Permalink
Moved check for op name out of create*Waiter (#4648)
Browse files Browse the repository at this point in the history
If there is a nested response but the operation is synchronous, there will not be a name - but we still need to run the rest of the logic in order to properly extract the response data.
  • Loading branch information
melinath authored Apr 2, 2021
1 parent 28b4a00 commit 2f5a0e1
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions mmv1/templates/terraform/operation.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ func (w *<%= product_name -%>OperationWaiter) QueryOp() (interface{}, error) {
}

func create<%= product_name %>Waiter(config *Config, op map[string]interface{}, <% if has_project -%> project, <% end -%> activity, userAgent string) (*<%=product_name%>OperationWaiter, error) {
if val, ok := op["name"]; !ok || val == "" {
// An operation could also be indicated with a "metadata" field.
if _, ok := op["metadata"]; !ok {
// This was a synchronous call - there is no operation to wait for.
return nil, nil
}
}
w := &<%= product_name -%>OperationWaiter{
Config: config,
UserAgent: userAgent,
Expand All @@ -57,8 +50,7 @@ func create<%= product_name %>Waiter(config *Config, op map[string]interface{},
// nolint: deadcode,unused
func <%= product_name.camelize(:lower) -%>OperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{},<% if has_project -%> project,<% end -%> activity, userAgent string, timeout time.Duration) error {
w, err := create<%= product_name %>Waiter(config, op, <% if has_project -%> project, <%end-%> activity, userAgent)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
if err != nil {
return err
}
if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil {
Expand All @@ -69,8 +61,12 @@ func <%= product_name.camelize(:lower) -%>OperationWaitTimeWithResponse(config *
<% end -%>

func <%= product_name.camelize(:lower) -%>OperationWaitTime(config *Config, op map[string]interface{}, <% if has_project -%> project,<% end -%> activity, userAgent string, timeout time.Duration) error {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil
}
w, err := create<%= product_name %>Waiter(config, op, <% if has_project -%> project, <%end-%> activity, userAgent)
if err != nil || w == nil {
if err != nil {
// If w is nil, the op was synchronous.
return err
}
Expand Down

0 comments on commit 2f5a0e1

Please sign in to comment.