Skip to content

Use user-provided timeouts for all resources #374

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

Merged
merged 3 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 17 additions & 9 deletions ovh/resource_cloud_project_kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ func resourceCloudProjectKube() *schema.Resource {
State: resourceCloudProjectKubeImportState,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(15 * time.Minute),
Update: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
Read: schema.DefaultTimeout(5 * time.Minute),
Default: schema.DefaultTimeout(10 * time.Minute),
},

Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -216,7 +224,7 @@ func resourceCloudProjectKubeCreate(d *schema.ResourceData, meta interface{}) er
}

log.Printf("[DEBUG] Waiting for kube %s to be READY", res.Id)
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, res.Id, []string{"INSTALLING"}, []string{"READY"})
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, res.Id, []string{"INSTALLING"}, []string{"READY"}, d.Timeout(schema.TimeoutCreate))
if err != nil {
return fmt.Errorf("timeout while waiting kube %s to be READY: %w", res.Id, err)
}
Expand Down Expand Up @@ -271,7 +279,7 @@ func resourceCloudProjectKubeDelete(d *schema.ResourceData, meta interface{}) er
}

log.Printf("[DEBUG] Waiting for kube %s to be DELETED", d.Id())
err = waitForCloudProjectKubeDeleted(config.OVHClient, serviceName, d.Id())
err = waitForCloudProjectKubeDeleted(d, config.OVHClient, serviceName, d.Id())
if err != nil {
return fmt.Errorf("timeout while waiting kube %s to be DELETED: %w", d.Id(), err)
}
Expand Down Expand Up @@ -299,7 +307,7 @@ func resourceCloudProjectKubeUpdate(d *schema.ResourceData, meta interface{}) er
}

log.Printf("[DEBUG] Waiting for kube %s to be READY", d.Id())
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, d.Id(), []string{"REDEPLOYING", "RESETTING"}, []string{"READY"})
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, d.Id(), []string{"REDEPLOYING", "RESETTING"}, []string{"READY"}, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return fmt.Errorf("timeout while waiting kube %s to be READY: %w", d.Id(), err)
}
Expand Down Expand Up @@ -351,7 +359,7 @@ func resourceCloudProjectKubeUpdate(d *schema.ResourceData, meta interface{}) er
}

log.Printf("[DEBUG] Waiting for kube %s to be READY", d.Id())
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, d.Id(), []string{"UPDATING", "REDEPLOYING", "RESETTING"}, []string{"READY"})
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, d.Id(), []string{"UPDATING", "REDEPLOYING", "RESETTING"}, []string{"READY"}, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return fmt.Errorf("timeout while waiting kube %s to be READY: %w", d.Id(), err)
}
Expand Down Expand Up @@ -405,7 +413,7 @@ func resourceCloudProjectKubeUpdate(d *schema.ResourceData, meta interface{}) er
}

log.Printf("[DEBUG] Waiting for kube %s to be READY", d.Id())
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, d.Id(), []string{"REDEPLOYING", "RESETTING"}, []string{"READY"})
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, d.Id(), []string{"REDEPLOYING", "RESETTING"}, []string{"READY"}, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return fmt.Errorf("timeout while waiting kube %s to be READY: %w", d.Id(), err)
}
Expand All @@ -422,7 +430,7 @@ func cloudProjectKubeExists(serviceName, id string, client *ovh.Client) error {
return client.Get(endpoint, res)
}

func waitForCloudProjectKubeReady(client *ovh.Client, serviceName, kubeId string, pending []string, target []string) error {
func waitForCloudProjectKubeReady(client *ovh.Client, serviceName, kubeId string, pending []string, target []string, timeout time.Duration) error {
stateConf := &resource.StateChangeConf{
Pending: pending,
Target: target,
Expand All @@ -436,7 +444,7 @@ func waitForCloudProjectKubeReady(client *ovh.Client, serviceName, kubeId string

return res, res.Status, nil
},
Timeout: 20 * time.Minute,
Timeout: timeout,
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
Expand All @@ -445,7 +453,7 @@ func waitForCloudProjectKubeReady(client *ovh.Client, serviceName, kubeId string
return err
}

func waitForCloudProjectKubeDeleted(client *ovh.Client, serviceName, kubeId string) error {
func waitForCloudProjectKubeDeleted(d *schema.ResourceData, client *ovh.Client, serviceName, kubeId string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{"DELETING"},
Target: []string{"DELETED"},
Expand All @@ -463,7 +471,7 @@ func waitForCloudProjectKubeDeleted(client *ovh.Client, serviceName, kubeId stri

return res, res.Status, nil
},
Timeout: 20 * time.Minute,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
Expand Down
17 changes: 13 additions & 4 deletions ovh/resource_cloud_project_kube_iprestrictions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"net/url"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

Expand All @@ -22,6 +23,14 @@ func resourceCloudProjectKubeIpRestrictions() *schema.Resource {
State: resourceCloudProjectKubeIpRestrictionsImportState,
},

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

Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -91,7 +100,7 @@ func resourceCloudProjectKubeIpRestrictionsCreateOrUpdate(d *schema.ResourceData

params := (&CloudProjectKubeIpRestrictionsCreateOrUpdateOpts{}).FromResource(d)

err := resourceCloudProjectKubeIpRestrictionsUpdate(config, serviceName, kubeId, params)
err := resourceCloudProjectKubeIpRestrictionsUpdate(d, config, serviceName, kubeId, params)
if err != nil {
return err
}
Expand All @@ -107,12 +116,12 @@ func resourceCloudProjectKubeIpRestrictionsDelete(d *schema.ResourceData, meta i
serviceName := d.Get("service_name").(string)
kubeId := d.Get("kube_id").(string)

return resourceCloudProjectKubeIpRestrictionsUpdate(config, serviceName, kubeId, &CloudProjectKubeIpRestrictionsCreateOrUpdateOpts{
return resourceCloudProjectKubeIpRestrictionsUpdate(d, config, serviceName, kubeId, &CloudProjectKubeIpRestrictionsCreateOrUpdateOpts{
Ips: []string{},
})
}

func resourceCloudProjectKubeIpRestrictionsUpdate(config *Config, serviceName string, kubeId string, params *CloudProjectKubeIpRestrictionsCreateOrUpdateOpts) error {
func resourceCloudProjectKubeIpRestrictionsUpdate(d *schema.ResourceData, config *Config, serviceName string, kubeId string, params *CloudProjectKubeIpRestrictionsCreateOrUpdateOpts) error {
endpoint := fmt.Sprintf("/cloud/project/%s/kube/%s/ipRestrictions", url.PathEscape(serviceName), url.PathEscape(kubeId))
res := make(CloudProjectKubeIpRestrictionsResponse, 0)

Expand All @@ -123,7 +132,7 @@ func resourceCloudProjectKubeIpRestrictionsUpdate(config *Config, serviceName st
}

log.Printf("[DEBUG] Waiting for kube %s to be READY", kubeId)
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, kubeId, []string{"REDEPLOYING", "RESETTING"}, []string{"READY"})
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, kubeId, []string{"REDEPLOYING", "RESETTING"}, []string{"READY"}, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return fmt.Errorf("timeout while waiting kube %s to be READY: %v", kubeId, err)
}
Expand Down
22 changes: 15 additions & 7 deletions ovh/resource_cloud_project_kube_nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ func resourceCloudProjectKubeNodePool() *schema.Resource {
State: resourceCloudProjectKubeNodePoolImportState,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(20 * time.Minute),
Update: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
Read: schema.DefaultTimeout(5 * time.Minute),
Default: schema.DefaultTimeout(10 * time.Minute),
},

Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -264,7 +272,7 @@ func resourceCloudProjectKubeNodePoolCreate(d *schema.ResourceData, meta interfa
}

log.Printf("[DEBUG] Waiting for nodepool %s to be READY", res.Id)
err = waitForCloudProjectKubeNodePoolReady(config.OVHClient, serviceName, kubeId, res.Id)
err = waitForCloudProjectKubeNodePoolReady(config.OVHClient, serviceName, kubeId, res.Id, d.Timeout(schema.TimeoutCreate))
if err != nil {
return fmt.Errorf("timeout while waiting nodepool %s to be READY: %w", res.Id, err)
}
Expand Down Expand Up @@ -318,7 +326,7 @@ func resourceCloudProjectKubeNodePoolUpdate(d *schema.ResourceData, meta interfa
}

log.Printf("[DEBUG] Waiting for nodepool %s to be READY", d.Id())
err = waitForCloudProjectKubeNodePoolReady(config.OVHClient, serviceName, kubeId, d.Id())
err = waitForCloudProjectKubeNodePoolReady(config.OVHClient, serviceName, kubeId, d.Id(), d.Timeout(schema.TimeoutUpdate))
if err != nil {
return fmt.Errorf("timeout while waiting nodepool %s to be READY: %w", d.Id(), err)
}
Expand All @@ -341,7 +349,7 @@ func resourceCloudProjectKubeNodePoolDelete(d *schema.ResourceData, meta interfa
}

log.Printf("[DEBUG] Waiting for nodepool %s to be DELETED", d.Id())
err = waitForCloudProjectKubeNodePoolDeleted(config.OVHClient, serviceName, kubeId, d.Id())
err = waitForCloudProjectKubeNodePoolDeleted(config.OVHClient, serviceName, kubeId, d.Id(), d.Timeout(schema.TimeoutDelete))
if err != nil {
return fmt.Errorf("timeout while waiting nodepool %s to be DELETED: %v", d.Id(), err)
}
Expand All @@ -359,7 +367,7 @@ func cloudProjectKubeNodePoolExists(serviceName, kubeId, id string, client *ovh.
return client.Get(endpoint, res)
}

func waitForCloudProjectKubeNodePoolReady(client *ovh.Client, serviceName, kubeId, id string) error {
func waitForCloudProjectKubeNodePoolReady(client *ovh.Client, serviceName, kubeId, id string, timeout time.Duration) error {
stateConf := &resource.StateChangeConf{
Pending: []string{"INSTALLING", "UPDATING", "REDEPLOYING", "RESIZING", "DOWNSCALING", "UPSCALING"},
Target: []string{"READY"},
Expand All @@ -373,7 +381,7 @@ func waitForCloudProjectKubeNodePoolReady(client *ovh.Client, serviceName, kubeI

return res, res.Status, nil
},
Timeout: 20 * time.Minute,
Timeout: timeout,
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
Expand All @@ -382,7 +390,7 @@ func waitForCloudProjectKubeNodePoolReady(client *ovh.Client, serviceName, kubeI
return err
}

func waitForCloudProjectKubeNodePoolDeleted(client *ovh.Client, serviceName, kubeId, id string) error {
func waitForCloudProjectKubeNodePoolDeleted(client *ovh.Client, serviceName, kubeId, id string, timeout time.Duration) error {
stateConf := &resource.StateChangeConf{
Pending: []string{"DELETING"},
Target: []string{"DELETED"},
Expand All @@ -400,7 +408,7 @@ func waitForCloudProjectKubeNodePoolDeleted(client *ovh.Client, serviceName, kub

return res, res.Status, nil
},
Timeout: 20 * time.Minute,
Timeout: timeout,
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
Expand Down
14 changes: 11 additions & 3 deletions ovh/resource_cloud_project_kube_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand All @@ -17,6 +18,13 @@ func resourceCloudProjectKubeOIDC() *schema.Resource {
Importer: &schema.ResourceImporter{
State: resourceCloudProjectKubeOIDCImportState,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Update: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
Read: schema.DefaultTimeout(5 * time.Minute),
Default: schema.DefaultTimeout(10 * time.Minute),
},

Schema: map[string]*schema.Schema{
"service_name": {
Expand Down Expand Up @@ -116,7 +124,7 @@ func resourceCloudProjectKubeOIDCCreate(d *schema.ResourceData, meta interface{}
d.SetId(serviceName + "/" + kubeID)

log.Printf("[DEBUG] Waiting for kube %s to be READY", kubeID)
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, kubeID, []string{"REDEPLOYING"}, []string{"READY"})
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, kubeID, []string{"REDEPLOYING"}, []string{"READY"}, d.Timeout(schema.TimeoutCreate))
if err != nil {
return fmt.Errorf("timeout while waiting kube %s to be READY: %w", kubeID, err)
}
Expand Down Expand Up @@ -168,7 +176,7 @@ func resourceCloudProjectKubeOIDCUpdate(d *schema.ResourceData, meta interface{}
}

log.Printf("[DEBUG] Waiting for kube %s to be READY", kubeID)
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, kubeID, []string{"REDEPLOYING"}, []string{"READY"})
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, kubeID, []string{"REDEPLOYING"}, []string{"READY"}, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return fmt.Errorf("timeout while waiting kube %s to be READY: %w", kubeID, err)
}
Expand All @@ -192,7 +200,7 @@ func resourceCloudProjectKubeOIDCDelete(d *schema.ResourceData, meta interface{}
}

log.Printf("[DEBUG] Waiting for kube %s to be READY", kubeID)
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, kubeID, []string{"REDEPLOYING"}, []string{"READY"})
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, kubeID, []string{"REDEPLOYING"}, []string{"READY"}, d.Timeout(schema.TimeoutDelete))
if err != nil {
return fmt.Errorf("timeout while waiting kube %s to be READY: %w", kubeID, err)
}
Expand Down
17 changes: 17 additions & 0 deletions website/docs/r/cloud_project_kube.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,23 @@ The following attributes are exported:
* `version` - See Argument Reference above.
* `customization` - See Argument Reference above.

## Timeouts

```hcl
resource "ovh_cloud_project_kube" "my_kube_cluster" {
# ...

timeouts {
create = "1h"
update = "45m"
delete = "50s"
}
}
```
* `create` - (Default 10m)
* `update` - (Default 10m)
* `delete` - (Default 10m)

## Import

OVHcloud Managed Kubernetes Service clusters can be imported using the `service_name` and the `id` of the cluster, separated by "/" E.g.,
Expand Down
17 changes: 17 additions & 0 deletions website/docs/r/cloud_project_kube_iprestrictions.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ The following arguments are supported:

No additional attributes than the ones provided are exported.

## Timeouts

```hcl
resource "ovh_cloud_project_kube_iprestrictions" "vrack_only" {
# ...

timeouts {
create = "1h"
update = "45m"
delete = "50s"
}
}
```
* `create` - (Default 10m)
* `update` - (Default 5m)
* `delete` - (Default 5m)

## Import

OVHcloud Managed Kubernetes Service cluster IP restrictions can be imported using the `service_name` and the `id` of the cluster, separated by "/" E.g.,
Expand Down
17 changes: 17 additions & 0 deletions website/docs/r/cloud_project_kube_nodepool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@ In addition, the following attributes are exported:
* `up_to_date_nodes` - Number of nodes with latest version installed in the pool
* `updated_at` - Last update date

## Timeouts

```hcl
resource "ovh_cloud_project_kube_nodepool" "pool" {
# ...

timeouts {
create = "1h"
update = "45m"
delete = "50s"
}
}
```
* `create` - (Default 20m)
* `update` - (Default 10m)
* `delete` - (Default 10m)

## Import

OVHcloud Managed Kubernetes Service cluster node pool can be imported using the `service_name`, the `id` of the cluster, and the `id` of the nodepool separated by "/" E.g.,
Expand Down
Loading