From 244cce65702ef62b6b94e9b5ee193510d29b963e Mon Sep 17 00:00:00 2001 From: A-Ashiq Date: Thu, 19 Dec 2024 09:43:17 +0000 Subject: [PATCH 1/2] Restart feedback API when rotating db password --- src/lambda-db-password-rotation/index.js | 1 + src/lambda-db-password-rotation/index.test.js | 2 ++ terraform/20-app/lambda.db-password-rotation.tf | 3 +++ 3 files changed, 6 insertions(+) diff --git a/src/lambda-db-password-rotation/index.js b/src/lambda-db-password-rotation/index.js index 2e2e45cb4..8a7658ad5 100644 --- a/src/lambda-db-password-rotation/index.js +++ b/src/lambda-db-password-rotation/index.js @@ -32,6 +32,7 @@ async function restartMainDbECSServices(ecsClient = new ECSClient(), overridenDe await dependencies.restartECSService(ecsClient, process.env.CMS_ADMIN_ECS_SERVICE_NAME) await dependencies.restartECSService(ecsClient, process.env.PRIVATE_API_ECS_SERVICE_NAME) await dependencies.restartECSService(ecsClient, process.env.PUBLIC_API_ECS_SERVICE_NAME) + await dependencies.restartECSService(ecsClient, process.env.FEEDBACK_API_ECS_SERVICE_NAME) console.log(`All required ECS tasks have been restarted for main DB`); }; diff --git a/src/lambda-db-password-rotation/index.test.js b/src/lambda-db-password-rotation/index.test.js index 5284d9245..e0706678d 100644 --- a/src/lambda-db-password-rotation/index.test.js +++ b/src/lambda-db-password-rotation/index.test.js @@ -58,12 +58,14 @@ describe('restartMainDbECSServices', () => { const fakeCMSAdminECSServiceName = 'fake-cms-admin-ecs-service-name' const fakePrivateAPIECSServiceName = 'fake-private-api-ecs-service-name' const fakePublicAPIECSServiceName = 'fake-public-api-ecs-service-name' + const fakeFeedbackAPIECSServiceName = 'fake-feedback-api-ecs-service-name' const mockedEnvVar = sinon.stub(process, 'env').value( { CMS_ADMIN_ECS_SERVICE_NAME: fakeCMSAdminECSServiceName, PRIVATE_API_ECS_SERVICE_NAME: fakePrivateAPIECSServiceName, PUBLIC_API_ECS_SERVICE_NAME: fakePublicAPIECSServiceName, + FEEDBACK_API_ECS_SERVICE_NAME: fakeFeedbackAPIECSServiceName, } ); diff --git a/terraform/20-app/lambda.db-password-rotation.tf b/terraform/20-app/lambda.db-password-rotation.tf index 7a67c35cf..555b04255 100644 --- a/terraform/20-app/lambda.db-password-rotation.tf +++ b/terraform/20-app/lambda.db-password-rotation.tf @@ -19,6 +19,7 @@ module "lambda_db_password_rotation" { CMS_ADMIN_ECS_SERVICE_NAME = module.ecs_service_cms_admin.name PRIVATE_API_ECS_SERVICE_NAME = module.ecs_service_private_api.name PUBLIC_API_ECS_SERVICE_NAME = module.ecs_service_public_api.name + FEEDBACK_API_ECS_SERVICE_NAME = module.ecs_service_feedback_api.name FEATURE_FLAGS_ECS_SERVICE_NAME = module.ecs_service_feature_flags.name } @@ -31,7 +32,9 @@ module "lambda_db_password_rotation" { module.ecs_service_private_api.id, module.ecs_service_public_api.id, module.ecs_service_cms_admin.id, + module.ecs_service_feedback_api.id, module.ecs_service_feature_flags.id, + ] } } From 62fa94d4af3201929ffe86576a1d1bfc6d393d8b Mon Sep 17 00:00:00 2001 From: A-Ashiq Date: Thu, 19 Dec 2024 09:50:59 +0000 Subject: [PATCH 2/2] Update test --- src/lambda-db-password-rotation/index.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lambda-db-password-rotation/index.test.js b/src/lambda-db-password-rotation/index.test.js index e0706678d..d54749f3b 100644 --- a/src/lambda-db-password-rotation/index.test.js +++ b/src/lambda-db-password-rotation/index.test.js @@ -80,12 +80,11 @@ describe('restartMainDbECSServices', () => { await restartMainDbECSServices(mockedECSClient, spyDependencies); // Then - // The function should have been called 3 times, 1 for each ECS service - expect(restartECSServiceSpy.calledThrice).toBeTruthy(); // The function should have been called with each ECS service name expect(restartECSServiceSpy.firstCall.lastArg).toEqual(fakeCMSAdminECSServiceName) expect(restartECSServiceSpy.secondCall.lastArg).toEqual(fakePrivateAPIECSServiceName) expect(restartECSServiceSpy.thirdCall.lastArg).toEqual(fakePublicAPIECSServiceName) + expect(restartECSServiceSpy.lastCall.lastArg).toEqual(fakeFeedbackAPIECSServiceName) // Restore the environment variable mockedEnvVar.restore();