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

bugfix 254 - timeout on resource level #333

Merged
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
14 changes: 9 additions & 5 deletions nutanix/resource_nutanix_access_control_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -23,6 +24,11 @@ func resourceNutanixAccessControlPolicy() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
Update: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
Delete: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
},
Schema: map[string]*schema.Schema{
"api_version": {
Type: schema.TypeString,
Expand Down Expand Up @@ -276,7 +282,6 @@ func resourceNutanixAccessControlPolicy() *schema.Resource {

func resourceNutanixAccessControlPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*Client).API

request := &v3.AccessControlPolicy{}
spec := &v3.AccessControlPolicySpec{}
metadata := &v3.Metadata{}
Expand Down Expand Up @@ -319,7 +324,7 @@ func resourceNutanixAccessControlPolicyCreate(ctx context.Context, d *schema.Res
Pending: []string{"QUEUED", "RUNNING", "PENDING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: subnetTimeout,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: subnetDelay,
MinTimeout: subnetMinTimeout,
}
Expand Down Expand Up @@ -416,7 +421,6 @@ func resourceNutanixAccessControlPolicyUpdate(ctx context.Context, d *schema.Res
metadata := &v3.Metadata{}
res := &v3.AccessControlPolicyResources{}
spec := &v3.AccessControlPolicySpec{}

id := d.Id()
response, err := conn.V3.GetAccessControlPolicy(id)

Expand Down Expand Up @@ -484,7 +488,7 @@ func resourceNutanixAccessControlPolicyUpdate(ctx context.Context, d *schema.Res
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: subnetTimeout,
Timeout: d.Timeout(schema.TimeoutUpdate),
Delay: subnetDelay,
MinTimeout: subnetMinTimeout,
}
Expand Down Expand Up @@ -512,7 +516,7 @@ func resourceNutanixAccessControlPolicyDelete(ctx context.Context, d *schema.Res
Pending: []string{"QUEUED", "RUNNING", "DELETED_PENDING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, cast.ToString(resp.Status.ExecutionContext.TaskUUID)),
Timeout: subnetTimeout,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: subnetDelay,
MinTimeout: subnetMinTimeout,
}
Expand Down
27 changes: 8 additions & 19 deletions nutanix/resource_nutanix_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func resourceNutanixImage() *schema.Resource {
Version: 0,
},
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
Update: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
Delete: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
},
Schema: map[string]*schema.Schema{
"api_version": {
Type: schema.TypeString,
Expand Down Expand Up @@ -159,11 +164,6 @@ func resourceNutanixImageCreate(ctx context.Context, d *schema.ResourceData, met
log.Printf("[DEBUG] Creating Image: %s", d.Get("name").(string))
client := meta.(*Client)
conn := client.API
timeout := client.WaitTimeout

if client.WaitTimeout == 0 {
timeout = 10
}

request := &v3.ImageIntentInput{}
spec := &v3.Image{}
Expand Down Expand Up @@ -221,7 +221,7 @@ func resourceNutanixImageCreate(ctx context.Context, d *schema.ResourceData, met
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: time.Duration(timeout) * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: imageDelay,
MinTimeout: imageMinTimeout,
}
Expand Down Expand Up @@ -345,11 +345,6 @@ func resourceNutanixImageRead(ctx context.Context, d *schema.ResourceData, meta
func resourceNutanixImageUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*Client)
conn := client.API
timeout := client.WaitTimeout

if client.WaitTimeout == 0 {
timeout = 10
}

// get state
request := &v3.ImageIntentInput{}
Expand Down Expand Up @@ -422,7 +417,7 @@ func resourceNutanixImageUpdate(ctx context.Context, d *schema.ResourceData, met
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: time.Duration(timeout) * time.Minute,
Timeout: d.Timeout(schema.TimeoutUpdate),
Delay: imageDelay,
MinTimeout: imageMinTimeout,
}
Expand All @@ -446,12 +441,6 @@ func resourceNutanixImageDelete(ctx context.Context, d *schema.ResourceData, met

client := meta.(*Client)
conn := client.API
timeout := client.WaitTimeout

if client.WaitTimeout == 0 {
timeout = 10
}

UUID := d.Id()

resp, err := conn.V3.DeleteImage(UUID)
Expand All @@ -469,7 +458,7 @@ func resourceNutanixImageDelete(ctx context.Context, d *schema.ResourceData, met
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: time.Duration(timeout) * time.Minute,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: imageDelay,
MinTimeout: imageMinTimeout,
}
Expand Down
14 changes: 7 additions & 7 deletions nutanix/resource_nutanix_karbon_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestAccNutanixKarbonCluster_basic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"version", "master_node_pool", "worker_node_pool", "storage_class_config", "wait_timeout_minutes"}, //Wil be fixed on future API versions
ImportStateVerifyIgnore: []string{"version", "master_node_pool", "worker_node_pool", "storage_class_config"}, //Wil be fixed on future API versions
},
},
})
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestAccNutanixKarbonCluster_scaleDown(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"version", "master_node_pool", "worker_node_pool", "storage_class_config", "wait_timeout_minutes"}, //Wil be fixed on future API versions
ImportStateVerifyIgnore: []string{"version", "master_node_pool", "worker_node_pool", "storage_class_config"}, //Wil be fixed on future API versions
},
},
})
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestAccNutanixKarbonCluster_updateCNI(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"version", "master_node_pool", "worker_node_pool", "storage_class_config", "wait_timeout_minutes"}, //Wil be fixed on future API versions
ImportStateVerifyIgnore: []string{"version", "master_node_pool", "worker_node_pool", "storage_class_config"}, //Wil be fixed on future API versions
},
},
})
Expand Down Expand Up @@ -196,17 +196,17 @@ func testAccNutanixKarbonClusterConfig(subnetName string, r int, containter stri
cni = "%s"
master_vip = ""
}

data "nutanix_clusters" "clusters" {}

data "nutanix_subnet" "karbon_subnet" {
subnet_name = "%s"
}

resource "nutanix_karbon_cluster" "cluster" {
name = "test-karbon-%d"
version = "1.16.13-0"

dynamic "active_passive_config" {
for_each = local.deployment_type == "active-passive" ? [1] : []
content {
Expand All @@ -227,7 +227,7 @@ func testAccNutanixKarbonClusterConfig(subnetName string, r int, containter stri
}
}
}

storage_class_config {
reclaim_policy = "Delete"
volumes_config {
Expand Down
17 changes: 13 additions & 4 deletions nutanix/resource_nutanix_network_security_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
)

var (
netTimeout = 10 * time.Minute
netDelay = 10 * time.Second
netMinTimeout = 3 * time.Second
)
Expand All @@ -32,6 +31,11 @@ func resourceNutanixNetworkSecurityRule() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
Update: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
Delete: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
},
SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Expand Down Expand Up @@ -683,7 +687,7 @@ func resourceNutanixNetworkSecurityRuleCreate(ctx context.Context, d *schema.Res
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: netTimeout,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: netDelay,
MinTimeout: netMinTimeout,
}
Expand Down Expand Up @@ -957,7 +961,7 @@ func resourceNutanixNetworkSecurityRuleUpdate(ctx context.Context, d *schema.Res
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: netTimeout,
Timeout: d.Timeout(schema.TimeoutUpdate),
Delay: netDelay,
MinTimeout: netMinTimeout,
}
Expand Down Expand Up @@ -988,7 +992,7 @@ func resourceNutanixNetworkSecurityRuleDelete(ctx context.Context, d *schema.Res
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: netTimeout,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: netDelay,
MinTimeout: netMinTimeout,
}
Expand Down Expand Up @@ -1508,6 +1512,11 @@ func resourceSecurityRuleInstanceStateUpgradeV0(ctx context.Context, is map[stri

func resourceNutanixSecurityRuleInstanceResourceV0() *schema.Resource {
return &schema.Resource{
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
Update: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
Delete: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
},
Schema: map[string]*schema.Schema{
"api_version": {
Type: schema.TypeString,
Expand Down
12 changes: 9 additions & 3 deletions nutanix/resource_nutanix_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -23,6 +24,11 @@ func resourceNutanixProject() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
Update: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
Delete: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -284,7 +290,7 @@ func resourceNutanixProjectCreate(ctx context.Context, d *schema.ResourceData, m
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: vmTimeout,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: vmDelay,
MinTimeout: vmMinTimeout,
}
Expand Down Expand Up @@ -432,7 +438,7 @@ func resourceNutanixProjectUpdate(ctx context.Context, d *schema.ResourceData, m
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: vmTimeout,
Timeout: d.Timeout(schema.TimeoutUpdate),
Delay: vmDelay,
MinTimeout: vmMinTimeout,
}
Expand All @@ -456,7 +462,7 @@ func resourceNutanixProjectDelete(ctx context.Context, d *schema.ResourceData, m
Pending: []string{"QUEUED", "RUNNING", "DELETED_PENDING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, cast.ToString(resp.Status.ExecutionContext.TaskUUID)),
Timeout: subnetTimeout,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: subnetDelay,
MinTimeout: subnetMinTimeout,
}
Expand Down
12 changes: 9 additions & 3 deletions nutanix/resource_nutanix_protection_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand All @@ -26,6 +27,11 @@ func resourceNutanixProtectionRule() *schema.Resource {
StateContext: schema.ImportStatePassthroughContext,
},
SchemaVersion: 1,
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
Update: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
Delete: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
},
Schema: map[string]*schema.Schema{
"api_version": {
Type: schema.TypeString,
Expand Down Expand Up @@ -317,7 +323,7 @@ func resourceNutanixProtectionRuleCreate(ctx context.Context, d *schema.Resource
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: subnetTimeout,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: subnetDelay,
MinTimeout: subnetMinTimeout,
}
Expand Down Expand Up @@ -461,7 +467,7 @@ func resourceNutanixProtectionRuleUpdate(ctx context.Context, d *schema.Resource
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: subnetTimeout,
Timeout: d.Timeout(schema.TimeoutUpdate),
Delay: subnetDelay,
MinTimeout: subnetMinTimeout,
}
Expand Down Expand Up @@ -490,7 +496,7 @@ func resourceNutanixProtectionRuleDelete(ctx context.Context, d *schema.Resource
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: subnetTimeout,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: subnetDelay,
MinTimeout: subnetMinTimeout,
}
Expand Down
12 changes: 9 additions & 3 deletions nutanix/resource_nutanix_recovery_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -24,6 +25,11 @@ func resourceNutanixRecoveryPlan() *schema.Resource {
StateContext: schema.ImportStatePassthroughContext,
},
SchemaVersion: 1,
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
Update: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
Delete: schema.DefaultTimeout(DEFAULTWAITTIMEOUT * time.Minute),
},
Schema: map[string]*schema.Schema{
"api_version": {
Type: schema.TypeString,
Expand Down Expand Up @@ -665,7 +671,7 @@ func resourceNutanixRecoveryPlanCreate(ctx context.Context, d *schema.ResourceDa
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: subnetTimeout,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: subnetDelay,
MinTimeout: subnetMinTimeout,
}
Expand Down Expand Up @@ -797,7 +803,7 @@ func resourceNutanixRecoveryPlanUpdate(ctx context.Context, d *schema.ResourceDa
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: subnetTimeout,
Timeout: d.Timeout(schema.TimeoutUpdate),
Delay: subnetDelay,
MinTimeout: subnetMinTimeout,
}
Expand Down Expand Up @@ -826,7 +832,7 @@ func resourceNutanixRecoveryPlanDelete(ctx context.Context, d *schema.ResourceDa
Pending: []string{"QUEUED", "RUNNING"},
Target: []string{"SUCCEEDED"},
Refresh: taskStateRefreshFunc(conn, taskUUID),
Timeout: subnetTimeout,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: subnetDelay,
MinTimeout: subnetMinTimeout,
}
Expand Down
Loading