@@ -19,6 +19,7 @@ import (
19
19
"github.com/hashicorp/terraform-plugin-framework/path"
20
20
"github.com/hashicorp/terraform-plugin-framework/resource"
21
21
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
22
+ "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
22
23
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
23
24
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
24
25
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
@@ -43,6 +44,7 @@ import (
43
44
// @Tags(identifierAttribute="arn")
44
45
// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/dsql;dsql.GetClusterOutput")
45
46
// @Testing(importStateIdAttribute="identifier")
47
+ // @Testing(generator=false)
46
48
func newClusterResource (_ context.Context ) (resource.ResourceWithConfigure , error ) {
47
49
r := & clusterResource {}
48
50
@@ -64,8 +66,15 @@ func (r *clusterResource) Schema(ctx context.Context, request resource.SchemaReq
64
66
names .AttrARN : framework .ARNAttributeComputedOnly (),
65
67
"deletion_protection_enabled" : schema.BoolAttribute {
66
68
Optional : true ,
69
+ Computed : true ,
70
+ Default : booldefault .StaticBool (false ),
67
71
},
68
72
"encryption_details" : framework.ResourceComputedListOfObjectsAttribute [encryptionDetailsModel ](ctx ),
73
+ names .AttrForceDestroy : schema.BoolAttribute {
74
+ Optional : true ,
75
+ Computed : true ,
76
+ Default : booldefault .StaticBool (false ),
77
+ },
69
78
names .AttrIdentifier : framework .IDAttribute (),
70
79
"kms_encryption_key" : schema.StringAttribute {
71
80
Optional : true ,
@@ -309,6 +318,19 @@ func (r *clusterResource) Delete(ctx context.Context, request resource.DeleteReq
309
318
310
319
conn := r .Meta ().DSQLClient (ctx )
311
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
+
312
334
id := fwflex .StringValueFromFramework (ctx , data .Identifier )
313
335
tflog .Debug (ctx , "deleting Aurora DSQL Cluster" , map [string ]any {
314
336
names .AttrIdentifier : id ,
@@ -338,6 +360,9 @@ func (r *clusterResource) Delete(ctx context.Context, request resource.DeleteReq
338
360
339
361
func (r * clusterResource ) ImportState (ctx context.Context , request resource.ImportStateRequest , response * resource.ImportStateResponse ) {
340
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 ))... )
341
366
}
342
367
343
368
func findClusterByID (ctx context.Context , conn * dsql.Client , id string ) (* dsql.GetClusterOutput , error ) {
@@ -441,10 +466,12 @@ func waitClusterUpdated(ctx context.Context, conn *dsql.Client, id string, timeo
441
466
442
467
func waitClusterDeleted (ctx context.Context , conn * dsql.Client , id string , timeout time.Duration ) (* dsql.GetClusterOutput , error ) {
443
468
stateConf := & retry.StateChangeConf {
444
- Pending : enum .Slice (awstypes .ClusterStatusDeleting , awstypes .ClusterStatusPendingDelete ),
445
- Target : []string {},
446
- Refresh : statusCluster (ctx , conn , id ),
447
- 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 ,
448
475
}
449
476
450
477
outputRaw , err := stateConf .WaitForStateContext (ctx )
@@ -522,6 +549,7 @@ type clusterResourceModel struct {
522
549
ARN types.String `tfsdk:"arn"`
523
550
DeletionProtectionEnabled types.Bool `tfsdk:"deletion_protection_enabled"`
524
551
EncryptionDetails fwtypes.ListNestedObjectValueOf [encryptionDetailsModel ] `tfsdk:"encryption_details"`
552
+ ForceDestroy types.Bool `tfsdk:"force_destroy"`
525
553
Identifier types.String `tfsdk:"identifier"`
526
554
KMSEncryptionKey types.String `tfsdk:"kms_encryption_key"`
527
555
MultiRegionProperties fwtypes.ListNestedObjectValueOf [multiRegionPropertiesModel ] `tfsdk:"multi_region_properties"`
0 commit comments