Skip to content

Commit

Permalink
set default timeouts for org unit and chrome policy create/update req…
Browse files Browse the repository at this point in the history
…uests; expose timeouts resource param
  • Loading branch information
w0de committed Dec 12, 2023
1 parent 2fbb0ea commit 02368e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/provider/resource_chrome_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func resourceChromePolicy() *schema.Resource {
ReadContext: resourceChromePolicyRead,
DeleteContext: resourceChromePolicyDelete,

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"org_unit_id": {
Description: "The target org unit on which this policy is applied.",
Expand Down Expand Up @@ -135,7 +140,7 @@ func resourceChromePolicyCreate(ctx context.Context, d *schema.ResourceData, met
})
}

err := retryTimeDuration(ctx, time.Minute, func() error {
err := retryTimeDuration(ctx, d.Timeout(schema.TimeoutCreate), func() error {
_, retryErr := chromePoliciesService.Orgunits.BatchModify(fmt.Sprintf("customers/%s", client.Customer), &chromepolicy.GoogleChromePolicyV1BatchModifyOrgUnitPoliciesRequest{Requests: requests}).Do()
return retryErr
})
Expand Down Expand Up @@ -187,7 +192,7 @@ func resourceChromePolicyUpdate(ctx context.Context, d *schema.ResourceData, met
})
}

err := retryTimeDuration(ctx, time.Minute, func() error {
err := retryTimeDuration(ctx, d.Timeout(schema.TimeoutUpdate), func() error {
_, retryErr := chromePoliciesService.Orgunits.BatchInherit(fmt.Sprintf("customers/%s", client.Customer), &chromepolicy.GoogleChromePolicyV1BatchInheritOrgUnitPoliciesRequest{Requests: requests}).Do()
return retryErr
})
Expand Down
6 changes: 6 additions & 0 deletions internal/provider/resource_org_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
directory "google.golang.org/api/admin/directory/v1"
"google.golang.org/api/googleapi"
"log"
"time"
)

func resourceOrgUnit() *schema.Resource {
Expand All @@ -21,6 +22,11 @@ func resourceOrgUnit() *schema.Resource {
UpdateContext: resourceOrgUnitUpdate,
DeleteContext: resourceOrgUnitDelete,

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Update: schema.DefaultTimeout(10 * time.Minute),
},

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Expand Down

0 comments on commit 02368e7

Please sign in to comment.