Skip to content

Commit

Permalink
CB-27556 Added cascading delete option to environments, environment a…
Browse files Browse the repository at this point in the history
…nd data lake delete should now always poll
  • Loading branch information
daszabo authored and gregito committed Oct 29, 2024
1 parent 7302a84 commit dba37d2
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 24 deletions.
9 changes: 4 additions & 5 deletions resources/datalake/resource_aws_datalake.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,11 @@ func (r *awsDatalakeResource) Delete(ctx context.Context, req resource.DeleteReq
return
}

if !(state.PollingOptions != nil && state.PollingOptions.Async.ValueBool()) {
if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil {
utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete AWS Datalake")
return
}
if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil {
utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete AWS Datalake")
return
}

}

func waitForDatalakeToBeDeleted(ctx context.Context, datalakeName string, fallbackPollingTimeout time.Duration, datalake *client.Datalake, options *utils.PollingOptions) error {
Expand Down
9 changes: 4 additions & 5 deletions resources/datalake/resource_azure_datalake.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,9 @@ func (r *azureDatalakeResource) Delete(ctx context.Context, req resource.DeleteR
return
}

if !(state.PollingOptions != nil && state.PollingOptions.Async.ValueBool()) {
if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil {
utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete Azure Datalake")
return
}
if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil {
utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete Azure Datalake")
return
}

}
9 changes: 4 additions & 5 deletions resources/datalake/resource_gcp_datalake.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,9 @@ func (r *gcpDatalakeResource) Delete(ctx context.Context, req resource.DeleteReq
return
}

if !(state.PollingOptions != nil && state.PollingOptions.Async.ValueBool()) {
if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil {
utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete GCP Datalake")
return
}
if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil {
utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete GCP Datalake")
return
}

}
7 changes: 2 additions & 5 deletions resources/environments/environment_action_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,15 @@ func describeEnvironmentWithDiagnosticHandle(envName string, id string, ctx cont
return utils.LogEnvironmentSilently(ctx, descEnvResp.GetPayload().Environment, describeLogPrefix), nil
}

func deleteEnvironmentWithDiagnosticHandle(environmentName string, ctx context.Context, client *cdp.Client, resp *resource.DeleteResponse, pollingOptions *utils.PollingOptions) error {
func deleteEnvironmentWithDiagnosticHandle(environmentName string, cascading bool, ctx context.Context, client *cdp.Client, resp *resource.DeleteResponse, pollingOptions *utils.PollingOptions) error {
params := operations.NewDeleteEnvironmentParamsWithContext(ctx)
params.WithInput(&environmentsmodels.DeleteEnvironmentRequest{EnvironmentName: &environmentName})
params.WithInput(&environmentsmodels.DeleteEnvironmentRequest{EnvironmentName: &environmentName, Cascading: cascading})
_, err := client.Environments.Operations.DeleteEnvironment(params)
if err != nil {
utils.AddEnvironmentDiagnosticsError(err, &resp.Diagnostics, "delete Environment")
return err
}

if pollingOptions != nil && pollingOptions.Async.ValueBool() {
return nil
}
err = waitForEnvironmentToBeDeleted(environmentName, timeoutOneHour, callFailureThreshold, client.Environments, ctx, pollingOptions)
if err != nil {
utils.AddEnvironmentDiagnosticsError(err, &resp.Diagnostics, "delete Environment")
Expand Down
2 changes: 2 additions & 0 deletions resources/environments/model_aws_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type awsEnvironmentResourceModel struct {

EnvironmentName types.String `tfsdk:"environment_name"`

Cascading types.Bool `tfsdk:"cascading_delete"`

FreeIpa types.Object `tfsdk:"freeipa"`

LogStorage *AWSLogStorage `tfsdk:"log_storage"`
Expand Down
2 changes: 2 additions & 0 deletions resources/environments/model_azure_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type azureEnvironmentResourceModel struct {

EnvironmentName types.String `tfsdk:"environment_name"`

Cascading types.Bool `tfsdk:"cascading_delete"`

ExistingNetworkParams types.Object `tfsdk:"existing_network_params"`

FreeIpa types.Object `tfsdk:"freeipa"`
Expand Down
2 changes: 2 additions & 0 deletions resources/environments/model_gcp_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
type gcpEnvironmentResourceModel struct {
EnvironmentName types.String `tfsdk:"environment_name"`

Cascading types.Bool `tfsdk:"cascading_delete"`

PollingOptions *utils.PollingOptions `tfsdk:"polling_options"`

CredentialName types.String `tfsdk:"credential_name"`
Expand Down
3 changes: 2 additions & 1 deletion resources/environments/polling.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import (
"context"
"errors"
"fmt"
"github.com/hashicorp/terraform-plugin-log/tflog"
"log"
"time"

"github.com/hashicorp/terraform-plugin-log/tflog"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"

"github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/gen/environments/client"
Expand Down
2 changes: 1 addition & 1 deletion resources/environments/resource_aws_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (r *awsEnvironmentResource) Delete(ctx context.Context, req resource.Delete
if resp.Diagnostics.HasError() {
return
}
if err := deleteEnvironmentWithDiagnosticHandle(state.EnvironmentName.ValueString(), ctx, r.client, resp, state.PollingOptions); err != nil {
if err := deleteEnvironmentWithDiagnosticHandle(state.EnvironmentName.ValueString(), state.Cascading.ValueBool(), ctx, r.client, resp, state.PollingOptions); err != nil {
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion resources/environments/resource_azure_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (r *azureEnvironmentResource) Delete(ctx context.Context, req resource.Dele
return
}

if err := deleteEnvironmentWithDiagnosticHandle(state.EnvironmentName.ValueString(), ctx, r.client, resp, state.PollingOptions); err != nil {
if err := deleteEnvironmentWithDiagnosticHandle(state.EnvironmentName.ValueString(), state.Cascading.ValueBool(), ctx, r.client, resp, state.PollingOptions); err != nil {
return
}
}
2 changes: 1 addition & 1 deletion resources/environments/resource_gcp_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (r *gcpEnvironmentResource) Delete(ctx context.Context, req resource.Delete
return
}

if err := deleteEnvironmentWithDiagnosticHandle(state.EnvironmentName.ValueString(), ctx, r.client, resp, state.PollingOptions); err != nil {
if err := deleteEnvironmentWithDiagnosticHandle(state.EnvironmentName.ValueString(), state.Cascading.ValueBool(), ctx, r.client, resp, state.PollingOptions); err != nil {
return
}
}
4 changes: 4 additions & 0 deletions resources/environments/schema_aws_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ var AwsEnvironmentSchema = schema.Schema{
"environment_name": schema.StringAttribute{
Required: true,
},
"cascading_delete": schema.BoolAttribute{
Optional: true,
Default: booldefault.StaticBool(true),
},
"freeipa": FreeIpaSchema,
"log_storage": schema.SingleNestedAttribute{
Required: true,
Expand Down
4 changes: 4 additions & 0 deletions resources/environments/schema_azure_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ var AzureEnvironmentSchema = schema.Schema{
"environment_name": schema.StringAttribute{
Required: true,
},
"cascading_delete": schema.BoolAttribute{
Optional: true,
Default: booldefault.StaticBool(true),
},
"existing_network_params": schema.SingleNestedAttribute{
Optional: true,
Computed: true,
Expand Down
4 changes: 4 additions & 0 deletions resources/environments/schema_gcp_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (r *gcpEnvironmentResource) Schema(_ context.Context, _ resource.SchemaRequ
MarkdownDescription: "The name of the environment. Must contain only lowercase letters, numbers and hyphens.",
Required: true,
},
"cascading_delete": schema.BoolAttribute{
Optional: true,
Default: booldefault.StaticBool(true),
},
"polling_options": schema.SingleNestedAttribute{
MarkdownDescription: "Polling related configuration options that could specify various values that will be used during CDP resource creation.",
Optional: true,
Expand Down

0 comments on commit dba37d2

Please sign in to comment.