Skip to content

Commit

Permalink
Merge pull request #372 from vmware/bangerar/add-wait-time
Browse files Browse the repository at this point in the history
Add wait time for create/update operation to complete.
  • Loading branch information
ramya-bangera authored Jan 19, 2024
2 parents c483524 + e782184 commit ee9e28b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestAcceptanceForProvisionerDataSource(t *testing.T) {
},
},
})
t.Log("provisioner datasource acceptance test complete!")
}

func getTestProvisionerWithDataSourceConfigValue(prvName string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func TestAcceptanceForProvisionerResource(t *testing.T) {
},
},
})
t.Log("provisioner resource acceptance test complete!")
}

func checkResourceAttributes(provider *schema.Provider, resourceName, prvName string) resource.TestCheckFunc {
Expand Down
12 changes: 12 additions & 0 deletions internal/resources/provisioner/resource_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package provisioner
import (
"context"
"log"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -24,6 +25,11 @@ type (
contextMethodKey struct{}
)

// Adding a wait time of 10sec after the create/update operation as the operation takes some time to complete and
// there is no status field to rely on to check the completion of create/update operation.
// NOTE: If the error still persists then the timeout have to tuned in accordingly.
const waitTime = 10 * time.Second

func ResourceProvisioner() *schema.Resource {
return &schema.Resource{
Schema: provisionerSchema,
Expand Down Expand Up @@ -80,6 +86,9 @@ func resourceProvisionerCreate(ctx context.Context, d *schema.ResourceData, m in

d.SetId(provisionerResponse.Provisioner.Meta.UID)

log.Printf("Wait for %d seconds after the create the operation before fetching the state", waitTime)
time.Sleep(waitTime)

return append(diags, resourceProvisionerRead(context.WithValue(ctx, contextMethodKey{}, helper.CreateState), d, m)...)
}

Expand Down Expand Up @@ -118,6 +127,9 @@ func resourceProvisionerInPlaceUpdate(ctx context.Context, d *schema.ResourceDat
return diag.FromErr(errors.Wrapf(err, "Unable to update Tanzu Mission Control provisioner entry, name : %s", model.FullName.Name))
}

log.Printf("Wait for %d seconds after the update the operation before fetching the state", waitTime)
time.Sleep(waitTime)

return resourceProvisionerRead(ctx, d, m)
}

Expand Down

0 comments on commit ee9e28b

Please sign in to comment.