Skip to content

Commit

Permalink
Retry for app user schema property read in after create and update (#426
Browse files Browse the repository at this point in the history
)

* Retry for app user schema property read in after create and update
  • Loading branch information
ashwini-desai authored Apr 14, 2021
1 parent 3c2fb50 commit 06eea0d
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions okta/resource_okta_app_user_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"errors"
"fmt"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -112,7 +114,20 @@ func resourceAppUserSchemaCreate(ctx context.Context, d *schema.ResourceData, m
return err
}
d.SetId(fmt.Sprintf("%s/%s", d.Get("app_id").(string), d.Get("index").(string)))
return resourceAppUserSchemaRead(ctx, d, m)
bOff := backoff.NewExponentialBackOff()
bOff.MaxElapsedTime = time.Second * 10
bOff.InitialInterval = time.Second
err = backoff.Retry(func() error {
err := resourceAppUserSchemaRead(ctx, d, m)
if err != nil {
return backoff.Permanent(fmt.Errorf("%s", err[0].Summary))
}
if d.Id() != "" {
return nil
}
return fmt.Errorf("Application User Schema property %s was not created in app %s", d.Get("index").(string), d.Get("app_id").(string))
}, bOff)
return diag.FromErr(err)
}

func resourceAppUserSchemaRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
Expand Down Expand Up @@ -147,7 +162,20 @@ func resourceAppUserSchemaUpdate(ctx context.Context, d *schema.ResourceData, m
if err := updateAppUserSubschema(ctx, d, m); err != nil {
return err
}
return resourceAppUserSchemaRead(ctx, d, m)
bOff := backoff.NewExponentialBackOff()
bOff.MaxElapsedTime = time.Second * 10
bOff.InitialInterval = time.Second
err = backoff.Retry(func() error {
err := resourceAppUserSchemaRead(ctx, d, m)
if err != nil {
return backoff.Permanent(fmt.Errorf("%s", err[0].Summary))
}
if d.Id() != "" {
return nil
}
return fmt.Errorf("Application User Schema property %s was not created in app %s", d.Get("index").(string), d.Get("app_id").(string))
}, bOff)
return diag.FromErr(err)
}

func resourceAppUserSchemaDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
Expand Down

0 comments on commit 06eea0d

Please sign in to comment.