From 070ddb513c32cd6120a1b6af82670e5bc6d40888 Mon Sep 17 00:00:00 2001 From: Zhenhua Li Date: Fri, 10 Jan 2025 13:32:39 -0800 Subject: [PATCH] Set the async type default to OpAsync (#12730) --- mmv1/api/async.go | 4 ++++ mmv1/templates/terraform/resource.go.tmpl | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/mmv1/api/async.go b/mmv1/api/async.go index f947c62741b3..b6ea3c7291f6 100644 --- a/mmv1/api/async.go +++ b/mmv1/api/async.go @@ -58,6 +58,7 @@ func NewOperation() *Operation { return op } +// It is only used in openapi-generate func NewAsync() *Async { oa := &Async{ Actions: []string{"create", "delete", "update"}, @@ -150,6 +151,9 @@ func (a *Async) UnmarshalYAML(unmarshal func(any) error) error { return err } + if a.Type == "" { + a.Type = "OpAsync" + } if a.Type == "PollAsync" && a.TargetOccurrences == 0 { a.TargetOccurrences = 1 } diff --git a/mmv1/templates/terraform/resource.go.tmpl b/mmv1/templates/terraform/resource.go.tmpl index 73c2d18e467a..7751309e81d4 100644 --- a/mmv1/templates/terraform/resource.go.tmpl +++ b/mmv1/templates/terraform/resource.go.tmpl @@ -314,8 +314,8 @@ func resource{{ $.ResourceName -}}Create(d *schema.ResourceData, meta interface{ d.SetId(id) {{if and $.GetAsync ($.GetAsync.Allow "Create") -}} -{{if ($.GetAsync.IsA "OpAsync") -}} -{{if and $.GetAsync.Result.ResourceInsideResponse $.GetIdentity -}} +{{ if ($.GetAsync.IsA "OpAsync") -}} +{{ if and $.GetAsync.Result.ResourceInsideResponse $.GetIdentity -}} // Use the resource in the operation response to populate // identity fields and d.Id() before read var opRes map[string]interface{} @@ -330,7 +330,7 @@ func resource{{ $.ResourceName -}}Create(d *schema.ResourceData, meta interface{ // The resource didn't actually create d.SetId("") -{{ end -}} +{{ end -}} return fmt.Errorf("Error waiting to create {{ $.Name -}}: %s", err) } @@ -390,8 +390,8 @@ func resource{{ $.ResourceName -}}Create(d *schema.ResourceData, meta interface{ } {{ end -}} -{{ end -}} -{{ end -}} +{{ end -}}{{/*if ($.GetAsync.IsA "OpAsync")*/}} +{{ end -}}{{/*if and $.GetAsync ($.GetAsync.Allow "Create")*/}} {{if $.CustomCode.PostCreate -}} {{- $.CustomTemplate $.CustomCode.PostCreate false -}} {{- end}}