@@ -70,6 +70,11 @@ func (r *clusterResource) Schema(ctx context.Context, request resource.SchemaReq
70
70
Default : booldefault .StaticBool (false ),
71
71
},
72
72
"encryption_details" : framework.ResourceComputedListOfObjectsAttribute [encryptionDetailsModel ](ctx ),
73
+ names .AttrForceDestroy : schema.BoolAttribute {
74
+ Optional : true ,
75
+ Computed : true ,
76
+ Default : booldefault .StaticBool (false ),
77
+ },
73
78
names .AttrIdentifier : framework .IDAttribute (),
74
79
"kms_encryption_key" : schema.StringAttribute {
75
80
Optional : true ,
@@ -313,6 +318,19 @@ func (r *clusterResource) Delete(ctx context.Context, request resource.DeleteReq
313
318
314
319
conn := r .Meta ().DSQLClient (ctx )
315
320
321
+ if data .ForceDestroy .ValueBool () {
322
+ input := dsql.UpdateClusterInput {
323
+ Identifier : data .Identifier .ValueStringPointer (),
324
+ DeletionProtectionEnabled : aws .Bool (false ),
325
+ ClientToken : aws .String (sdkid .UniqueId ()),
326
+ }
327
+ // Changing DeletionProtectionEnabled is instantaneous, no need to wait.
328
+ if _ , err := conn .UpdateCluster (ctx , & input ); err != nil {
329
+ response .Diagnostics .AddError (fmt .Sprintf ("disabling deletion protection for Aurora DSQL Cluster (%s)" , data .Identifier .ValueString ()), err .Error ())
330
+ return
331
+ }
332
+ }
333
+
316
334
id := fwflex .StringValueFromFramework (ctx , data .Identifier )
317
335
tflog .Debug (ctx , "deleting Aurora DSQL Cluster" , map [string ]any {
318
336
names .AttrIdentifier : id ,
@@ -342,6 +360,9 @@ func (r *clusterResource) Delete(ctx context.Context, request resource.DeleteReq
342
360
343
361
func (r * clusterResource ) ImportState (ctx context.Context , request resource.ImportStateRequest , response * resource.ImportStateResponse ) {
344
362
resource .ImportStatePassthroughID (ctx , path .Root (names .AttrIdentifier ), request , response )
363
+
364
+ // Set force_destroy to false on import to prevent accidental deletion
365
+ response .Diagnostics .Append (response .State .SetAttribute (ctx , path .Root (names .AttrForceDestroy ), types .BoolValue (false ))... )
345
366
}
346
367
347
368
func findClusterByID (ctx context.Context , conn * dsql.Client , id string ) (* dsql.GetClusterOutput , error ) {
@@ -445,10 +466,12 @@ func waitClusterUpdated(ctx context.Context, conn *dsql.Client, id string, timeo
445
466
446
467
func waitClusterDeleted (ctx context.Context , conn * dsql.Client , id string , timeout time.Duration ) (* dsql.GetClusterOutput , error ) {
447
468
stateConf := & retry.StateChangeConf {
448
- Pending : enum .Slice (awstypes .ClusterStatusDeleting , awstypes .ClusterStatusPendingDelete ),
449
- Target : []string {},
450
- Refresh : statusCluster (ctx , conn , id ),
451
- Timeout : timeout ,
469
+ Pending : enum .Slice (awstypes .ClusterStatusDeleting , awstypes .ClusterStatusPendingDelete ),
470
+ Target : []string {},
471
+ Refresh : statusCluster (ctx , conn , id ),
472
+ Timeout : timeout ,
473
+ Delay : 1 * time .Minute ,
474
+ PollInterval : 10 * time .Second ,
452
475
}
453
476
454
477
outputRaw , err := stateConf .WaitForStateContext (ctx )
@@ -526,6 +549,7 @@ type clusterResourceModel struct {
526
549
ARN types.String `tfsdk:"arn"`
527
550
DeletionProtectionEnabled types.Bool `tfsdk:"deletion_protection_enabled"`
528
551
EncryptionDetails fwtypes.ListNestedObjectValueOf [encryptionDetailsModel ] `tfsdk:"encryption_details"`
552
+ ForceDestroy types.Bool `tfsdk:"force_destroy"`
529
553
Identifier types.String `tfsdk:"identifier"`
530
554
KMSEncryptionKey types.String `tfsdk:"kms_encryption_key"`
531
555
MultiRegionProperties fwtypes.ListNestedObjectValueOf [multiRegionPropertiesModel ] `tfsdk:"multi_region_properties"`
0 commit comments