Skip to content
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
2 changes: 2 additions & 0 deletions docs/data-sources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ resource "local_file" "admin_kube_config" {
### Read-Only

- `admin_kube_config` (String) The admin kubeconfig file for accessing the cluster. This is computed automatically.
- `health` (String) The current health status of the cluster. This is computed automatically.
- `id` (String) The ID of this resource.
- `kube_config` (String) The kubeconfig file for accessing the cluster as a non-admin user. This is computed automatically.
- `state` (String) The current state of the cluster. This is computed automatically.
1 change: 1 addition & 0 deletions docs/resources/cluster_aks.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Refer to the [Import section](/docs#import) to learn more.
- `description` (String) The description of the cluster. Default value is empty string.
- `force_delete` (Boolean) If set to `true`, the cluster will be force deleted and user has to manually clean up the provisioned cloud resources.
- `force_delete_delay` (Number) Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.
- `graceful_creation_timeout` (Boolean) If set to `true`, cluster creation timeouts will be handled gracefully with warnings instead of errors, preserving the resource in state for subsequent applies to reconcile. Default is `false`.
- `host_config` (Block List) The host configuration for the cluster. (see [below for nested schema](#nestedblock--host_config))
- `namespaces` (Block List) The namespaces for the cluster. (see [below for nested schema](#nestedblock--namespaces))
- `os_patch_after` (String) The date and time after which to patch the cluster. Prefix the time value with the respective RFC. Ex: `RFC3339: 2006-01-02T15:04:05Z07:00`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Refer to the [Import section](/docs#import) to learn more.
- `description` (String) The description of the cluster. Default value is empty string.
- `force_delete` (Boolean) If set to `true`, the cluster will be force deleted and user has to manually clean up the provisioned cloud resources.
- `force_delete_delay` (Number) Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.
- `graceful_creation_timeout` (Boolean) If set to `true`, cluster creation timeouts will be handled gracefully with warnings instead of errors, preserving the resource in state for subsequent applies to reconcile. Default is `false`.
- `host_config` (Block List) The host configuration for the cluster. (see [below for nested schema](#nestedblock--host_config))
- `namespaces` (Block List) The namespaces for the cluster. (see [below for nested schema](#nestedblock--namespaces))
- `os_patch_after` (String) Date and time after which to patch cluster `RFC3339: 2006-01-02T15:04:05Z07:00`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Refer to the [Import section](/docs#import) to learn more.
- `description` (String) The description of the cluster. Default value is empty string.
- `force_delete` (Boolean) If set to `true`, the cluster will be force deleted and user has to manually clean up the provisioned cloud resources.
- `force_delete_delay` (Number) Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.
- `graceful_creation_timeout` (Boolean) If set to `true`, cluster creation timeouts will be handled gracefully with warnings instead of errors, preserving the resource in state for subsequent applies to reconcile. Default is `false`.
- `host_config` (Block List) The host configuration for the cluster. (see [below for nested schema](#nestedblock--host_config))
- `namespaces` (Block List) The namespaces for the cluster. (see [below for nested schema](#nestedblock--namespaces))
- `os_patch_after` (String) Date and time after which to patch cluster `RFC3339: 2006-01-02T15:04:05Z07:00`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_custom_cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Refer to the [Import section](/docs#import) to learn more.
- `description` (String) The description of the cluster. Default value is empty string.
- `force_delete` (Boolean) If set to `true`, the cluster will be force deleted and user has to manually clean up the provisioned cloud resources.
- `force_delete_delay` (Number) Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.
- `graceful_creation_timeout` (Boolean) If set to `true`, cluster creation timeouts will be handled gracefully with warnings instead of errors, preserving the resource in state for subsequent applies to reconcile. Default is `false`.
- `location_config` (Block List) (see [below for nested schema](#nestedblock--location_config))
- `namespaces` (Block List) The namespaces for the cluster. (see [below for nested schema](#nestedblock--namespaces))
- `os_patch_after` (String) Date and time after which to patch cluster `RFC3339: 2006-01-02T15:04:05Z07:00`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_edge_native.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Refer to the [Import section](/docs#import) to learn more.
- `description` (String) The description of the cluster. Default value is empty string.
- `force_delete` (Boolean) If set to `true`, the cluster will be force deleted and user has to manually clean up the provisioned cloud resources.
- `force_delete_delay` (Number) Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.
- `graceful_creation_timeout` (Boolean) If set to `true`, cluster creation timeouts will be handled gracefully with warnings instead of errors, preserving the resource in state for subsequent applies to reconcile. Default is `false`.
- `host_config` (Block List) The host configuration for the cluster. (see [below for nested schema](#nestedblock--host_config))
- `location_config` (Block List) (see [below for nested schema](#nestedblock--location_config))
- `namespaces` (Block List) The namespaces for the cluster. (see [below for nested schema](#nestedblock--namespaces))
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_edge_vsphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ description: |-
- `description` (String) The description of the cluster. Default value is empty string.
- `force_delete` (Boolean) If set to `true`, the cluster will be force deleted and user has to manually clean up the provisioned cloud resources.
- `force_delete_delay` (Number) Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.
- `graceful_creation_timeout` (Boolean) If set to `true`, cluster creation timeouts will be handled gracefully with warnings instead of errors, preserving the resource in state for subsequent applies to reconcile. Default is `false`.
- `host_config` (Block List) The host configuration for the cluster. (see [below for nested schema](#nestedblock--host_config))
- `location_config` (Block List) (see [below for nested schema](#nestedblock--location_config))
- `namespaces` (Block List) The namespaces for the cluster. (see [below for nested schema](#nestedblock--namespaces))
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_eks.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Refer to the [Import section](/docs#import) to learn more.
- `fargate_profile` (Block List) (see [below for nested schema](#nestedblock--fargate_profile))
- `force_delete` (Boolean) If set to `true`, the cluster will be force deleted and user has to manually clean up the provisioned cloud resources.
- `force_delete_delay` (Number) Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.
- `graceful_creation_timeout` (Boolean) If set to `true`, cluster creation timeouts will be handled gracefully with warnings instead of errors, preserving the resource in state for subsequent applies to reconcile. Default is `false`.
- `host_config` (Block List) The host configuration for the cluster. (see [below for nested schema](#nestedblock--host_config))
- `namespaces` (Block List) The namespaces for the cluster. (see [below for nested schema](#nestedblock--namespaces))
- `os_patch_after` (String) Date and time after which to patch cluster `RFC3339: 2006-01-02T15:04:05Z07:00`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Refer to the [Import section](/docs#import) to learn more.
- `description` (String) The description of the cluster. Default value is empty string.
- `force_delete` (Boolean) If set to `true`, the cluster will be force deleted and user has to manually clean up the provisioned cloud resources.
- `force_delete_delay` (Number) Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.
- `graceful_creation_timeout` (Boolean) If set to `true`, cluster creation timeouts will be handled gracefully with warnings instead of errors, preserving the resource in state for subsequent applies to reconcile. Default is `false`.
- `host_config` (Block List) The host configuration for the cluster. (see [below for nested schema](#nestedblock--host_config))
- `namespaces` (Block List) The namespaces for the cluster. (see [below for nested schema](#nestedblock--namespaces))
- `os_patch_after` (String) Date and time after which to patch cluster `RFC3339: 2006-01-02T15:04:05Z07:00`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_gke.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Refer to the [Import section](/docs#import) to learn more.
- `description` (String) The description of the cluster. Default value is empty string.
- `force_delete` (Boolean) If set to `true`, the cluster will be force deleted and user has to manually clean up the provisioned cloud resources.
- `force_delete_delay` (Number) Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.
- `graceful_creation_timeout` (Boolean) If set to `true`, cluster creation timeouts will be handled gracefully with warnings instead of errors, preserving the resource in state for subsequent applies to reconcile. Default is `false`.
- `host_config` (Block List) The host configuration for the cluster. (see [below for nested schema](#nestedblock--host_config))
- `namespaces` (Block List) The namespaces for the cluster. (see [below for nested schema](#nestedblock--namespaces))
- `os_patch_after` (String) Date and time after which to patch cluster `RFC3339: 2006-01-02T15:04:05Z07:00`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_maas.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Refer to the [Import section](/docs#import) to learn more.
- `description` (String) The description of the cluster. Default value is empty string.
- `force_delete` (Boolean) If set to `true`, the cluster will be force deleted and user has to manually clean up the provisioned cloud resources.
- `force_delete_delay` (Number) Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.
- `graceful_creation_timeout` (Boolean) If set to `true`, cluster creation timeouts will be handled gracefully with warnings instead of errors, preserving the resource in state for subsequent applies to reconcile. Default is `false`.
- `host_config` (Block List) The host configuration for the cluster. (see [below for nested schema](#nestedblock--host_config))
- `location_config` (Block List) (see [below for nested schema](#nestedblock--location_config))
- `namespaces` (Block List) The namespaces for the cluster. (see [below for nested schema](#nestedblock--namespaces))
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_openstack.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ resource "spectrocloud_cluster_openstack" "cluster" {
- `description` (String) The description of the cluster. Default value is empty string.
- `force_delete` (Boolean) If set to `true`, the cluster will be force deleted and user has to manually clean up the provisioned cloud resources.
- `force_delete_delay` (Number) Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.
- `graceful_creation_timeout` (Boolean) If set to `true`, cluster creation timeouts will be handled gracefully with warnings instead of errors, preserving the resource in state for subsequent applies to reconcile. Default is `false`.
- `host_config` (Block List) The host configuration for the cluster. (see [below for nested schema](#nestedblock--host_config))
- `location_config` (Block List) (see [below for nested schema](#nestedblock--location_config))
- `namespaces` (Block List) The namespaces for the cluster. (see [below for nested schema](#nestedblock--namespaces))
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_vsphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Refer to the [Import section](/docs#import) to learn more.
- `description` (String) The description of the cluster. Default value is empty string.
- `force_delete` (Boolean) If set to `true`, the cluster will be force deleted and user has to manually clean up the provisioned cloud resources.
- `force_delete_delay` (Number) Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.
- `graceful_creation_timeout` (Boolean) If set to `true`, cluster creation timeouts will be handled gracefully with warnings instead of errors, preserving the resource in state for subsequent applies to reconcile. Default is `false`.
- `host_config` (Block List) The host configuration for the cluster. (see [below for nested schema](#nestedblock--host_config))
- `location_config` (Block List) (see [below for nested schema](#nestedblock--location_config))
- `namespaces` (Block List) The namespaces for the cluster. (see [below for nested schema](#nestedblock--namespaces))
Expand Down
1 change: 1 addition & 0 deletions docs/resources/virtual_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ resource "spectrocloud_virtual_cluster" "cluster" {
- `description` (String) The description of the cluster. Default value is empty string.
- `force_delete` (Boolean) If set to `true`, the cluster will be force deleted and user has to manually clean up the provisioned cloud resources.
- `force_delete_delay` (Number) Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.
- `graceful_creation_timeout` (Boolean) If set to `true`, cluster creation timeouts will be handled gracefully with warnings instead of errors, preserving the resource in state for subsequent applies to reconcile. Default is `false`.
- `host_cluster_uid` (String)
- `namespaces` (Block List) The namespaces for the cluster. (see [below for nested schema](#nestedblock--namespaces))
- `os_patch_after` (String) The date and time after which to patch the cluster. Prefix the time value with the respective RFC. Ex: `RFC3339: 2006-01-02T15:04:05Z07:00`
Expand Down
46 changes: 46 additions & 0 deletions spectrocloud/cluster_common_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package spectrocloud

import (
"context"
"errors"
"fmt"
"log"
"time"

Expand Down Expand Up @@ -113,6 +115,13 @@ func resourceClusterReadyRefreshFunc(c *client.V1Client, id string) retry.StateR
func waitForClusterCreation(ctx context.Context, d *schema.ResourceData, uid string, diags diag.Diagnostics, c *client.V1Client, initial bool) (diag.Diagnostics, bool) {
d.SetId(uid)

// Debug logging
if gracefulCreationTimeout, ok := d.GetOk("graceful_creation_timeout"); ok {
log.Printf("waitForClusterCreation: graceful_creation_timeout = %v", gracefulCreationTimeout)
} else {
log.Printf("waitForClusterCreation: graceful_creation_timeout not set or false")
}

if initial { // only skip_completion when initally creating a cluster, do not skip when attach addon profile
if d.Get("skip_completion") != nil && d.Get("skip_completion").(bool) {
return diags, true
Expand Down Expand Up @@ -140,6 +149,43 @@ func waitForClusterCreation(ctx context.Context, d *schema.ResourceData, uid str
// Wait, catching any errors
_, err := stateConf.WaitForStateContext(ctx)
if err != nil {
// Check if graceful_creation_timeout is enabled and this is a timeout error
if gracefulCreationTimeout, ok := d.GetOk("graceful_creation_timeout"); ok && gracefulCreationTimeout.(bool) {
// Check if this is a timeout error
var timeoutErr *retry.TimeoutError
if errors.As(err, &timeoutErr) {
log.Printf("waitForClusterCreation (Running-Healthy phase): graceful timeout handling enabled, returning warning instead of error")

// Get current cluster state for warning message
cluster, stateErr := c.GetCluster(d.Id())
currentState := timeoutErr.LastState
if currentState == "" {
currentState = "Unknown"
}
if stateErr == nil && cluster != nil && cluster.Status != nil {
currentState = cluster.Status.State
if cluster.Status.State == "Running" {
if clusterSummary, _ := c.GetClusterOverview(d.Id()); clusterSummary != nil && clusterSummary.Status.Health != nil {
if clusterSummary.Status.Health.State != "" && clusterSummary.Status.Health.State != "Healthy" {
currentState += "-" + clusterSummary.Status.Health.State
}
}
}
}

// Return warning instead of error
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "Cluster creation timeout",
Detail: fmt.Sprintf(
"Cluster creation timed out after waiting for %v. Current cluster state is '%s'. "+
"The cluster may still be provisioning in the background and could eventually reach the 'Running-Healthy' state.",
d.Timeout(schema.TimeoutCreate), currentState),
})
return diags, false
}
}
// For non-timeout errors or when graceful_creation_timeout is disabled, still return the error
return diag.FromErr(err), true
}
return nil, false
Expand Down
25 changes: 25 additions & 0 deletions spectrocloud/data_source_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ func dataSourceCluster() *schema.Resource {
Default: false,
Description: "If set to true, the cluster will treated as a virtual cluster. Defaults to `false`.",
},
"state": {
Type: schema.TypeString,
Computed: true,
Description: "The current state of the cluster. This is computed automatically.",
},
"health": {
Type: schema.TypeString,
Computed: true,
Description: "The current health status of the cluster. This is computed automatically.",
},
},
}
}
Expand Down Expand Up @@ -73,6 +83,21 @@ func dataSourceClusterRead(_ context.Context, d *schema.ResourceData, m interfac
if err := d.Set("name", cluster.Metadata.Name); err != nil {
return diag.FromErr(err)
}

// Set cluster state
if cluster.Status != nil && cluster.Status.State != "" {
if err := d.Set("state", cluster.Status.State); err != nil {
return diag.FromErr(err)
}
}

// Set cluster health
clusterSummary, summaryErr := c.GetClusterOverview(cluster.Metadata.UID)
if summaryErr == nil && clusterSummary.Status.Health != nil && clusterSummary.Status.Health.State != "" {
if err := d.Set("health", clusterSummary.Status.Health.State); err != nil {
return diag.FromErr(err)
}
}
}
}
return diags
Expand Down
7 changes: 6 additions & 1 deletion spectrocloud/data_source_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package spectrocloud

import (
"context"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/assert"
"testing"
)

func TestDataSourceClusterRead(t *testing.T) {
Expand All @@ -23,6 +24,8 @@ func TestDataSourceClusterRead(t *testing.T) {
"virtual": {Type: schema.TypeBool, Optional: true},
"kube_config": {Type: schema.TypeString, Computed: true},
"admin_kube_config": {Type: schema.TypeString, Computed: true},
"state": {Type: schema.TypeString, Computed: true},
"health": {Type: schema.TypeString, Computed: true},
}, map[string]interface{}{
"name": "test-cluster",
"context": "some-context",
Expand All @@ -39,6 +42,8 @@ func TestDataSourceClusterRead(t *testing.T) {
"virtual": {Type: schema.TypeBool, Optional: true},
"kube_config": {Type: schema.TypeString, Computed: true},
"admin_kube_config": {Type: schema.TypeString, Computed: true},
"state": {Type: schema.TypeString, Computed: true},
"health": {Type: schema.TypeString, Computed: true},
}, map[string]interface{}{
"name": "test-cluster",
"context": "some-context",
Expand Down
9 changes: 9 additions & 0 deletions spectrocloud/resource_cluster_aks.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ func resourceClusterAks() *schema.Resource {
Description: "Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.",
ValidateDiagFunc: validation.ToDiagFunc(validation.IntAtLeast(20)),
},
"graceful_creation_timeout": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "If set to `true`, cluster creation timeouts will be handled gracefully with warnings instead of errors, preserving the resource in state for subsequent applies to reconcile. Default is `false`.",
},
},
}
}
Expand All @@ -331,6 +337,9 @@ func resourceClusterAksCreate(ctx context.Context, d *schema.ResourceData, m int
if isError {
return diagnostics
}
if len(diagnostics) > 0 {
diags = append(diags, diagnostics...)
}

resourceClusterAksRead(ctx, d, m)

Expand Down
Loading