Skip to content

Commit 9d0e1af

Browse files
committed
feat: allow env delete timeout customization
1 parent 0409cbb commit 9d0e1af

File tree

13 files changed

+68
-19
lines changed

13 files changed

+68
-19
lines changed

examples/resources/altinitycloud_env_aws/peering/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ resource "altinitycloud_env_aws" "this" {
2929
}
3030
peering_connections = [
3131
{
32-
aws_account_id = local.aws_account_id # This only required if the VPC is it not in the same account as the environment.
32+
aws_account_id = local.aws_account_id # This only required if the VPC is not in the same account as the environment.
3333
vpc_id = "vpc-xyz"
3434
}
3535
]

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515

1616
require (
1717
github.com/MakeNowJust/heredoc/v2 v2.0.1
18+
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1
1819
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
1920
github.com/hashicorp/terraform-plugin-testing v1.8.0
2021
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ github.com/hashicorp/terraform-plugin-docs v0.19.3 h1:xoxpeIuBfnoGxXY0dTajdj4GjE
122122
github.com/hashicorp/terraform-plugin-docs v0.19.3/go.mod h1:4pLASsatTmRynVzsjEhbXZ6s7xBlUw/2Kt0zfrq8HxA=
123123
github.com/hashicorp/terraform-plugin-framework v1.9.0 h1:caLcDoxiRucNi2hk8+j3kJwkKfvHznubyFsJMWfZqKU=
124124
github.com/hashicorp/terraform-plugin-framework v1.9.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM=
125+
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 h1:gm5b1kHgFFhaKFhm4h2TgvMUlNzFAtUqlcOWnWPm+9E=
126+
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1/go.mod h1:MsjL1sQ9L7wGwzJ5RjcI6FzEMdyoBnw+XK8ZnOvQOLY=
125127
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc=
126128
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg=
127129
github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/125t+AAurhqphJ2Co=

internal/provider/env/aws/model.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
common "github.com/altinity/terraform-provider-altinitycloud/internal/provider/env/common"
77
"github.com/altinity/terraform-provider-altinitycloud/internal/sdk/client"
88
sdk "github.com/altinity/terraform-provider-altinitycloud/internal/sdk/client"
9+
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
910
"github.com/hashicorp/terraform-plugin-framework/types"
1011
)
1112

@@ -27,10 +28,11 @@ type AWSEnvResourceModel struct {
2728
CloudConnect types.Bool `tfsdk:"cloud_connect"`
2829
MaintenanceWindows []common.MaintenanceWindowModel `tfsdk:"maintenance_windows"`
2930

30-
SpecRevision types.Int64 `tfsdk:"spec_revision"`
31-
ForceDestroy types.Bool `tfsdk:"force_destroy"`
32-
ForceDestroyClusters types.Bool `tfsdk:"force_destroy_clusters"`
33-
SkipDeprovisionOnDestroy types.Bool `tfsdk:"skip_deprovision_on_destroy"`
31+
SpecRevision types.Int64 `tfsdk:"spec_revision"`
32+
ForceDestroy types.Bool `tfsdk:"force_destroy"`
33+
ForceDestroyClusters types.Bool `tfsdk:"force_destroy_clusters"`
34+
SkipDeprovisionOnDestroy types.Bool `tfsdk:"skip_deprovision_on_destroy"`
35+
Timeouts timeouts.Value `tfsdk:"timeouts"`
3436
}
3537

3638
type LoadBalancersModel struct {

internal/provider/env/aws/resource.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,14 @@ func (r *AWSEnvResource) Delete(ctx context.Context, req resource.DeleteRequest,
177177
return
178178
}
179179

180+
deleteTimeout, diags := data.Timeouts.Delete(ctx, 60*time.Minute)
181+
resp.Diagnostics.Append(diags...)
182+
if resp.Diagnostics.HasError() {
183+
return
184+
}
185+
180186
// Polling to wait for deletion to complete
181-
timeout := time.After(time.Duration(30) * time.Minute)
187+
timeout := time.After(deleteTimeout)
182188
ticker := time.NewTicker(30 * time.Second)
183189
defer ticker.Stop()
184190

internal/provider/env/aws/schema.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/MakeNowJust/heredoc/v2"
77
"github.com/altinity/terraform-provider-altinitycloud/internal/provider/common"
88
"github.com/altinity/terraform-provider-altinitycloud/internal/provider/modifiers"
9+
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
910
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
1011
"github.com/hashicorp/terraform-plugin-framework/attr"
1112
"github.com/hashicorp/terraform-plugin-framework/datasource"
@@ -43,6 +44,9 @@ func (r *AWSEnvResource) Schema(ctx context.Context, req resource.SchemaRequest,
4344
"force_destroy": common.GetForceDestroyAttribute(false, true, true),
4445
"force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, true, true),
4546
"skip_deprovision_on_destroy": common.GetSkipProvisioningOnDestroyAttribute(false, true, true),
47+
"timeouts": timeouts.Attributes(ctx, timeouts.Opts{
48+
Delete: true,
49+
}),
4650
},
4751
}
4852
}
@@ -74,6 +78,7 @@ func (d *AWSEnvDataSource) Schema(ctx context.Context, req datasource.SchemaRequ
7478
"force_destroy": common.GetForceDestroyAttribute(false, false, true),
7579
"force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, false, true),
7680
"skip_deprovision_on_destroy": common.GetSkipProvisioningOnDestroyAttribute(false, false, true),
81+
"timeouts": timeouts.Attributes(ctx, timeouts.Opts{}),
7782
},
7883
}
7984
}

internal/provider/env/azure/model.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
common "github.com/altinity/terraform-provider-altinitycloud/internal/provider/env/common"
77
"github.com/altinity/terraform-provider-altinitycloud/internal/sdk/client"
8+
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
89
"github.com/hashicorp/terraform-plugin-framework/types"
910
)
1011

@@ -25,10 +26,11 @@ type AzureEnvResourceModel struct {
2526
Tags []common.KeyValueModel `tfsdk:"tags"`
2627
PrivateLinkService *PrivateLinkServiceModel `tfsdk:"private_link_service"`
2728

28-
SpecRevision types.Int64 `tfsdk:"spec_revision"`
29-
ForceDestroy types.Bool `tfsdk:"force_destroy"`
30-
ForceDestroyClusters types.Bool `tfsdk:"force_destroy_clusters"`
31-
SkipDeprovisionOnDestroy types.Bool `tfsdk:"skip_deprovision_on_destroy"`
29+
SpecRevision types.Int64 `tfsdk:"spec_revision"`
30+
ForceDestroy types.Bool `tfsdk:"force_destroy"`
31+
ForceDestroyClusters types.Bool `tfsdk:"force_destroy_clusters"`
32+
SkipDeprovisionOnDestroy types.Bool `tfsdk:"skip_deprovision_on_destroy"`
33+
Timeouts timeouts.Value `tfsdk:"timeouts"`
3234
}
3335

3436
type PrivateLinkServiceModel struct {

internal/provider/env/azure/resource.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,14 @@ func (r *AzureEnvResource) Delete(ctx context.Context, req resource.DeleteReques
178178
return
179179
}
180180

181+
deleteTimeout, diags := data.Timeouts.Delete(ctx, 60*time.Minute)
182+
resp.Diagnostics.Append(diags...)
183+
if resp.Diagnostics.HasError() {
184+
return
185+
}
186+
181187
// Polling to wait for deletion to complete
182-
timeout := time.After(time.Duration(30) * time.Minute)
188+
timeout := time.After(deleteTimeout)
183189
ticker := time.NewTicker(30 * time.Second)
184190
defer ticker.Stop()
185191

internal/provider/env/azure/schema.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/MakeNowJust/heredoc/v2"
77
"github.com/altinity/terraform-provider-altinitycloud/internal/provider/common"
88
"github.com/altinity/terraform-provider-altinitycloud/internal/provider/modifiers"
9+
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
910
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
1011
"github.com/hashicorp/terraform-plugin-framework/attr"
1112
"github.com/hashicorp/terraform-plugin-framework/datasource"
@@ -41,6 +42,9 @@ func (r *AzureEnvResource) Schema(ctx context.Context, req resource.SchemaReques
4142
"force_destroy": common.GetForceDestroyAttribute(false, true, true),
4243
"force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, true, true),
4344
"skip_deprovision_on_destroy": common.GetSkipProvisioningOnDestroyAttribute(false, true, true),
45+
"timeouts": timeouts.Attributes(ctx, timeouts.Opts{
46+
Delete: true,
47+
}),
4448
},
4549
}
4650
}
@@ -71,6 +75,9 @@ func (d *AzureEnvDataSource) Schema(ctx context.Context, req datasource.SchemaRe
7175
"force_destroy": common.GetForceDestroyAttribute(false, false, true),
7276
"force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, false, true),
7377
"skip_deprovision_on_destroy": common.GetSkipProvisioningOnDestroyAttribute(false, false, true),
78+
"timeouts": timeouts.Attributes(ctx, timeouts.Opts{
79+
Delete: true,
80+
}),
7481
},
7582
}
7683
}

internal/provider/env/gcp/model.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
common "github.com/altinity/terraform-provider-altinitycloud/internal/provider/env/common"
77
"github.com/altinity/terraform-provider-altinitycloud/internal/sdk/client"
8+
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
89
"github.com/hashicorp/terraform-plugin-framework/types"
910
)
1011

@@ -22,10 +23,11 @@ type GCPEnvResourceModel struct {
2223
LoadBalancingStrategy types.String `tfsdk:"load_balancing_strategy"`
2324
MaintenanceWindows []common.MaintenanceWindowModel `tfsdk:"maintenance_windows"`
2425

25-
SpecRevision types.Int64 `tfsdk:"spec_revision"`
26-
ForceDestroy types.Bool `tfsdk:"force_destroy"`
27-
ForceDestroyClusters types.Bool `tfsdk:"force_destroy_clusters"`
28-
SkipDeprovisionOnDestroy types.Bool `tfsdk:"skip_deprovision_on_destroy"`
26+
SpecRevision types.Int64 `tfsdk:"spec_revision"`
27+
ForceDestroy types.Bool `tfsdk:"force_destroy"`
28+
ForceDestroyClusters types.Bool `tfsdk:"force_destroy_clusters"`
29+
SkipDeprovisionOnDestroy types.Bool `tfsdk:"skip_deprovision_on_destroy"`
30+
Timeouts timeouts.Value `tfsdk:"timeouts"`
2931
}
3032

3133
type LoadBalancersModel struct {

0 commit comments

Comments
 (0)