From cca02de21b04eacdad28d16410108100f1bb14cb Mon Sep 17 00:00:00 2001 From: Nicolas PELLEGRIN Date: Mon, 25 Nov 2024 00:31:13 +0100 Subject: [PATCH] fix(bedrockagent): set Bedrock Datasource data deletion policy to RETAIN before deleting it --- resources/bedrock-agent-datasource.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/resources/bedrock-agent-datasource.go b/resources/bedrock-agent-datasource.go index 8f73eadb..40061dce 100644 --- a/resources/bedrock-agent-datasource.go +++ b/resources/bedrock-agent-datasource.go @@ -101,11 +101,32 @@ func (r *BedrockDataSource) Properties() types.Properties { } func (r *BedrockDataSource) Remove(_ context.Context) error { - _, err := r.svc.DeleteDataSource(&bedrockagent.DeleteDataSourceInput{ + // Must set retention to RETAIN to be able to delete datasource when data is already removed + // Reference: https://github.com/ekristen/aws-nuke/issues/431 + current, err := r.svc.GetDataSource(&bedrockagent.GetDataSourceInput{ + DataSourceId: r.ID, + KnowledgeBaseId: r.KnowledgeBaseID, + }) + if err != nil { + return err + } + _, err = r.svc.UpdateDataSource(&bedrockagent.UpdateDataSourceInput{ + DataDeletionPolicy: aws.String(bedrockagent.DataDeletionPolicyRetain), + DataSourceConfiguration: current.DataSource.DataSourceConfiguration, + DataSourceId: r.ID, + Description: current.DataSource.Description, + KnowledgeBaseId: r.KnowledgeBaseID, + Name: current.DataSource.Name, + ServerSideEncryptionConfiguration: current.DataSource.ServerSideEncryptionConfiguration, + VectorIngestionConfiguration: current.DataSource.VectorIngestionConfiguration, + }) + if err != nil { + return err + } + _, err = r.svc.DeleteDataSource(&bedrockagent.DeleteDataSourceInput{ DataSourceId: r.ID, KnowledgeBaseId: r.KnowledgeBaseID, }) - return err }