diff --git a/docs/data-sources/env_aws.md b/docs/data-sources/env_aws.md index 8edb112..c9e8899 100644 --- a/docs/data-sources/env_aws.md +++ b/docs/data-sources/env_aws.md @@ -30,7 +30,7 @@ data "altinitycloud_env_aws" "current" { ### Optional -- `cloud_connect` (Boolean) `true` indicates that cloud resources are to be managed via altinity/cloud-connect and `false` means direct management (default `true`). **[IMMUTABLE]** +- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts)) ### Read-Only @@ -40,6 +40,7 @@ data "altinitycloud_env_aws" "current" { Examples: - "10.136.0.0/21" - "172.20.0.0/21" +- `cloud_connect` (Boolean) `true` indicates that cloud resources are to be managed via altinity/cloud-connect and `false` means direct management (default `true`). **[IMMUTABLE]** - `custom_domain` (String) Custom domain. Examples: @@ -82,6 +83,14 @@ data "altinitycloud_env_aws" "current" { - ["us-east-1a", "us-east-1b"] - ["sa-east-1c", "sa-east-1d"] + +### Nested Schema for `timeouts` + +Optional: + +- `delete` (String) Adjust timeout for deleting the environment. + + ### Nested Schema for `endpoints` diff --git a/docs/data-sources/env_azure.md b/docs/data-sources/env_azure.md index 91e5c3d..36e5993 100644 --- a/docs/data-sources/env_azure.md +++ b/docs/data-sources/env_azure.md @@ -28,6 +28,10 @@ data "altinitycloud_env_azure" "current" { Examples: - "acme-staging" (where "acme" is your account name) +### Optional + +- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts)) + ### Read-Only - `cidr` (String) VPC CIDR block from the private IPv4 address ranges as specified in RFC 1918 (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16). At least /21 required. **[IMMUTABLE]** @@ -77,6 +81,14 @@ data "altinitycloud_env_azure" "current" { Examples: - ["eastus-1", "eastus-2"] + +### Nested Schema for `timeouts` + +Optional: + +- `delete` (String) Adjust timeout for deleting the environment. + + ### Nested Schema for `load_balancers` diff --git a/docs/data-sources/env_gcp.md b/docs/data-sources/env_gcp.md index 79d92af..a65a06d 100644 --- a/docs/data-sources/env_gcp.md +++ b/docs/data-sources/env_gcp.md @@ -28,6 +28,10 @@ data "altinitycloud_env_gcp" "current" { Examples: - "acme-staging" (where "acme" is your account name) +### Optional + +- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts)) + ### Read-Only - `cidr` (String) VPC CIDR block from the private IPv4 address ranges as specified in RFC 1918 (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16). At least /21 required. **[IMMUTABLE]** @@ -72,6 +76,14 @@ data "altinitycloud_env_gcp" "current" { Examples: - ["us-west1a", "us-west1b"] + +### Nested Schema for `timeouts` + +Optional: + +- `delete` (String) Adjust timeout for deleting the environment. + + ### Nested Schema for `load_balancers` diff --git a/docs/data-sources/env_k8s.md b/docs/data-sources/env_k8s.md index 152c958..263267e 100644 --- a/docs/data-sources/env_k8s.md +++ b/docs/data-sources/env_k8s.md @@ -28,6 +28,10 @@ data "altinitycloud_env_k8s" "current" { Examples: - "acme-staging" (where "acme" is your account name) +### Optional + +- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts)) + ### Read-Only - `custom_domain` (String) Custom domain. @@ -68,6 +72,14 @@ data "altinitycloud_env_k8s" "current" { - `skip_deprovision_on_destroy` (Boolean) - `spec_revision` (Number) Spec revision + +### Nested Schema for `timeouts` + +Optional: + +- `delete` (String) Adjust timeout for deleting the environment. + + ### Nested Schema for `custom_node_types` diff --git a/docs/resources/env_aws.md b/docs/resources/env_aws.md index d422359..ea684a7 100644 --- a/docs/resources/env_aws.md +++ b/docs/resources/env_aws.md @@ -159,7 +159,7 @@ resource "altinitycloud_env_aws" "this" { } peering_connections = [ { - aws_account_id = local.aws_account_id # This only required if the VPC is it not in the same account as the environment. + aws_account_id = local.aws_account_id # This only required if the VPC is not in the same account as the environment. vpc_id = "vpc-xyz" } ] @@ -246,6 +246,7 @@ resource "aws_vpc_peering_connection_accepter" "peer" { - `peering_connections` (Attributes List) AWS environment VPC peering configuration. (see [below for nested schema](#nestedatt--peering_connections)) - `skip_deprovision_on_destroy` (Boolean) - `tags` (Attributes List) Tags to apply to AWS resources. (see [below for nested schema](#nestedatt--tags)) +- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts)) - `zones` (List of String) Explicit list of AWS availability zones. At least 2 required. Examples: @@ -364,6 +365,14 @@ Required: - `key` (String) Name of the key - `value` (String) Value of the key + + +### Nested Schema for `timeouts` + +Optional: + +- `delete` (String) Adjust timeout for deleting the environment. + ## Import Import is supported using the following syntax: diff --git a/docs/resources/env_azure.md b/docs/resources/env_azure.md index 1e44c01..e27a4a4 100644 --- a/docs/resources/env_azure.md +++ b/docs/resources/env_azure.md @@ -115,6 +115,7 @@ resource "altinitycloud_env_azure" "azure" { - `private_link_service` (Attributes) Azure Private Link service configuration. (see [below for nested schema](#nestedatt--private_link_service)) - `skip_deprovision_on_destroy` (Boolean) - `tags` (Attributes List) Tags to apply to Azure resources. (see [below for nested schema](#nestedatt--tags)) +- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts)) - `zones` (List of String) Explicit list of Azure availability zones. At least 2 required. Examples: @@ -212,6 +213,14 @@ Required: - `key` (String) Name of the key - `value` (String) Value of the key + + +### Nested Schema for `timeouts` + +Optional: + +- `delete` (String) Adjust timeout for deleting the environment. + ## Import Import is supported using the following syntax: diff --git a/docs/resources/env_gcp.md b/docs/resources/env_gcp.md index 7883b67..4f35ce4 100644 --- a/docs/resources/env_gcp.md +++ b/docs/resources/env_gcp.md @@ -121,6 +121,7 @@ resource "altinitycloud_env_gcp" "this" { - `maintenance_windows` (Attributes List) List of maintenance windows during which automatic maintenance is permitted. By default updates are applied as soon as they are available. (see [below for nested schema](#nestedatt--maintenance_windows)) - `number_of_zones` (Number) Number of zones where the environment will be available. When set, zones will be set automatically based on your cloud provider (Do not use it together with zones) - `skip_deprovision_on_destroy` (Boolean) +- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts)) - `zones` (List of String) Explicit list of GCP zones. At least 2 required. Examples: - ["us-west1a", "us-west1b"] @@ -200,6 +201,14 @@ Optional: - `enabled` (Boolean) Set to `true` if maintenance window is enabled, `false` otherwise. (default `false`) + + +### Nested Schema for `timeouts` + +Optional: + +- `delete` (String) Adjust timeout for deleting the environment. + ## Import Import is supported using the following syntax: diff --git a/docs/resources/env_k8s.md b/docs/resources/env_k8s.md index ce667d0..598f905 100644 --- a/docs/resources/env_k8s.md +++ b/docs/resources/env_k8s.md @@ -136,6 +136,7 @@ resource "altinitycloud_env_k8s" "this" { - `maintenance_windows` (Attributes List) List of maintenance windows during which automatic maintenance is permitted. By default updates are applied as soon as they are available. (see [below for nested schema](#nestedatt--maintenance_windows)) - `metrics` (Attributes) Metrics configuration (see [below for nested schema](#nestedatt--metrics)) - `skip_deprovision_on_destroy` (Boolean) +- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts)) ### Read-Only @@ -322,6 +323,14 @@ Optional: - `retention_period_in_days` (Number) Metrics retention period in days (default `30`). + + +### Nested Schema for `timeouts` + +Optional: + +- `delete` (String) Adjust timeout for deleting the environment. + ## Import Import is supported using the following syntax: diff --git a/examples/resources/altinitycloud_env_aws/peering/main.tf b/examples/resources/altinitycloud_env_aws/peering/main.tf index f631fec..a71438d 100644 --- a/examples/resources/altinitycloud_env_aws/peering/main.tf +++ b/examples/resources/altinitycloud_env_aws/peering/main.tf @@ -29,7 +29,7 @@ resource "altinitycloud_env_aws" "this" { } peering_connections = [ { - aws_account_id = local.aws_account_id # This only required if the VPC is it not in the same account as the environment. + aws_account_id = local.aws_account_id # This only required if the VPC is not in the same account as the environment. vpc_id = "vpc-xyz" } ] diff --git a/go.mod b/go.mod index 7b0bd44..db33e7c 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( require ( github.com/MakeNowJust/heredoc/v2 v2.0.1 + github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 github.com/hashicorp/terraform-plugin-testing v1.8.0 ) diff --git a/go.sum b/go.sum index b8156d4..57a480d 100644 --- a/go.sum +++ b/go.sum @@ -122,6 +122,8 @@ github.com/hashicorp/terraform-plugin-docs v0.19.3 h1:xoxpeIuBfnoGxXY0dTajdj4GjE github.com/hashicorp/terraform-plugin-docs v0.19.3/go.mod h1:4pLASsatTmRynVzsjEhbXZ6s7xBlUw/2Kt0zfrq8HxA= github.com/hashicorp/terraform-plugin-framework v1.9.0 h1:caLcDoxiRucNi2hk8+j3kJwkKfvHznubyFsJMWfZqKU= github.com/hashicorp/terraform-plugin-framework v1.9.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM= +github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 h1:gm5b1kHgFFhaKFhm4h2TgvMUlNzFAtUqlcOWnWPm+9E= +github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1/go.mod h1:MsjL1sQ9L7wGwzJ5RjcI6FzEMdyoBnw+XK8ZnOvQOLY= github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc= github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg= github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/125t+AAurhqphJ2Co= diff --git a/internal/provider/common/attributes.go b/internal/provider/common/attributes.go index 751ed1f..ddfbd50 100644 --- a/internal/provider/common/attributes.go +++ b/internal/provider/common/attributes.go @@ -1,14 +1,15 @@ package common import ( + "context" "regexp" - "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" - "github.com/altinity/terraform-provider-altinitycloud/internal/provider/modifiers" "github.com/altinity/terraform-provider-altinitycloud/internal/sdk/client" + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -258,6 +259,13 @@ func GetTagsAttribute(required, optional, computed bool, description string) rsc } } +func GetTimeoutsAttribute(ctx context.Context) rschema.Attribute { + return timeouts.Attributes(ctx, timeouts.Opts{ + Delete: true, + DeleteDescription: "Adjust timeout for deleting the environment.", + }) +} + var PendingDeleteAttribute = rschema.BoolAttribute{ Required: false, Optional: false, diff --git a/internal/provider/env/aws/model.go b/internal/provider/env/aws/model.go index c7e4e87..9205f38 100644 --- a/internal/provider/env/aws/model.go +++ b/internal/provider/env/aws/model.go @@ -6,6 +6,7 @@ import ( common "github.com/altinity/terraform-provider-altinitycloud/internal/provider/env/common" "github.com/altinity/terraform-provider-altinitycloud/internal/sdk/client" sdk "github.com/altinity/terraform-provider-altinitycloud/internal/sdk/client" + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -27,10 +28,11 @@ type AWSEnvResourceModel struct { CloudConnect types.Bool `tfsdk:"cloud_connect"` MaintenanceWindows []common.MaintenanceWindowModel `tfsdk:"maintenance_windows"` - SpecRevision types.Int64 `tfsdk:"spec_revision"` - ForceDestroy types.Bool `tfsdk:"force_destroy"` - ForceDestroyClusters types.Bool `tfsdk:"force_destroy_clusters"` - SkipDeprovisionOnDestroy types.Bool `tfsdk:"skip_deprovision_on_destroy"` + SpecRevision types.Int64 `tfsdk:"spec_revision"` + ForceDestroy types.Bool `tfsdk:"force_destroy"` + ForceDestroyClusters types.Bool `tfsdk:"force_destroy_clusters"` + SkipDeprovisionOnDestroy types.Bool `tfsdk:"skip_deprovision_on_destroy"` + Timeouts timeouts.Value `tfsdk:"timeouts"` } type LoadBalancersModel struct { diff --git a/internal/provider/env/aws/resource.go b/internal/provider/env/aws/resource.go index d7c387b..a3b2e20 100644 --- a/internal/provider/env/aws/resource.go +++ b/internal/provider/env/aws/resource.go @@ -177,8 +177,14 @@ func (r *AWSEnvResource) Delete(ctx context.Context, req resource.DeleteRequest, return } + deleteTimeout, diags := data.Timeouts.Delete(ctx, 60*time.Minute) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + // Polling to wait for deletion to complete - timeout := time.After(time.Duration(30) * time.Minute) + timeout := time.After(deleteTimeout) ticker := time.NewTicker(30 * time.Second) defer ticker.Stop() diff --git a/internal/provider/env/aws/schema.go b/internal/provider/env/aws/schema.go index cfbca3d..1eaa347 100644 --- a/internal/provider/env/aws/schema.go +++ b/internal/provider/env/aws/schema.go @@ -38,11 +38,12 @@ func (r *AWSEnvResource) Schema(ctx context.Context, req resource.SchemaRequest, "peering_connections": getPeeringConnectionsAttribute(false, true, false), "endpoints": getEndpointsAttribute(false, true, false), "tags": getTagsAttribute(false, true, false), - "cloud_connect": cloudConnectAttribute, + "cloud_connect": getCloudConnectAttribute(false, true, true), "spec_revision": common.SpecRevisionAttribute, "force_destroy": common.GetForceDestroyAttribute(false, true, true), "force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, true, true), "skip_deprovision_on_destroy": common.GetSkipProvisioningOnDestroyAttribute(false, true, true), + "timeouts": common.GetTimeoutsAttribute(ctx), }, } } @@ -66,7 +67,7 @@ func (d *AWSEnvDataSource) Schema(ctx context.Context, req datasource.SchemaRequ "peering_connections": getPeeringConnectionsAttribute(false, false, true), "endpoints": getEndpointsAttribute(false, false, true), "tags": getTagsAttribute(false, false, true), - "cloud_connect": cloudConnectAttribute, + "cloud_connect": getCloudConnectAttribute(false, false, true), "spec_revision": common.SpecRevisionAttribute, // these options are not used in data sources, @@ -74,6 +75,7 @@ func (d *AWSEnvDataSource) Schema(ctx context.Context, req datasource.SchemaRequ "force_destroy": common.GetForceDestroyAttribute(false, false, true), "force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, false, true), "skip_deprovision_on_destroy": common.GetSkipProvisioningOnDestroyAttribute(false, false, true), + "timeouts": common.GetTimeoutsAttribute(ctx), }, } } @@ -167,13 +169,19 @@ func getEndpointsAttribute(required, optional, computed bool) rschema.ListNested } } -var cloudConnectAttribute = rschema.BoolAttribute{ - Optional: true, - Computed: true, - MarkdownDescription: common.CLOUD_CONNECT_DESCRIPTION, - Default: booldefault.StaticBool(true), +func getCloudConnectAttribute(required, optional, computed bool) rschema.BoolAttribute { + return rschema.BoolAttribute{ + Optional: optional, + Required: required, + Computed: computed, + MarkdownDescription: common.CLOUD_CONNECT_DESCRIPTION, + Default: booldefault.StaticBool(true), + } } +// Optional: true, +// Computed: true, + var endpointAttribute = rschema.NestedAttributeObject{ Attributes: map[string]rschema.Attribute{ "service_name": rschema.StringAttribute{ diff --git a/internal/provider/env/azure/model.go b/internal/provider/env/azure/model.go index fe6088a..5db30ab 100644 --- a/internal/provider/env/azure/model.go +++ b/internal/provider/env/azure/model.go @@ -5,6 +5,7 @@ import ( common "github.com/altinity/terraform-provider-altinitycloud/internal/provider/env/common" "github.com/altinity/terraform-provider-altinitycloud/internal/sdk/client" + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -25,10 +26,11 @@ type AzureEnvResourceModel struct { Tags []common.KeyValueModel `tfsdk:"tags"` PrivateLinkService *PrivateLinkServiceModel `tfsdk:"private_link_service"` - SpecRevision types.Int64 `tfsdk:"spec_revision"` - ForceDestroy types.Bool `tfsdk:"force_destroy"` - ForceDestroyClusters types.Bool `tfsdk:"force_destroy_clusters"` - SkipDeprovisionOnDestroy types.Bool `tfsdk:"skip_deprovision_on_destroy"` + SpecRevision types.Int64 `tfsdk:"spec_revision"` + ForceDestroy types.Bool `tfsdk:"force_destroy"` + ForceDestroyClusters types.Bool `tfsdk:"force_destroy_clusters"` + SkipDeprovisionOnDestroy types.Bool `tfsdk:"skip_deprovision_on_destroy"` + Timeouts timeouts.Value `tfsdk:"timeouts"` } type PrivateLinkServiceModel struct { diff --git a/internal/provider/env/azure/resource.go b/internal/provider/env/azure/resource.go index f526259..80342de 100644 --- a/internal/provider/env/azure/resource.go +++ b/internal/provider/env/azure/resource.go @@ -178,8 +178,14 @@ func (r *AzureEnvResource) Delete(ctx context.Context, req resource.DeleteReques return } + deleteTimeout, diags := data.Timeouts.Delete(ctx, 60*time.Minute) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + // Polling to wait for deletion to complete - timeout := time.After(time.Duration(30) * time.Minute) + timeout := time.After(deleteTimeout) ticker := time.NewTicker(30 * time.Second) defer ticker.Stop() diff --git a/internal/provider/env/azure/schema.go b/internal/provider/env/azure/schema.go index c47eda5..e5cc8e1 100644 --- a/internal/provider/env/azure/schema.go +++ b/internal/provider/env/azure/schema.go @@ -41,6 +41,7 @@ func (r *AzureEnvResource) Schema(ctx context.Context, req resource.SchemaReques "force_destroy": common.GetForceDestroyAttribute(false, true, true), "force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, true, true), "skip_deprovision_on_destroy": common.GetSkipProvisioningOnDestroyAttribute(false, true, true), + "timeouts": common.GetTimeoutsAttribute(ctx), }, } } @@ -71,6 +72,7 @@ func (d *AzureEnvDataSource) Schema(ctx context.Context, req datasource.SchemaRe "force_destroy": common.GetForceDestroyAttribute(false, false, true), "force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, false, true), "skip_deprovision_on_destroy": common.GetSkipProvisioningOnDestroyAttribute(false, false, true), + "timeouts": common.GetTimeoutsAttribute(ctx), }, } } diff --git a/internal/provider/env/gcp/model.go b/internal/provider/env/gcp/model.go index 2216c15..b7da769 100644 --- a/internal/provider/env/gcp/model.go +++ b/internal/provider/env/gcp/model.go @@ -5,6 +5,7 @@ import ( common "github.com/altinity/terraform-provider-altinitycloud/internal/provider/env/common" "github.com/altinity/terraform-provider-altinitycloud/internal/sdk/client" + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -22,10 +23,11 @@ type GCPEnvResourceModel struct { LoadBalancingStrategy types.String `tfsdk:"load_balancing_strategy"` MaintenanceWindows []common.MaintenanceWindowModel `tfsdk:"maintenance_windows"` - SpecRevision types.Int64 `tfsdk:"spec_revision"` - ForceDestroy types.Bool `tfsdk:"force_destroy"` - ForceDestroyClusters types.Bool `tfsdk:"force_destroy_clusters"` - SkipDeprovisionOnDestroy types.Bool `tfsdk:"skip_deprovision_on_destroy"` + SpecRevision types.Int64 `tfsdk:"spec_revision"` + ForceDestroy types.Bool `tfsdk:"force_destroy"` + ForceDestroyClusters types.Bool `tfsdk:"force_destroy_clusters"` + SkipDeprovisionOnDestroy types.Bool `tfsdk:"skip_deprovision_on_destroy"` + Timeouts timeouts.Value `tfsdk:"timeouts"` } type LoadBalancersModel struct { diff --git a/internal/provider/env/gcp/resource.go b/internal/provider/env/gcp/resource.go index 7ea0f7d..dc8360c 100644 --- a/internal/provider/env/gcp/resource.go +++ b/internal/provider/env/gcp/resource.go @@ -178,8 +178,14 @@ func (r *GCPEnvResource) Delete(ctx context.Context, req resource.DeleteRequest, return } + deleteTimeout, diags := data.Timeouts.Delete(ctx, 60*time.Minute) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + // Polling to wait for deletion to complete - timeout := time.After(time.Duration(30) * time.Minute) + timeout := time.After(deleteTimeout) ticker := time.NewTicker(30 * time.Second) defer ticker.Stop() diff --git a/internal/provider/env/gcp/schema.go b/internal/provider/env/gcp/schema.go index 2ee6e3a..9bf03ad 100644 --- a/internal/provider/env/gcp/schema.go +++ b/internal/provider/env/gcp/schema.go @@ -36,6 +36,7 @@ func (r *GCPEnvResource) Schema(ctx context.Context, req resource.SchemaRequest, "force_destroy": common.GetForceDestroyAttribute(false, true, true), "force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, true, true), "skip_deprovision_on_destroy": common.GetSkipProvisioningOnDestroyAttribute(false, true, true), + "timeouts": common.GetTimeoutsAttribute(ctx), }, } } @@ -63,6 +64,7 @@ func (d *GCPEnvDataSource) Schema(ctx context.Context, req datasource.SchemaRequ "force_destroy": common.GetForceDestroyAttribute(false, false, true), "force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, false, true), "skip_deprovision_on_destroy": common.GetSkipProvisioningOnDestroyAttribute(false, false, true), + "timeouts": common.GetTimeoutsAttribute(ctx), }, } } diff --git a/internal/provider/env/k8s/model.go b/internal/provider/env/k8s/model.go index 031a6b5..c47960c 100644 --- a/internal/provider/env/k8s/model.go +++ b/internal/provider/env/k8s/model.go @@ -5,6 +5,7 @@ import ( common "github.com/altinity/terraform-provider-altinitycloud/internal/provider/env/common" "github.com/altinity/terraform-provider-altinitycloud/internal/sdk/client" + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -21,10 +22,11 @@ type K8SEnvResourceModel struct { Metrics *MetricsModel `tfsdk:"metrics"` MaintenanceWindows []common.MaintenanceWindowModel `tfsdk:"maintenance_windows"` - SpecRevision types.Int64 `tfsdk:"spec_revision"` - ForceDestroy types.Bool `tfsdk:"force_destroy"` - ForceDestroyClusters types.Bool `tfsdk:"force_destroy_clusters"` - SkipDeprovisionOnDestroy types.Bool `tfsdk:"skip_deprovision_on_destroy"` + SpecRevision types.Int64 `tfsdk:"spec_revision"` + ForceDestroy types.Bool `tfsdk:"force_destroy"` + ForceDestroyClusters types.Bool `tfsdk:"force_destroy_clusters"` + SkipDeprovisionOnDestroy types.Bool `tfsdk:"skip_deprovision_on_destroy"` + Timeouts timeouts.Value `tfsdk:"timeouts"` } type LogsModel struct { diff --git a/internal/provider/env/k8s/resource.go b/internal/provider/env/k8s/resource.go index 8a56050..1716bf6 100644 --- a/internal/provider/env/k8s/resource.go +++ b/internal/provider/env/k8s/resource.go @@ -176,10 +176,17 @@ func (r *K8SEnvResource) Delete(ctx context.Context, req resource.DeleteRequest, return } + deleteTimeout, diags := data.Timeouts.Delete(ctx, 60*time.Minute) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + // Polling to wait for deletion to complete - timeout := time.After(time.Duration(30) * time.Minute) + timeout := time.After(deleteTimeout) ticker := time.NewTicker(30 * time.Second) defer ticker.Stop() + for { select { case <-ctx.Done(): diff --git a/internal/provider/env/k8s/schema.go b/internal/provider/env/k8s/schema.go index fdefb57..b50162d 100644 --- a/internal/provider/env/k8s/schema.go +++ b/internal/provider/env/k8s/schema.go @@ -41,6 +41,7 @@ func (r *K8SEnvResource) Schema(ctx context.Context, req resource.SchemaRequest, "force_destroy": common.GetForceDestroyAttribute(false, true, true), "force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, true, true), "skip_deprovision_on_destroy": common.GetSkipProvisioningOnDestroyAttribute(false, true, true), + "timeouts": common.GetTimeoutsAttribute(ctx), }, } } @@ -67,6 +68,7 @@ func (d *K8SEnvDataSource) Schema(ctx context.Context, req datasource.SchemaRequ "force_destroy": common.GetForceDestroyAttribute(false, false, true), "force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, false, true), "skip_deprovision_on_destroy": common.GetSkipProvisioningOnDestroyAttribute(false, false, true), + "timeouts": common.GetTimeoutsAttribute(ctx), }, } }