Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix: Extend subscription timeout #429

Merged
merged 18 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/resources/rediscloud_active_active_subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/d
* `update` - (Defaults to 30 mins) Used when updating the subscription
* `delete` - (Defaults to 10 mins) Used when destroying the subscription

~> **Note:** If the subscription still times out. You may also need to set `REDISCLOUD_SUBSCRIPTION_TIMEOUT`.
For example, to increase timeouts to 60 minutes set `REDISCLOUD_SUBSCRIPTION_TIMEOUT=60`.

## Import

`rediscloud_active_active_subscription` can be imported using the ID of the subscription, e.g.
Expand Down
3 changes: 3 additions & 0 deletions docs/resources/rediscloud_subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/d
* `update` - (Defaults to 30 mins) Used when updating the subscription
* `delete` - (Defaults to 10 mins) Used when destroying the subscription

~> **Note:** If the subscription still times out. You may also need to set `REDISCLOUD_SUBSCRIPTION_TIMEOUT`.
For example, to increase timeouts to 60 minutes set `REDISCLOUD_SUBSCRIPTION_TIMEOUT=60`.

## Attribute reference

The `region` block has these attributes:
Expand Down
33 changes: 30 additions & 3 deletions provider/resource_rediscloud_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"log"
"os"
"regexp"
"strconv"
"time"
Expand Down Expand Up @@ -707,11 +708,17 @@ func createDatabase(dbName string, idx *int, modules []*subscriptions.CreateModu
}

func waitForSubscriptionToBeActive(ctx context.Context, id int, api *apiClient) error {
// TODO: Set timeout based on the timeouts block, instead of an env var.
timeout, err := getSubscriptionTimeout()
if err != nil {
return err
}

wait := &retry.StateChangeConf{
Delay: 10 * time.Second,
Pending: []string{subscriptions.SubscriptionStatusPending},
Target: []string{subscriptions.SubscriptionStatusActive},
Timeout: 20 * time.Minute,
Timeout: timeout,

Refresh: func() (result interface{}, state string, err error) {
log.Printf("[DEBUG] Waiting for subscription %d to be active", id)
Expand All @@ -732,11 +739,16 @@ func waitForSubscriptionToBeActive(ctx context.Context, id int, api *apiClient)
}

func waitForSubscriptionToBeDeleted(ctx context.Context, id int, api *apiClient) error {
timeout, err := getSubscriptionTimeout()
if err != nil {
return err
}

wait := &retry.StateChangeConf{
Delay: 10 * time.Second,
Pending: []string{subscriptions.SubscriptionStatusDeleting},
Target: []string{"deleted"},
Timeout: 10 * time.Minute,
Timeout: timeout,

Refresh: func() (result interface{}, state string, err error) {
log.Printf("[DEBUG] Waiting for subscription %d to be deleted", id)
Expand Down Expand Up @@ -774,7 +786,7 @@ func waitForDatabaseToBeActive(ctx context.Context, subId, id int, api *apiClien
databases.StatusProxyPolicyChangeDraft,
},
Target: []string{databases.StatusActive},
Timeout: 10 * time.Minute,
Timeout: 30 * time.Minute,

Refresh: func() (result interface{}, state string, err error) {
log.Printf("[DEBUG] Waiting for database %d to be active", id)
Expand Down Expand Up @@ -955,3 +967,18 @@ func readPaymentMethodID(d *schema.ResourceData) (*int, error) {
}
return nil, nil
}

func getSubscriptionTimeout() (time.Duration, error) {
// Allow configuring the subscription timeout via an environment variable.
timeout := 30
val, _ := os.LookupEnv("REDISCLOUD_SUBSCRIPTION_TIMEOUT")
if len(val) != 0 {
envTimeout, err := strconv.Atoi(val)
if err != nil {
return time.Duration(0), err
}
timeout = envTimeout
}
timeoutDuration := time.Duration(timeout) * time.Minute
return timeoutDuration, nil
}
Loading