@@ -4,14 +4,23 @@ import (
44 "context"
55 "fmt"
66 "net/http"
7+ "strings"
8+ "time"
79
810 "github.com/hashicorp/terraform-plugin-framework/path"
911 "github.com/hashicorp/terraform-plugin-framework/resource"
1012 "github.com/hashicorp/terraform-plugin-framework/resource/schema"
13+ "github.com/hashicorp/terraform-plugin-log/tflog"
14+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1115
1216 bloxoneclient "github.com/infobloxopen/bloxone-go-client/client"
1317)
1418
19+ const (
20+ // NetworkListOperationTimeout is the maximum amount of time to wait for eventual consistency
21+ NetworkListOperationTimeout = 2 * time .Minute
22+ )
23+
1524// Ensure provider defined types fully satisfy framework interfaces.
1625var _ resource.Resource = & NetworkListResource {}
1726var _ resource.ResourceWithImportState = & NetworkListResource {}
@@ -66,19 +75,29 @@ func (r *NetworkListResource) Create(ctx context.Context, req resource.CreateReq
6675 return
6776 }
6877
69- apiRes , _ , err := r .client .FWAPI .
70- NetworkListsAPI .
71- CreateNetworkList (ctx ).
72- Body (* data .Expand (ctx , & resp .Diagnostics )).
73- Execute ()
78+ err := retry .RetryContext (ctx , NetworkListOperationTimeout , func () * retry.RetryError {
79+ apiRes , _ , err := r .client .FWAPI .
80+ NetworkListsAPI .
81+ CreateNetworkList (ctx ).
82+ Body (* data .Expand (ctx , & resp .Diagnostics )).
83+ Execute ()
84+ if err != nil {
85+ if strings .Contains (err .Error (), "Internal Server Error" ) {
86+ tflog .Debug (ctx , "Waiting for related objects to be present, will retry" , map [string ]interface {}{"error" : err .Error ()})
87+ return retry .RetryableError (err )
88+ }
89+ resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to create NetworkList, got error: %s" , err ))
90+ return retry .NonRetryableError (err )
91+ }
92+ res := apiRes .GetResults ()
93+ data .Flatten (ctx , & res , & resp .Diagnostics )
94+
95+ return nil
96+ })
7497 if err != nil {
75- resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to create NetworkLists, got error: %s" , err ))
7698 return
7799 }
78100
79- res := apiRes .GetResults ()
80- data .Flatten (ctx , & res , & resp .Diagnostics )
81-
82101 // Save data into Terraform state
83102 resp .Diagnostics .Append (resp .State .Set (ctx , & data )... )
84103}
0 commit comments