diff --git a/resources/datalake/resource_aws_datalake.go b/resources/datalake/resource_aws_datalake.go index a8d37a49..a4bb0159 100644 --- a/resources/datalake/resource_aws_datalake.go +++ b/resources/datalake/resource_aws_datalake.go @@ -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 { diff --git a/resources/datalake/resource_azure_datalake.go b/resources/datalake/resource_azure_datalake.go index ab54f697..5f965dbd 100644 --- a/resources/datalake/resource_azure_datalake.go +++ b/resources/datalake/resource_azure_datalake.go @@ -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 } + } diff --git a/resources/datalake/resource_gcp_datalake.go b/resources/datalake/resource_gcp_datalake.go index 70ed0bb3..3553c9c5 100644 --- a/resources/datalake/resource_gcp_datalake.go +++ b/resources/datalake/resource_gcp_datalake.go @@ -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 } + } diff --git a/resources/environments/environment_action_util.go b/resources/environments/environment_action_util.go index 426e6435..f261e399 100644 --- a/resources/environments/environment_action_util.go +++ b/resources/environments/environment_action_util.go @@ -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") diff --git a/resources/environments/model_aws_environment.go b/resources/environments/model_aws_environment.go index 355de0a2..0f856c7f 100644 --- a/resources/environments/model_aws_environment.go +++ b/resources/environments/model_aws_environment.go @@ -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"` diff --git a/resources/environments/model_azure_environment.go b/resources/environments/model_azure_environment.go index 3aa8701c..9fbddded 100644 --- a/resources/environments/model_azure_environment.go +++ b/resources/environments/model_azure_environment.go @@ -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"` diff --git a/resources/environments/model_gcp_environment.go b/resources/environments/model_gcp_environment.go index fe38a2ad..f9f29f56 100644 --- a/resources/environments/model_gcp_environment.go +++ b/resources/environments/model_gcp_environment.go @@ -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"` diff --git a/resources/environments/polling.go b/resources/environments/polling.go index 5a75d711..9778257f 100644 --- a/resources/environments/polling.go +++ b/resources/environments/polling.go @@ -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" diff --git a/resources/environments/resource_aws_environment.go b/resources/environments/resource_aws_environment.go index 26e8e7d4..5e476f08 100644 --- a/resources/environments/resource_aws_environment.go +++ b/resources/environments/resource_aws_environment.go @@ -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 } } diff --git a/resources/environments/resource_azure_environment.go b/resources/environments/resource_azure_environment.go index 4f33cf75..b7367c0e 100644 --- a/resources/environments/resource_azure_environment.go +++ b/resources/environments/resource_azure_environment.go @@ -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 } } diff --git a/resources/environments/resource_gcp_environment.go b/resources/environments/resource_gcp_environment.go index ed4b59d9..2f9f303c 100644 --- a/resources/environments/resource_gcp_environment.go +++ b/resources/environments/resource_gcp_environment.go @@ -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 } } diff --git a/resources/environments/schema_aws_environment.go b/resources/environments/schema_aws_environment.go index 218bb6e6..6ce1420e 100644 --- a/resources/environments/schema_aws_environment.go +++ b/resources/environments/schema_aws_environment.go @@ -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, diff --git a/resources/environments/schema_azure_environment.go b/resources/environments/schema_azure_environment.go index 4397ea8b..0a9faf01 100644 --- a/resources/environments/schema_azure_environment.go +++ b/resources/environments/schema_azure_environment.go @@ -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, diff --git a/resources/environments/schema_gcp_environment.go b/resources/environments/schema_gcp_environment.go index 960699c6..f07c8953 100644 --- a/resources/environments/schema_gcp_environment.go +++ b/resources/environments/schema_gcp_environment.go @@ -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,