Skip to content

Commit

Permalink
feat: allow env delete timeout customization
Browse files Browse the repository at this point in the history
  • Loading branch information
ianaya89 committed Jun 5, 2024
1 parent 0409cbb commit 55d5336
Show file tree
Hide file tree
Showing 23 changed files with 161 additions and 22 deletions.
5 changes: 5 additions & 0 deletions docs/data-sources/env_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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

Expand Down Expand Up @@ -82,6 +83,10 @@ data "altinitycloud_env_aws" "current" {
- ["us-east-1a", "us-east-1b"]
- ["sa-east-1c", "sa-east-1d"]

<a id="nestedatt--timeouts"></a>
### Nested Schema for `timeouts`


<a id="nestedatt--endpoints"></a>
### Nested Schema for `endpoints`

Expand Down
12 changes: 12 additions & 0 deletions docs/data-sources/env_azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]**
Expand Down Expand Up @@ -77,6 +81,14 @@ data "altinitycloud_env_azure" "current" {
Examples:
- ["eastus-1", "eastus-2"]

<a id="nestedatt--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.


<a id="nestedatt--load_balancers"></a>
### Nested Schema for `load_balancers`

Expand Down
12 changes: 12 additions & 0 deletions docs/data-sources/env_gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]**
Expand Down Expand Up @@ -72,6 +76,14 @@ data "altinitycloud_env_gcp" "current" {
Examples:
- ["us-west1a", "us-west1b"]

<a id="nestedatt--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.


<a id="nestedatt--load_balancers"></a>
### Nested Schema for `load_balancers`

Expand Down
12 changes: 12 additions & 0 deletions docs/data-sources/env_k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -68,6 +72,14 @@ data "altinitycloud_env_k8s" "current" {
- `skip_deprovision_on_destroy` (Boolean)
- `spec_revision` (Number) Spec revision

<a id="nestedatt--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.


<a id="nestedatt--custom_node_types"></a>
### Nested Schema for `custom_node_types`

Expand Down
11 changes: 10 additions & 1 deletion docs/resources/env_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -364,6 +365,14 @@ Required:
- `key` (String) Name of the key
- `value` (String) Value of the key


<a id="nestedatt--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.

## Import

Import is supported using the following syntax:
Expand Down
9 changes: 9 additions & 0 deletions docs/resources/env_azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -212,6 +213,14 @@ Required:
- `key` (String) Name of the key
- `value` (String) Value of the key


<a id="nestedatt--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.

## Import

Import is supported using the following syntax:
Expand Down
9 changes: 9 additions & 0 deletions docs/resources/env_gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -200,6 +201,14 @@ Optional:

- `enabled` (Boolean) Set to `true` if maintenance window is enabled, `false` otherwise. (default `false`)


<a id="nestedatt--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.

## Import

Import is supported using the following syntax:
Expand Down
9 changes: 9 additions & 0 deletions docs/resources/env_k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -322,6 +323,14 @@ Optional:

- `retention_period_in_days` (Number) Metrics retention period in days (default `30`).


<a id="nestedatt--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.

## Import

Import is supported using the following syntax:
Expand Down
2 changes: 1 addition & 1 deletion examples/resources/altinitycloud_env_aws/peering/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
10 changes: 6 additions & 4 deletions internal/provider/env/aws/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion internal/provider/env/aws/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
5 changes: 5 additions & 0 deletions internal/provider/env/aws/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/MakeNowJust/heredoc/v2"
"github.com/altinity/terraform-provider-altinitycloud/internal/provider/common"
"github.com/altinity/terraform-provider-altinitycloud/internal/provider/modifiers"
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/datasource"
Expand Down Expand Up @@ -43,6 +44,9 @@ func (r *AWSEnvResource) 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": timeouts.Attributes(ctx, timeouts.Opts{
Delete: true,
}),
},
}
}
Expand Down Expand Up @@ -74,6 +78,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": timeouts.Attributes(ctx, timeouts.Opts{}),
},
}
}
Expand Down
10 changes: 6 additions & 4 deletions internal/provider/env/azure/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion internal/provider/env/azure/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
7 changes: 7 additions & 0 deletions internal/provider/env/azure/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/MakeNowJust/heredoc/v2"
"github.com/altinity/terraform-provider-altinitycloud/internal/provider/common"
"github.com/altinity/terraform-provider-altinitycloud/internal/provider/modifiers"
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/datasource"
Expand Down Expand Up @@ -41,6 +42,9 @@ 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": timeouts.Attributes(ctx, timeouts.Opts{
Delete: true,
}),
},
}
}
Expand Down Expand Up @@ -71,6 +75,9 @@ 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": timeouts.Attributes(ctx, timeouts.Opts{
Delete: true,
}),
},
}
}
Expand Down
10 changes: 6 additions & 4 deletions internal/provider/env/gcp/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion internal/provider/env/gcp/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading

0 comments on commit 55d5336

Please sign in to comment.