From b3d824d30543ceb182c257ea757b7593fb5f464b Mon Sep 17 00:00:00 2001 From: Christopher Watanabe <91735518+christopher-watanabe-snkeos@users.noreply.github.com> Date: Wed, 3 Jul 2024 15:41:11 +0200 Subject: [PATCH] feat: Remove LogGroups and export table on stack deletion (#9) --- solutions/deployment/lib/bulkExportStateMachine.ts | 5 +++-- solutions/deployment/lib/cdk-infra-stack.ts | 3 ++- solutions/deployment/lib/elasticsearch.ts | 3 ++- .../smart-deployment/src/lib/bulkExportStateMachine.ts | 5 +++-- solutions/smart-deployment/src/lib/cdk-infra-stack.ts | 8 +++++--- solutions/smart-deployment/src/lib/elasticsearch.ts | 5 +++-- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/solutions/deployment/lib/bulkExportStateMachine.ts b/solutions/deployment/lib/bulkExportStateMachine.ts index 7a90b39c..9580fc0b 100644 --- a/solutions/deployment/lib/bulkExportStateMachine.ts +++ b/solutions/deployment/lib/bulkExportStateMachine.ts @@ -1,4 +1,4 @@ -import { Duration } from 'aws-cdk-lib'; +import { Duration, RemovalPolicy } from 'aws-cdk-lib'; import { Key } from 'aws-cdk-lib/aws-kms'; import { Function } from 'aws-cdk-lib/aws-lambda'; import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs'; @@ -109,7 +109,8 @@ export default class BulkExportStateMachine { destination: new LogGroup(scope, 'bulkExportStateMachineLogs', { logGroupName: `BulkExportSM-Logs-${stage}`, encryptionKey: logKMSKey, - retention: RetentionDays.TEN_YEARS + retention: RetentionDays.TEN_YEARS, + removalPolicy: RemovalPolicy.DESTROY }), }, }); diff --git a/solutions/deployment/lib/cdk-infra-stack.ts b/solutions/deployment/lib/cdk-infra-stack.ts index 6f9cd7c4..4876dd43 100644 --- a/solutions/deployment/lib/cdk-infra-stack.ts +++ b/solutions/deployment/lib/cdk-infra-stack.ts @@ -351,7 +351,8 @@ export default class FhirWorksStack extends Stack { const apiGatewayLogGroup = new LogGroup(this, 'apiGatewayLogGroup', { encryptionKey: kmsResources.logKMSKey, logGroupName: `/aws/api-gateway/fhir-service-${props!.stage}`, - retention: RetentionDays.TEN_YEARS + retention: RetentionDays.TEN_YEARS, + removalPolicy: RemovalPolicy.DESTROY }); const apiGatewayRestApi = new RestApi(this, 'apiGatewayRestApi', { diff --git a/solutions/deployment/lib/elasticsearch.ts b/solutions/deployment/lib/elasticsearch.ts index 048b14a1..fbc98aa0 100644 --- a/solutions/deployment/lib/elasticsearch.ts +++ b/solutions/deployment/lib/elasticsearch.ts @@ -256,7 +256,8 @@ export default class ElasticSearchResources { this.searchLogs = new LogGroup(scope, 'searchLogs', { logGroupName: `${stackName}-search-logs`, encryptionKey: elasticSearchKMSKey, - retention: RetentionDays.TEN_YEARS + retention: RetentionDays.TEN_YEARS, + removalPolicy: RemovalPolicy.DESTROY }); this.searchLogsResourcePolicy = new ResourcePolicy(scope, 'searchLogsResourcePolicy', { diff --git a/solutions/smart-deployment/src/lib/bulkExportStateMachine.ts b/solutions/smart-deployment/src/lib/bulkExportStateMachine.ts index fc5a24f9..f82d7298 100644 --- a/solutions/smart-deployment/src/lib/bulkExportStateMachine.ts +++ b/solutions/smart-deployment/src/lib/bulkExportStateMachine.ts @@ -1,4 +1,4 @@ -import { Duration } from 'aws-cdk-lib'; +import { Duration, RemovalPolicy } from 'aws-cdk-lib'; import { Key } from 'aws-cdk-lib/aws-kms'; import { Function } from 'aws-cdk-lib/aws-lambda'; import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs'; @@ -110,7 +110,8 @@ export default class BulkExportStateMachine { destination: new LogGroup(scope, 'bulkExportStateMachineLogs', { logGroupName: `BulkExportSM-Logs-${stage}`, encryptionKey: logKMSKey, - retention: RetentionDays.TEN_YEARS + retention: RetentionDays.TEN_YEARS, + removalPolicy: RemovalPolicy.DESTROY }), }, }); diff --git a/solutions/smart-deployment/src/lib/cdk-infra-stack.ts b/solutions/smart-deployment/src/lib/cdk-infra-stack.ts index a0dbad00..56699c78 100644 --- a/solutions/smart-deployment/src/lib/cdk-infra-stack.ts +++ b/solutions/smart-deployment/src/lib/cdk-infra-stack.ts @@ -202,7 +202,8 @@ export default class FhirWorksStack extends Stack { encryption: TableEncryption.CUSTOMER_MANAGED, encryptionKey: kmsResources.dynamoDbKMSKey, billingMode: BillingMode.PAY_PER_REQUEST, - pointInTimeRecovery: true + pointInTimeRecovery: true, + RemovalPolicy: RemovalPolicy.DESTROY }); exportRequestDynamoDbTable.addGlobalSecondaryIndex({ indexName: exportRequestTableJobStatusIndex, @@ -261,7 +262,7 @@ export default class FhirWorksStack extends Stack { versioned: true, encryption: BucketEncryption.KMS, encryptionKey: kmsResources.s3KMSKey, - removalPolicy: RemovalPolicy.RETAIN, + removalPolicy: RemovalPolicy.DESTROY, blockPublicAccess: { blockPublicAcls: true, blockPublicPolicy: true, @@ -298,7 +299,8 @@ export default class FhirWorksStack extends Stack { const apiGatewayLogGroup = new LogGroup(this, 'apiGatewayLogGroup', { encryptionKey: kmsResources.logKMSKey, logGroupName: `/aws/api-gateway/fhir-service-${props!.stage}`, - retention: RetentionDays.TEN_YEARS + retention: RetentionDays.TEN_YEARS, + removalPolicy: RemovalPolicy.DESTROY }); const apiGatewayRestApi = new RestApi(this, 'apiGatewayRestApi', { diff --git a/solutions/smart-deployment/src/lib/elasticsearch.ts b/solutions/smart-deployment/src/lib/elasticsearch.ts index 232c6b60..cebc383a 100644 --- a/solutions/smart-deployment/src/lib/elasticsearch.ts +++ b/solutions/smart-deployment/src/lib/elasticsearch.ts @@ -1,4 +1,4 @@ -import { CfnMapping } from 'aws-cdk-lib'; +import { CfnMapping, RemovalPolicy } from 'aws-cdk-lib'; import { Domain, EngineVersion } from 'aws-cdk-lib/aws-opensearchservice'; import { CfnUserPool, @@ -249,7 +249,8 @@ export default class ElasticSearchResources { this.searchLogs = new LogGroup(scope, 'searchLogs', { logGroupName: `${stackName}-search-logs`, encryptionKey: elasticSearchKMSKey, - retention: RetentionDays.TEN_YEARS + retention: RetentionDays.TEN_YEARS, + removalPolicy: RemovalPolicy.DESTROY }); this.searchLogsResourcePolicy = new ResourcePolicy(scope, 'searchLogsResourcePolicy', {