Skip to content

Commit

Permalink
feat: add allow_delete_while_disconnected to envs
Browse files Browse the repository at this point in the history
  • Loading branch information
ianaya89 committed Jan 14, 2025
1 parent 9864078 commit 01e5bcc
Show file tree
Hide file tree
Showing 27 changed files with 165 additions and 129 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/env_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Bring Your Own Cloud (BYOC) AWS environment data source.

### Read-Only

- `allow_delete_while_disconnected` (Boolean) Set to `true` to allow deletion of the environment while it is disconnected from the cloud connect. If the the environment is not connected during the deletion process you will end up in a delete timeout (default `false`).
- `aws_account_id` (String) ID of the AWS account ([docs](https://docs.aws.amazon.com/IAM/latest/UserGuide/console_account-alias.html#ViewYourAWSId)) in which to provision AWS resources. **[IMMUTABLE]**
- `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
1 change: 1 addition & 0 deletions docs/data-sources/env_azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Bring Your Own Cloud (BYOC) Azure environment data source.

### Read-Only

- `allow_delete_while_disconnected` (Boolean) Set to `true` to allow deletion of the environment while it is disconnected from the cloud connect. If the the environment is not connected during the deletion process you will end up in a delete timeout (default `false`).
- `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]**

Examples:
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/env_gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Bring Your Own Cloud (BYOC) GCP environment data source.

### Read-Only

- `allow_delete_while_disconnected` (Boolean) Set to `true` to allow deletion of the environment while it is disconnected from the cloud connect. If the the environment is not connected during the deletion process you will end up in a delete timeout (default `false`).
- `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]**

Examples:
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/env_hcloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Bring Your Own Cloud (BYOC) HCloud environment data source.

### Read-Only

- `allow_delete_while_disconnected` (Boolean) Set to `true` to allow deletion of the environment while it is disconnected from the cloud connect. If the the environment is not connected during the deletion process you will end up in a delete timeout (default `false`).
- `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]**

Examples:
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/env_k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Bring Your Own Kubernetes (BYOK) environment data source.

### Read-Only

- `allow_delete_while_disconnected` (Boolean) Set to `true` to allow deletion of the environment while it is disconnected from the cloud connect. If the the environment is not connected during the deletion process you will end up in a delete timeout (default `false`).
- `custom_domain` (String) Custom domain.

Examples:
Expand Down
1 change: 1 addition & 0 deletions docs/resources/env_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ resource "aws_vpc_peering_connection_accepter" "peer" {

### Optional

- `allow_delete_while_disconnected` (Boolean) Set to `true` to allow deletion of the environment while it is disconnected from the cloud connect. If the the environment is not connected during the deletion process you will end up in a delete timeout (default `false`).
- `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.

Expand Down
1 change: 1 addition & 0 deletions docs/resources/env_azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ data "altinitycloud_env_azure_status" "this" {

### Optional

- `allow_delete_while_disconnected` (Boolean) Set to `true` to allow deletion of the environment while it is disconnected from the cloud connect. If the the environment is not connected during the deletion process you will end up in a delete timeout (default `false`).
- `custom_domain` (String) Custom domain.

Examples:
Expand Down
1 change: 1 addition & 0 deletions docs/resources/env_gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ data "altinitycloud_env_gcp_status" "this" {

### Optional

- `allow_delete_while_disconnected` (Boolean) Set to `true` to allow deletion of the environment while it is disconnected from the cloud connect. If the the environment is not connected during the deletion process you will end up in a delete timeout (default `false`).
- `custom_domain` (String) Custom domain.

Examples:
Expand Down
1 change: 1 addition & 0 deletions docs/resources/env_hcloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ data "altinitycloud_env_hcloud_status" "this" {

### Optional

- `allow_delete_while_disconnected` (Boolean) Set to `true` to allow deletion of the environment while it is disconnected from the cloud connect. If the the environment is not connected during the deletion process you will end up in a delete timeout (default `false`).
- `custom_domain` (String) Custom domain.

Examples:
Expand Down
1 change: 1 addition & 0 deletions docs/resources/env_k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ resource "altinitycloud_env_k8s" "this" {

### Optional

- `allow_delete_while_disconnected` (Boolean) Set to `true` to allow deletion of the environment while it is disconnected from the cloud connect. If the the environment is not connected during the deletion process you will end up in a delete timeout (default `false`).
- `custom_domain` (String) Custom domain.

Examples:
Expand Down
10 changes: 10 additions & 0 deletions internal/provider/common/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ func GetSkipProvisioningOnDestroyAttribute(required, optional, computed bool) rs
}
}

func GetAllowDeleteWhileDisconnectedAttribute(required, optional, computed bool) rschema.BoolAttribute {
return rschema.BoolAttribute{
Required: required,
Optional: optional,
Computed: computed,
MarkdownDescription: ALLOW_DELETE_WHILE_DISCONNECTED_DESCRIPTION,
Default: booldefault.StaticBool(false),
}
}

func GetReservationsAttribute(required, optional, computed bool) rschema.SetAttribute {
return rschema.SetAttribute{
ElementType: types.StringType,
Expand Down
1 change: 1 addition & 0 deletions internal/provider/common/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const NODE_GROUP_TOLERATIONS_OPERATOR = `Node toleration operator used to match
const FORCE_DESTROY_DESCRIPTION = "Locks the environment for accidental deletion when running `terraform destroy` command. Your environment will be deleted, only when setting this parameter to `true`. Once this parameter is set to `true`, there must be a successful `terraform apply` run (before running the `terraform destroy`) to update this value in the state. Without a successful `terraform apply` after this parameter is set, this flag will have no effect. (default `false`)"
const FORCE_DESTROY_CLUSTERS_DESCRIPTION = "By default, the destroy operation will not delete any provisioned clusters and the deletion will fail until the clusters get removed. Set to `true` to remove all provisioned clusters as part of the environment deletion process."
const SKIP_PROVISIONING_ON_DESTROY_DESCRIPTION = "Set to `true` will delete without waiting for environment deprovisioning. Use this with precaution, it may end up with dangling resources in your cloud provider (default `false`)."
const ALLOW_DELETE_WHILE_DISCONNECTED_DESCRIPTION = "Set to `true` to allow deletion of the environment while it is disconnected from the cloud connect. If the the environment is not connected during the deletion process you will end up in a delete timeout (default `false`)."
const STATUS_DESCRIPTION = "Environment status"
const STATUS_SPEC_REVISION_DESCRIPTION = "Spec revision"
const STATUS_APPLIED_SPEC_REVISION_DESCRIPTION = "Applied spec revision"
Expand Down
9 changes: 5 additions & 4 deletions internal/provider/env/aws/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,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"`
AllowDeleteWhileDisconnected types.Bool `tfsdk:"allow_delete_while_disconnected"`
}

type LoadBalancersModel struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/env/aws/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ func (r *AWSEnvResource) Delete(ctx context.Context, req resource.DeleteRequest,

if len(envStatus.AWSEnv.Status.Errors) > 0 {
for _, err := range envStatus.AWSEnv.Status.Errors {
if err.Code == "DISCONNECTED" && !data.SkipDeprovisionOnDestroy.ValueBool() {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete env %s, environment is DISCONNECTED.\nCheck environment's `cloudconnect` or use `skip_deprovision_on_destroy` to delete environment without deprovisioning cloud resources.", envName))
if err.Code == "DISCONNECTED" && !data.SkipDeprovisionOnDestroy.ValueBool() && !data.AllowDeleteWhileDisconnected.ValueBool() {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to start env %s, environment is DISCONNECTED.\nCheck environment's `cloudconnect` or use `allow_delete_while_disconnected=true` to continue with the delete operation.", envName))
return
}
}
Expand Down
48 changes: 25 additions & 23 deletions internal/provider/env/aws/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,27 @@ func (r *AWSEnvResource) Schema(ctx context.Context, req resource.SchemaRequest,
resp.Schema = rschema.Schema{
MarkdownDescription: heredoc.Doc(`Bring Your Own Cloud (BYOC) AWS environment resource.`),
Attributes: map[string]rschema.Attribute{
"id": common.IDAttribute,
"name": common.NameAttribute,
"custom_domain": common.GetCommonCustomDomainAttribute(false, true, false),
"load_balancers": getLoadBalancersAttribute(false, true, true),
"load_balancing_strategy": common.GetLoadBalancingStrategyAttribute(false, true, true),
"maintenance_windows": common.GetMaintenanceWindowAttribute(false, true, false),
"cidr": common.GetCIDRAttribute(true, false, false),
"zones": getZonesAttribute(false, true, true, common.AWS_ZONES_DESCRIPTION),
"node_groups": common.GetNodeGroupsAttribute(true, false, false),
"aws_account_id": getAWSAccountIDAttribute(true, false, false),
"region": common.GetRegionAttribute(true, false, false, common.AWS_REGION_DESCRIPTION),
"nat": getNATAttribute(false, true, true),
"peering_connections": getPeeringConnectionsAttribute(false, true, false),
"endpoints": getEndpointsAttribute(false, true, false),
"tags": getTagsAttribute(false, true, false),
"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),
"id": common.IDAttribute,
"name": common.NameAttribute,
"custom_domain": common.GetCommonCustomDomainAttribute(false, true, false),
"load_balancers": getLoadBalancersAttribute(false, true, true),
"load_balancing_strategy": common.GetLoadBalancingStrategyAttribute(false, true, true),
"maintenance_windows": common.GetMaintenanceWindowAttribute(false, true, false),
"cidr": common.GetCIDRAttribute(true, false, false),
"zones": getZonesAttribute(false, true, true, common.AWS_ZONES_DESCRIPTION),
"node_groups": common.GetNodeGroupsAttribute(true, false, false),
"aws_account_id": getAWSAccountIDAttribute(true, false, false),
"region": common.GetRegionAttribute(true, false, false, common.AWS_REGION_DESCRIPTION),
"nat": getNATAttribute(false, true, true),
"peering_connections": getPeeringConnectionsAttribute(false, true, false),
"endpoints": getEndpointsAttribute(false, true, false),
"tags": getTagsAttribute(false, true, false),
"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),
"allow_delete_while_disconnected": common.GetAllowDeleteWhileDisconnectedAttribute(false, true, true),
},
}
}
Expand Down Expand Up @@ -73,9 +74,10 @@ func (d *AWSEnvDataSource) Schema(ctx context.Context, req datasource.SchemaRequ

// 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),
"force_destroy": common.GetForceDestroyAttribute(false, false, true),
"force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, false, true),
"skip_deprovision_on_destroy": common.GetSkipProvisioningOnDestroyAttribute(false, false, true),
"allow_delete_while_disconnected": common.GetAllowDeleteWhileDisconnectedAttribute(false, false, true),
},
}
}
Expand Down
9 changes: 5 additions & 4 deletions internal/provider/env/azure/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,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"`
AllowDeleteWhileDisconnected types.Bool `tfsdk:"allow_delete_while_disconnected"`
}

type PrivateLinkServiceModel struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/env/azure/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ func (r *AzureEnvResource) Delete(ctx context.Context, req resource.DeleteReques

if len(envStatus.AzureEnv.Status.Errors) > 0 {
for _, err := range envStatus.AzureEnv.Status.Errors {
if err.Code == "DISCONNECTED" && !data.SkipDeprovisionOnDestroy.ValueBool() {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete env %s, environment is DISCONNECTED.\nCheck environment's `cloudconnect` or use `skip_deprovision_on_destroy` to delete environment without deprovisioning cloud resources.", envName))
if err.Code == "DISCONNECTED" && !data.SkipDeprovisionOnDestroy.ValueBool() && !data.AllowDeleteWhileDisconnected.ValueBool() {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to start env %s, environment is DISCONNECTED.\nCheck environment's `cloudconnect` or use `allow_delete_while_disconnected=true` to continue with the delete operation.", envName))
return
}
}
Expand Down
44 changes: 23 additions & 21 deletions internal/provider/env/azure/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,25 @@ func (r *AzureEnvResource) Schema(ctx context.Context, req resource.SchemaReques
resp.Schema = rschema.Schema{
MarkdownDescription: heredoc.Doc(`Bring Your Own Cloud (BYOC) Azure environment resource.`),
Attributes: map[string]rschema.Attribute{
"id": common.IDAttribute,
"name": common.NameAttribute,
"custom_domain": getCustomDomainAttribute(false, true, false),
"load_balancers": getLoadBalancersAttribute(false, true, true),
"load_balancing_strategy": common.GetLoadBalancingStrategyAttribute(false, true, true),
"maintenance_windows": common.GetMaintenanceWindowAttribute(false, true, false),
"cidr": common.GetCIDRAttribute(true, false, false),
"zones": common.GetZonesAttribute(false, true, true, common.AZURE_ZONES_DESCRIPTION),
"node_groups": common.GetNodeGroupsAttribute(true, false, false),
"region": common.GetRegionAttribute(true, false, false, common.AZURE_REGION_DESCRIPTION),
"tenant_id": getAzureTenantIDAttribute(true, false, false),
"subscription_id": getAzureSubscriptionIDAttribute(true, false, false),
"tags": getTagsAttribute(false, true, false),
"private_link_service": getPrivateLinkServiceAttribute(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),
"id": common.IDAttribute,
"name": common.NameAttribute,
"custom_domain": getCustomDomainAttribute(false, true, false),
"load_balancers": getLoadBalancersAttribute(false, true, true),
"load_balancing_strategy": common.GetLoadBalancingStrategyAttribute(false, true, true),
"maintenance_windows": common.GetMaintenanceWindowAttribute(false, true, false),
"cidr": common.GetCIDRAttribute(true, false, false),
"zones": common.GetZonesAttribute(false, true, true, common.AZURE_ZONES_DESCRIPTION),
"node_groups": common.GetNodeGroupsAttribute(true, false, false),
"region": common.GetRegionAttribute(true, false, false, common.AZURE_REGION_DESCRIPTION),
"tenant_id": getAzureTenantIDAttribute(true, false, false),
"subscription_id": getAzureSubscriptionIDAttribute(true, false, false),
"tags": getTagsAttribute(false, true, false),
"private_link_service": getPrivateLinkServiceAttribute(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),
"allow_delete_while_disconnected": common.GetAllowDeleteWhileDisconnectedAttribute(false, true, true),
},
}
}
Expand All @@ -66,9 +67,10 @@ func (d *AzureEnvDataSource) Schema(ctx context.Context, req datasource.SchemaRe

// 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),
"force_destroy": common.GetForceDestroyAttribute(false, false, true),
"force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, false, true),
"skip_deprovision_on_destroy": common.GetSkipProvisioningOnDestroyAttribute(false, false, true),
"allow_delete_while_disconnected": common.GetAllowDeleteWhileDisconnectedAttribute(false, false, true),
},
}
}
Expand Down
Loading

0 comments on commit 01e5bcc

Please sign in to comment.