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

feat: allow env delete timeout customization #58

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
11 changes: 10 additions & 1 deletion docs/data-sources/env_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -82,6 +83,14 @@ 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`

Optional:

- `delete` (String) Adjust timeout for deleting the environment.


<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) Adjust timeout for deleting the environment.


<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) Adjust timeout for deleting the environment.


<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) Adjust timeout for deleting the environment.


<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) Adjust timeout for deleting the environment.

## 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) Adjust timeout for deleting the environment.

## 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) Adjust timeout for deleting the environment.

## 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) Adjust timeout for deleting the environment.

## 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
12 changes: 10 additions & 2 deletions internal/provider/common/attributes.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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,
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
22 changes: 15 additions & 7 deletions internal/provider/env/aws/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}
}
Expand All @@ -66,14 +67,15 @@ 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,
// but we need to include them in the schema to avoid conversion errors.
"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),
},
}
}
Expand Down Expand Up @@ -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{
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
Loading