Skip to content

Commit

Permalink
Set the async type default to OpAsync (#12730)
Browse files Browse the repository at this point in the history
  • Loading branch information
zli82016 authored Jan 10, 2025
1 parent 22008e5 commit 070ddb5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions mmv1/api/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions mmv1/templates/terraform/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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)
}

Expand Down Expand Up @@ -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}}
Expand Down

0 comments on commit 070ddb5

Please sign in to comment.