From e9886dfcbcf4c4d18cfae9956bc47d829e9bcea9 Mon Sep 17 00:00:00 2001 From: Shilpi Goel Date: Wed, 8 Jan 2025 17:07:28 +0000 Subject: [PATCH 1/9] added latest Mou endpoint --- .../Api/Organisation.cs | 32 ++++++++++++++++++- .../CO.CDP.Organisation.WebApi/Program.cs | 7 +++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs b/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs index ae2aa56b6..76276a0c2 100644 --- a/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs +++ b/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs @@ -928,7 +928,7 @@ await useCase.Execute((organisationId, keyName)) return app; } - public static RouteGroupBuilder UseMouEndpoints(this RouteGroupBuilder app) + public static RouteGroupBuilder UseOrganisationMouEndpoints(this RouteGroupBuilder app) { app.MapGet("/{organisationId}/mou", [OrganisationAuthorize( @@ -1040,6 +1040,36 @@ await useCase.Execute((organisationId, signMou)) return app; } + public static RouteGroupBuilder UseMouEndpoints(this RouteGroupBuilder app) + { + app.MapGet("/latest", + [OrganisationAuthorize( + [AuthenticationChannel.OneLogin], + [Constants.OrganisationPersonScope.Admin], + OrganisationIdLocation.Path)] + async (IUseCase useCase) => + await useCase.Execute() + .AndThen(mouLatest => mouLatest != null ? Results.Ok(mouLatest) : Results.NotFound())) + .Produces(StatusCodes.Status200OK, "application/json") + .Produces(StatusCodes.Status401Unauthorized) + .Produces(StatusCodes.Status404NotFound) + .ProducesProblem(StatusCodes.Status422UnprocessableEntity) + .Produces(StatusCodes.Status500InternalServerError) + .WithOpenApi(operation => + { + operation.OperationId = "GetLatestMou"; + operation.Description = "Get Latest MOU."; + operation.Summary = "Get Latest MOU to sign."; + operation.Responses["200"].Description = "Latest MOU."; + operation.Responses["401"].Description = "Valid authentication credentials are missing in the request."; + operation.Responses["404"].Description = "Latest Mou information not found."; + operation.Responses["422"].Description = "Unprocessable entity."; + operation.Responses["500"].Description = "Internal server error."; + return operation; + }); + return app; + } + public static RouteGroupBuilder UseOrganisationPartiesEndpoints(this RouteGroupBuilder app) { app.MapGet("/{organisationId}/parties", diff --git a/Services/CO.CDP.Organisation.WebApi/Program.cs b/Services/CO.CDP.Organisation.WebApi/Program.cs index dfb05b866..e37ce56a2 100644 --- a/Services/CO.CDP.Organisation.WebApi/Program.cs +++ b/Services/CO.CDP.Organisation.WebApi/Program.cs @@ -184,8 +184,13 @@ .WithTags("Feedback - provide feedback"); app.MapGroup("/organisations") - .UseMouEndpoints() + .UseOrganisationMouEndpoints() .WithTags("Organisation - MOUs"); +app.MapGroup("/mou") + .UseMouEndpoints() + .WithTags("Mou"); + + app.Run(); public abstract partial class Program; \ No newline at end of file From 54c60903564c2238f4510b9da121f26282a987d1 Mon Sep 17 00:00:00 2001 From: Shilpi Goel Date: Wed, 8 Jan 2025 17:10:57 +0000 Subject: [PATCH 2/9] Added usecase for endpoint --- .../Api/Organisation.cs | 2 +- Services/CO.CDP.Organisation.WebApi/Program.cs | 1 + .../UseCase/GetLatestMouUseCase.cs | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Services/CO.CDP.Organisation.WebApi/UseCase/GetLatestMouUseCase.cs diff --git a/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs b/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs index 76276a0c2..aad022b5f 100644 --- a/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs +++ b/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs @@ -1047,7 +1047,7 @@ public static RouteGroupBuilder UseMouEndpoints(this RouteGroupBuilder app) [AuthenticationChannel.OneLogin], [Constants.OrganisationPersonScope.Admin], OrganisationIdLocation.Path)] - async (IUseCase useCase) => + async (IUseCase useCase) => await useCase.Execute() .AndThen(mouLatest => mouLatest != null ? Results.Ok(mouLatest) : Results.NotFound())) .Produces(StatusCodes.Status200OK, "application/json") diff --git a/Services/CO.CDP.Organisation.WebApi/Program.cs b/Services/CO.CDP.Organisation.WebApi/Program.cs index e37ce56a2..baac4b0df 100644 --- a/Services/CO.CDP.Organisation.WebApi/Program.cs +++ b/Services/CO.CDP.Organisation.WebApi/Program.cs @@ -108,6 +108,7 @@ builder.Services.AddScoped, GetOrganisationMouSignatureUseCase>(); builder.Services.AddScoped, GetOrganisationMouSignatureLatestUseCase>(); builder.Services.AddScoped, SignOrganisationMouUseCase>(); +builder.Services.AddScoped, GetLatestMouUseCase>(); builder.Services.AddProblemDetails(); diff --git a/Services/CO.CDP.Organisation.WebApi/UseCase/GetLatestMouUseCase.cs b/Services/CO.CDP.Organisation.WebApi/UseCase/GetLatestMouUseCase.cs new file mode 100644 index 000000000..3672e9a41 --- /dev/null +++ b/Services/CO.CDP.Organisation.WebApi/UseCase/GetLatestMouUseCase.cs @@ -0,0 +1,18 @@ +using AutoMapper; +using CO.CDP.Functional; +using CO.CDP.Organisation.WebApi.Model; +using CO.CDP.OrganisationInformation.Persistence; + +namespace CO.CDP.Organisation.WebApi.UseCase; + +public class GetLatestMouUseCase(IOrganisationRepository organisationRepository, IMapper mapper) + : IUseCase +{ + public async Task Execute() + { + var latestMou = await organisationRepository.GetLatestMou() + ?? throw new UnknownMouException($"No MOU found."); + + return mapper.Map(latestMou); + } +} \ No newline at end of file From e38516edc18d0391ef00eba6a926e1c0eaa1189f Mon Sep 17 00:00:00 2001 From: Shilpi Goel Date: Thu, 9 Jan 2025 10:30:05 +0000 Subject: [PATCH 3/9] added unit tests --- .../UseCase/GetLatestMouUseCaseTest.cs | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetLatestMouUseCaseTest.cs diff --git a/Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetLatestMouUseCaseTest.cs b/Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetLatestMouUseCaseTest.cs new file mode 100644 index 000000000..ee964c826 --- /dev/null +++ b/Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetLatestMouUseCaseTest.cs @@ -0,0 +1,146 @@ +using AutoMapper; +using CO.CDP.Organisation.WebApi.Model; +using CO.CDP.Organisation.WebApi.Tests.AutoMapper; +using CO.CDP.Organisation.WebApi.UseCase; +using CO.CDP.OrganisationInformation; +using CO.CDP.OrganisationInformation.Persistence; +using FluentAssertions; +using Moq; +using Persistence = CO.CDP.OrganisationInformation.Persistence; +using Person = CO.CDP.OrganisationInformation.Persistence.Person; + +namespace CO.CDP.Organisation.WebApi.Tests.UseCase; + +public class GetLatestMouUseCaseTest(AutoMapperFixture mapperFixture) + : IClassFixture +{ + private readonly Mock _organisationRepository = new(); + private GetLatestMouUseCase _useCase => new GetLatestMouUseCase(_organisationRepository.Object, mapperFixture.Mapper); + + [Fact] + public async Task Execute_ShouldReturnMappedMou_WhenLatestMouExists() + { + var latestMouEntity = new Persistence.Mou + { + Id = 1, + Guid = Guid.NewGuid(), + FilePath = "/path/to/mou.pdf", + CreatedOn = DateTimeOffset.UtcNow, + UpdatedOn = DateTimeOffset.UtcNow + }; + + var mappedMou = new CO.CDP.Organisation.WebApi.Model.Mou + { + Id = latestMouEntity.Guid, + FilePath = latestMouEntity.FilePath, + CreatedOn = latestMouEntity.CreatedOn + }; + + _organisationRepository + .Setup(repo => repo.GetLatestMou()) + .ReturnsAsync(latestMouEntity); + + var result = await _useCase.Execute(); + + // Assert + result.Should().BeEquivalentTo(mappedMou); + + _organisationRepository.Verify(repo => repo.GetLatestMou(), Times.Once); + } + + [Fact] + public async Task Execute_ShouldThrowUnknownMouException_WhenLatestMouIsNull() + { + _organisationRepository + .Setup(repo => repo.GetLatestMou()) + .ReturnsAsync((Persistence.Mou)null!); + + Func act = async () => await _useCase.Execute(); + + await act.Should().ThrowAsync() + .WithMessage("No MOU found."); + + _organisationRepository.Verify(repo => repo.GetLatestMou(), Times.Once); + } + + public static Person FakePerson( + Guid? guid = null, + string? userUrn = null, + string firstname = "Jon", + string lastname = "doe", + string? email = null, + string phone = "07925123123", + List? scopes = null, + Tenant? tenant = null, + List<(Persistence.Organisation, List)>? organisationsWithScope = null +) + { + scopes = scopes ?? []; + var personGuid = guid ?? Guid.NewGuid(); + var person = new Person + { + Guid = personGuid, + UserUrn = userUrn ?? $"urn:fdc:gov.uk:2022:{Guid.NewGuid()}", + FirstName = firstname, + LastName = lastname, + Email = email ?? $"jon{personGuid}@example.com", + Phone = phone, + Scopes = scopes + }; + if (tenant != null) + { + person.Tenants.Add(tenant); + } + + foreach (var organisationWithScope in organisationsWithScope ?? []) + { + person.PersonOrganisations.Add( + new OrganisationPerson + { + Person = person, + Organisation = organisationWithScope.Item1, + Scopes = organisationWithScope.Item2 + } + ); + } + + return person; + } + + private static Persistence.Organisation FakeOrganisation(bool? withBuyerInfo = true) + { + Persistence.Organisation org = new() + { + Id = 1, + Guid = Guid.NewGuid(), + Name = "FakeOrg", + Tenant = new Tenant + { + Guid = Guid.NewGuid(), + Name = "Tenant 101" + }, + ContactPoints = + [ + new Persistence.Organisation.ContactPoint + { + Email = "contact@test.org" + } + ], + Type = OrganisationType.Organisation + }; + + if (withBuyerInfo == true) + { + var devolvedRegulations = new List(); + devolvedRegulations.Add(DevolvedRegulation.NorthernIreland); + + org.BuyerInfo = new Persistence.Organisation.BuyerInformation + { + BuyerType = "FakeBuyerType", + DevolvedRegulations = devolvedRegulations, + }; + } + + return org; + } +} \ No newline at end of file From 36110175ef8d5ed0dc1b304f1b39fa91eb774c62 Mon Sep 17 00:00:00 2001 From: Shilpi Goel Date: Thu, 9 Jan 2025 11:32:34 +0000 Subject: [PATCH 4/9] New endpoint GET mou/{mouid} and GET mou/latest --- .../UseCase/GetLatestMouUseCaseTest.cs | 3 +- .../UseCase/GetMouUseCaseTest.cs | 147 ++++++++++++++++++ .../Api/Organisation.cs | 39 ++++- .../CO.CDP.Organisation.WebApi/Program.cs | 1 + .../UseCase/GetMouUseCase.cs | 18 +++ 5 files changed, 201 insertions(+), 7 deletions(-) create mode 100644 Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetMouUseCaseTest.cs create mode 100644 Services/CO.CDP.Organisation.WebApi/UseCase/GetMouUseCase.cs diff --git a/Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetLatestMouUseCaseTest.cs b/Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetLatestMouUseCaseTest.cs index ee964c826..010c06c08 100644 --- a/Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetLatestMouUseCaseTest.cs +++ b/Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetLatestMouUseCaseTest.cs @@ -41,8 +41,7 @@ public async Task Execute_ShouldReturnMappedMou_WhenLatestMouExists() .ReturnsAsync(latestMouEntity); var result = await _useCase.Execute(); - - // Assert + result.Should().BeEquivalentTo(mappedMou); _organisationRepository.Verify(repo => repo.GetLatestMou(), Times.Once); diff --git a/Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetMouUseCaseTest.cs b/Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetMouUseCaseTest.cs new file mode 100644 index 000000000..3253355bb --- /dev/null +++ b/Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetMouUseCaseTest.cs @@ -0,0 +1,147 @@ +using AutoMapper; +using CO.CDP.Organisation.WebApi.Model; +using CO.CDP.Organisation.WebApi.Tests.AutoMapper; +using CO.CDP.Organisation.WebApi.UseCase; +using CO.CDP.OrganisationInformation; +using CO.CDP.OrganisationInformation.Persistence; +using FluentAssertions; +using Moq; +using Persistence = CO.CDP.OrganisationInformation.Persistence; +using Person = CO.CDP.OrganisationInformation.Persistence.Person; + +namespace CO.CDP.Organisation.WebApi.Tests.UseCase; + +public class GetMouUseCaseTest(AutoMapperFixture mapperFixture) + : IClassFixture +{ + private readonly Mock _organisationRepository = new(); + private GetMouUseCase _useCase => new GetMouUseCase(_organisationRepository.Object, mapperFixture.Mapper); + + [Fact] + public async Task Execute_ShouldReturnMappedMou_WhenLatestMouExists() + { + var mouId = Guid.NewGuid(); + var mouEntity = new Persistence.Mou + { + Id = 1, + Guid = mouId, + FilePath = "/path/to/mou.pdf", + CreatedOn = DateTimeOffset.UtcNow, + UpdatedOn = DateTimeOffset.UtcNow + }; + + var mappedMou = new Model.Mou + { + Id = mouId, + FilePath = mouEntity.FilePath, + CreatedOn = mouEntity.CreatedOn + }; + + _organisationRepository + .Setup(repo => repo.GetMou(mouId)) + .ReturnsAsync(mouEntity); + + var result = await _useCase.Execute(mouId); + + result.Should().BeEquivalentTo(mappedMou); + + _organisationRepository.Verify(repo => repo.GetMou(mouId), Times.Once); + } + + [Fact] + public async Task Execute_ShouldThrowUnknownMouException_WhenLatestMouIsNull() + { + var mouId = Guid.NewGuid(); + _organisationRepository + .Setup(repo => repo.GetMou(mouId)) + .ReturnsAsync((Persistence.Mou)null!); + + Func act = async () => await _useCase.Execute(mouId); + + await act.Should().ThrowAsync() + .WithMessage("No MOU found."); + + _organisationRepository.Verify(repo => repo.GetMou(mouId), Times.Once); + } + + public static Person FakePerson( + Guid? guid = null, + string? userUrn = null, + string firstname = "Jon", + string lastname = "doe", + string? email = null, + string phone = "07925123123", + List? scopes = null, + Tenant? tenant = null, + List<(Persistence.Organisation, List)>? organisationsWithScope = null +) + { + scopes = scopes ?? []; + var personGuid = guid ?? Guid.NewGuid(); + var person = new Person + { + Guid = personGuid, + UserUrn = userUrn ?? $"urn:fdc:gov.uk:2022:{Guid.NewGuid()}", + FirstName = firstname, + LastName = lastname, + Email = email ?? $"jon{personGuid}@example.com", + Phone = phone, + Scopes = scopes + }; + if (tenant != null) + { + person.Tenants.Add(tenant); + } + + foreach (var organisationWithScope in organisationsWithScope ?? []) + { + person.PersonOrganisations.Add( + new OrganisationPerson + { + Person = person, + Organisation = organisationWithScope.Item1, + Scopes = organisationWithScope.Item2 + } + ); + } + + return person; + } + + private static Persistence.Organisation FakeOrganisation(bool? withBuyerInfo = true) + { + Persistence.Organisation org = new() + { + Id = 1, + Guid = Guid.NewGuid(), + Name = "FakeOrg", + Tenant = new Tenant + { + Guid = Guid.NewGuid(), + Name = "Tenant 101" + }, + ContactPoints = + [ + new Persistence.Organisation.ContactPoint + { + Email = "contact@test.org" + } + ], + Type = OrganisationType.Organisation + }; + + if (withBuyerInfo == true) + { + var devolvedRegulations = new List(); + devolvedRegulations.Add(DevolvedRegulation.NorthernIreland); + + org.BuyerInfo = new Persistence.Organisation.BuyerInformation + { + BuyerType = "FakeBuyerType", + DevolvedRegulations = devolvedRegulations, + }; + } + + return org; + } +} \ No newline at end of file diff --git a/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs b/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs index aad022b5f..8fa299b9f 100644 --- a/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs +++ b/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs @@ -987,7 +987,7 @@ await useCase.Execute((organisationId, mouSignatureId)) [AuthenticationChannel.OneLogin], [Constants.OrganisationPersonScope.Admin], OrganisationIdLocation.Path)] - async (Guid organisationId, IUseCase useCase) => + async (Guid organisationId, IUseCase useCase) => await useCase.Execute(organisationId) .AndThen(mouSignatureLatest => mouSignatureLatest != null ? Results.Ok(mouSignatureLatest) : Results.NotFound())) .Produces(StatusCodes.Status200OK, "application/json") @@ -1043,10 +1043,11 @@ await useCase.Execute((organisationId, signMou)) public static RouteGroupBuilder UseMouEndpoints(this RouteGroupBuilder app) { app.MapGet("/latest", - [OrganisationAuthorize( - [AuthenticationChannel.OneLogin], - [Constants.OrganisationPersonScope.Admin], - OrganisationIdLocation.Path)] + [OrganisationAuthorize( + [AuthenticationChannel.OneLogin] + // ,[Constants.OrganisationPersonScope.Admin], + // OrganisationIdLocation.Path + )] async (IUseCase useCase) => await useCase.Execute() .AndThen(mouLatest => mouLatest != null ? Results.Ok(mouLatest) : Results.NotFound())) @@ -1067,6 +1068,34 @@ await useCase.Execute() operation.Responses["500"].Description = "Internal server error."; return operation; }); + + app.MapGet("/{mouId}", + [OrganisationAuthorize( + [AuthenticationChannel.OneLogin] + // ,[Constants.OrganisationPersonScope.Admin], + // OrganisationIdLocation.Path + )] + async (Guid mouId, IUseCase useCase) => + await useCase.Execute(mouId) + .AndThen(mou => mou != null ? Results.Ok(mou) : Results.NotFound())) + .Produces(StatusCodes.Status200OK, "application/json") + .Produces(StatusCodes.Status401Unauthorized) + .Produces(StatusCodes.Status404NotFound) + .ProducesProblem(StatusCodes.Status422UnprocessableEntity) + .Produces(StatusCodes.Status500InternalServerError) + .WithOpenApi(operation => + { + operation.OperationId = "GetMou"; + operation.Description = "Get MOU byId."; + operation.Summary = "Get MOU by ID."; + operation.Responses["200"].Description = "MOU by Id."; + operation.Responses["401"].Description = "Valid authentication credentials are missing in the request."; + operation.Responses["404"].Description = "Mou information not found."; + operation.Responses["422"].Description = "Unprocessable entity."; + operation.Responses["500"].Description = "Internal server error."; + return operation; + }); + return app; } diff --git a/Services/CO.CDP.Organisation.WebApi/Program.cs b/Services/CO.CDP.Organisation.WebApi/Program.cs index baac4b0df..ea006bdba 100644 --- a/Services/CO.CDP.Organisation.WebApi/Program.cs +++ b/Services/CO.CDP.Organisation.WebApi/Program.cs @@ -109,6 +109,7 @@ builder.Services.AddScoped, GetOrganisationMouSignatureLatestUseCase>(); builder.Services.AddScoped, SignOrganisationMouUseCase>(); builder.Services.AddScoped, GetLatestMouUseCase>(); +builder.Services.AddScoped, GetMouUseCase>(); builder.Services.AddProblemDetails(); diff --git a/Services/CO.CDP.Organisation.WebApi/UseCase/GetMouUseCase.cs b/Services/CO.CDP.Organisation.WebApi/UseCase/GetMouUseCase.cs new file mode 100644 index 000000000..f11c37147 --- /dev/null +++ b/Services/CO.CDP.Organisation.WebApi/UseCase/GetMouUseCase.cs @@ -0,0 +1,18 @@ +using AutoMapper; +using CO.CDP.Functional; +using CO.CDP.Organisation.WebApi.Model; +using CO.CDP.OrganisationInformation.Persistence; + +namespace CO.CDP.Organisation.WebApi.UseCase; + +public class GetMouUseCase(IOrganisationRepository organisationRepository, IMapper mapper) + : IUseCase +{ + public async Task Execute(Guid mouId) + { + var mou = await organisationRepository.GetMou(mouId) + ?? throw new UnknownMouException($"No MOU found."); + + return mapper.Map(mou); + } +} \ No newline at end of file From 4697c56c9d543a0bee4af230d44b5b8641769f87 Mon Sep 17 00:00:00 2001 From: Shilpi Goel Date: Thu, 9 Jan 2025 16:44:17 +0000 Subject: [PATCH 5/9] uncomment the auth --- Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs b/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs index 8fa299b9f..a3bb2fffc 100644 --- a/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs +++ b/Services/CO.CDP.Organisation.WebApi/Api/Organisation.cs @@ -1045,8 +1045,8 @@ public static RouteGroupBuilder UseMouEndpoints(this RouteGroupBuilder app) app.MapGet("/latest", [OrganisationAuthorize( [AuthenticationChannel.OneLogin] - // ,[Constants.OrganisationPersonScope.Admin], - // OrganisationIdLocation.Path + , [Constants.OrganisationPersonScope.Admin], + OrganisationIdLocation.Path )] async (IUseCase useCase) => await useCase.Execute() @@ -1072,8 +1072,8 @@ await useCase.Execute() app.MapGet("/{mouId}", [OrganisationAuthorize( [AuthenticationChannel.OneLogin] - // ,[Constants.OrganisationPersonScope.Admin], - // OrganisationIdLocation.Path + , [Constants.OrganisationPersonScope.Admin], + OrganisationIdLocation.Path )] async (Guid mouId, IUseCase useCase) => await useCase.Execute(mouId) From 8b4f57e4055dd986fbcb153f8563e8ad1a910c09 Mon Sep 17 00:00:00 2001 From: Andy Mantell <134642+andymantell@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:20:08 +0000 Subject: [PATCH 6/9] Wait and retry checking for services to be up in Github pipeline (#1120) --- Makefile | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 39f1608de..7428b5a1e 100644 --- a/Makefile +++ b/Makefile @@ -35,9 +35,23 @@ up: compose.override.yml ## Start Docker containers .PHONY: up verify-up: compose.override.yml ## Verify if all Docker containers have run - @docker compose ps -a --format json | jq --exit-status 'select(.ExitCode != 0 or (.Health != "healthy" and .Health != ""))' && exit 1 || echo "All services up" + @timeout=60; \ + interval=5; \ + while [ $$timeout -gt 0 ]; do \ + if docker compose ps -a --format json | jq --exit-status 'select(.ExitCode != 0 or (.Health != "healthy" and .Health != ""))' > /dev/null; then \ + echo "Waiting for services to be healthy..."; \ + sleep $$interval; \ + timeout=$$(($$timeout - $$interval)); \ + else \ + echo "All services up"; \ + exit 0; \ + fi; \ + done; \ + echo "Services did not become healthy in time"; \ + exit 1 .PHONY: verify-up + down: ## Destroy Docker containers @docker compose down .PHONY: down From cfd595bf2856d44f1c0a50aa9bd0306350f7fe12 Mon Sep 17 00:00:00 2001 From: Shilpi Goel Date: Fri, 10 Jan 2025 14:54:58 +0000 Subject: [PATCH 7/9] fixed exception --- .../UseCase/GetOrganisationMouSignatureLatestUseCase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Services/CO.CDP.Organisation.WebApi/UseCase/GetOrganisationMouSignatureLatestUseCase.cs b/Services/CO.CDP.Organisation.WebApi/UseCase/GetOrganisationMouSignatureLatestUseCase.cs index 9891c18f1..4f7a26b18 100644 --- a/Services/CO.CDP.Organisation.WebApi/UseCase/GetOrganisationMouSignatureLatestUseCase.cs +++ b/Services/CO.CDP.Organisation.WebApi/UseCase/GetOrganisationMouSignatureLatestUseCase.cs @@ -17,7 +17,7 @@ public class GetOrganisationMouSignatureLatestUseCase(IOrganisationRepository or if (mouSignatures == null || !mouSignatures.Any()) { - throw new InvalidOperationException($"No MOU signatures found for organisation {organisationId}."); + throw new UnknownMouException($"No MOU signatures found for organisation {organisationId}."); } var latestSignature = mouSignatures.OrderByDescending(m => m.CreatedOn).First(); From 1a7764db188e997cc71f3532dc6760ca9d32b37b Mon Sep 17 00:00:00 2001 From: Shilpi Goel Date: Fri, 10 Jan 2025 15:01:06 +0000 Subject: [PATCH 8/9] fixed unit tests --- .../UseCase/GetOrganisationMouSignatureLatestUseCaseTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetOrganisationMouSignatureLatestUseCaseTest.cs b/Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetOrganisationMouSignatureLatestUseCaseTest.cs index 6f4ca6caf..1d0b85fe9 100644 --- a/Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetOrganisationMouSignatureLatestUseCaseTest.cs +++ b/Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetOrganisationMouSignatureLatestUseCaseTest.cs @@ -77,7 +77,7 @@ public async Task Execute_ShouldThrowInvalidOperationException_WhenNoMouSignatur Func act = async () => await _useCase.Execute(organisation.Guid); - await act.Should().ThrowAsync() + await act.Should().ThrowAsync() .WithMessage($"No MOU signatures found for organisation {organisation.Guid}."); } From 9562bbbc8f8a9f6b0d053867d81b0c28a3bd5691 Mon Sep 17 00:00:00 2001 From: Ali Bahman Date: Fri, 10 Jan 2025 15:23:55 +0000 Subject: [PATCH 9/9] DP-979 Add mechanism to switch DB connection per environment (#1121) - Add mechanism to switch DB connection per environment - Switch Staging to new Clusters - Provision Staging clusters as prod-like account --- terragrunt/modules/database/locals.tf | 2 ++ .../database/rds-entity-verification.tf | 10 +++---- terragrunt/modules/database/rds-sirsi.tf | 10 +++---- terragrunt/modules/ecs/locals.tf | 16 +++++++++- terragrunt/modules/ecs/service-authority.tf | 8 ++--- .../modules/ecs/service-data-sharing.tf | 8 ++--- .../ecs/service-entity-verification.tf | 8 ++--- terragrunt/modules/ecs/service-forms.tf | 8 ++--- .../modules/ecs/service-organisation.tf | 8 ++--- terragrunt/modules/ecs/service-person.tf | 8 ++--- terragrunt/modules/ecs/service-tenant.tf | 8 ++--- terragrunt/modules/ecs/task-migrations.tf | 8 ++--- .../task-definitions/authority.json.tftpl | 10 +++---- .../task-definitions/data-sharing.json.tftpl | 10 +++---- .../entity-verification-migrations.json.tftpl | 4 +-- .../entity-verification.json.tftpl | 10 +++---- .../task-definitions/forms.json.tftpl | 10 +++---- ...nisation-information-migrations.json.tftpl | 4 +-- .../task-definitions/organisation.json.tftpl | 10 +++---- .../task-definitions/person.json.tftpl | 10 +++---- .../task-definitions/tenant.json.tftpl | 10 +++---- terragrunt/modules/ecs/variables.tf | 30 +++++++++++++++++++ 22 files changed, 128 insertions(+), 82 deletions(-) diff --git a/terragrunt/modules/database/locals.tf b/terragrunt/modules/database/locals.tf index ecf42999b..375450349 100644 --- a/terragrunt/modules/database/locals.tf +++ b/terragrunt/modules/database/locals.tf @@ -2,4 +2,6 @@ locals { name_prefix = var.product.resource_name sirsi_cluster_name = "${local.name_prefix}-cluster" ev_cluster_name = "${local.name_prefix}-ev-cluster" + + is_production = var.is_production || var.environment == "staging" } diff --git a/terragrunt/modules/database/rds-entity-verification.tf b/terragrunt/modules/database/rds-entity-verification.tf index 259d6a6f1..994a2ecbc 100644 --- a/terragrunt/modules/database/rds-entity-verification.tf +++ b/terragrunt/modules/database/rds-entity-verification.tf @@ -23,15 +23,15 @@ module "rds_entity_verification" { module "cluster_entity_verification" { source = "../db-postgres-cluster" - backup_retention_period = var.is_production ? 35 : 1 + backup_retention_period = local.is_production ? 35 : 1 db_name = local.ev_cluster_name db_sg_id = var.db_postgres_sg_id - deletion_protection = var.is_production + deletion_protection = local.is_production engine_version = var.aurora_postgres_engine_version family = "aurora-postgresql${floor(var.aurora_postgres_engine_version)}" - monitoring_interval = var.is_production ? 30 : 0 - monitoring_role_arn = var.is_production ? var.role_rds_cloudwatch_arn : "" - performance_insights_enabled = var.is_production + monitoring_interval = local.is_production ? 30 : 0 + monitoring_role_arn = local.is_production ? var.role_rds_cloudwatch_arn : "" + performance_insights_enabled = local.is_production instance_type = var.aurora_postgres_instance_type private_subnet_ids = var.private_subnet_ids role_terraform_arn = var.role_terraform_arn diff --git a/terragrunt/modules/database/rds-sirsi.tf b/terragrunt/modules/database/rds-sirsi.tf index ac9bd0459..fa68d0a41 100644 --- a/terragrunt/modules/database/rds-sirsi.tf +++ b/terragrunt/modules/database/rds-sirsi.tf @@ -23,15 +23,15 @@ module "rds_sirsi" { module "cluster_sirsi" { source = "../db-postgres-cluster" - backup_retention_period = var.is_production ? 35 : 1 + backup_retention_period = local.is_production ? 35 : 1 db_name = local.sirsi_cluster_name db_sg_id = var.db_postgres_sg_id - deletion_protection = var.is_production + deletion_protection = local.is_production engine_version = var.aurora_postgres_engine_version family = "aurora-postgresql${floor(var.aurora_postgres_engine_version)}" - monitoring_interval = var.is_production ? 30 : 0 - monitoring_role_arn = var.is_production ? var.role_rds_cloudwatch_arn : "" - performance_insights_enabled = var.is_production + monitoring_interval = local.is_production ? 30 : 0 + monitoring_role_arn = local.is_production ? var.role_rds_cloudwatch_arn : "" + performance_insights_enabled = local.is_production instance_type = var.aurora_postgres_instance_type private_subnet_ids = var.private_subnet_ids role_terraform_arn = var.role_terraform_arn diff --git a/terragrunt/modules/ecs/locals.tf b/terragrunt/modules/ecs/locals.tf index 21a8261ec..e6339f556 100644 --- a/terragrunt/modules/ecs/locals.tf +++ b/terragrunt/modules/ecs/locals.tf @@ -2,6 +2,20 @@ locals { aspcore_environment = "Aws${title(var.environment)}" + aurora_cluster_enabled = contains(["staging"], var.environment) + + db_sirsi_secret_arn = local.aurora_cluster_enabled ? var.db_sirsi_cluster_credentials_arn : var.db_sirsi_credentials_arn + db_ev_secret_arn = local.aurora_cluster_enabled ? var.db_ev_cluster_credentials_arn : var.db_entity_verification_credentials_arn + + db_sirsi_address = local.aurora_cluster_enabled ? var.db_sirsi_cluster_address : var.db_sirsi_address + db_sirsi_name = local.aurora_cluster_enabled ? var.db_sirsi_cluster_name : var.db_sirsi_name + db_sirsi_password = "${local.db_sirsi_secret_arn}:password::" + db_sirsi_username = "${local.db_sirsi_secret_arn}:username::" + db_ev_address = local.aurora_cluster_enabled ? var.db_ev_cluster_address : var.db_entity_verification_address + db_ev_name = local.aurora_cluster_enabled ? var.db_ev_cluster_name : var.db_entity_verification_name + db_ev_password = "${local.db_ev_secret_arn}:password::" + db_ev_username = "${local.db_ev_secret_arn}:username::" + ecr_urls = { for task in local.tasks : task => "${local.orchestrator_account_id}.dkr.ecr.eu-west-2.amazonaws.com/cdp-${task}" } @@ -25,7 +39,7 @@ locals { service_version = var.pinned_service_version == null ? data.aws_ssm_parameter.orchestrator_service_version.value : var.pinned_service_version - shared_sessions_enabled = var.environment == "development" ? true : false + shared_sessions_enabled = var.environment == "development" ? true : false ssm_data_protection_prefix = "${local.name_prefix}-ec-sessions" migrations = ["organisation-information-migrations", "entity-verification-migrations"] diff --git a/terragrunt/modules/ecs/service-authority.tf b/terragrunt/modules/ecs/service-authority.tf index 663192f66..4cd91f299 100644 --- a/terragrunt/modules/ecs/service-authority.tf +++ b/terragrunt/modules/ecs/service-authority.tf @@ -8,6 +8,10 @@ module "ecs_service_authority" { authority_private_key = "${data.aws_secretsmanager_secret.authority_keys.arn}:PRIVATE::" container_port = var.service_configs.authority.port cpu = var.service_configs.authority.cpu + db_address = local.db_sirsi_address + db_name = local.db_sirsi_name + db_password = local.db_sirsi_password + db_username = local.db_sirsi_username host_port = var.service_configs.authority.port image = local.ecr_urls[var.service_configs.authority.name] lg_name = aws_cloudwatch_log_group.tasks[var.service_configs.authority.name].name @@ -15,10 +19,6 @@ module "ecs_service_authority" { lg_region = data.aws_region.current.name memory = var.service_configs.authority.memory name = var.service_configs.authority.name - oi_db_address = var.db_sirsi_address - oi_db_name = var.db_sirsi_name - oi_db_password = "${var.db_sirsi_credentials_arn}:username::" - oi_db_username = "${var.db_sirsi_credentials_arn}:password::" onelogin_authority = local.one_loging.credential_locations.authority onelogin_client_id = local.one_loging.credential_locations.client_id onelogin_private_key = local.one_loging.credential_locations.private_key diff --git a/terragrunt/modules/ecs/service-data-sharing.tf b/terragrunt/modules/ecs/service-data-sharing.tf index c28033223..c51dc0368 100644 --- a/terragrunt/modules/ecs/service-data-sharing.tf +++ b/terragrunt/modules/ecs/service-data-sharing.tf @@ -7,6 +7,10 @@ module "ecs_service_data_sharing" { aspcore_environment = local.aspcore_environment container_port = var.service_configs.data_sharing.port cpu = var.service_configs.data_sharing.cpu + db_address = local.db_sirsi_address + db_name = local.db_sirsi_name + db_password = local.db_sirsi_password + db_username = local.db_sirsi_username host_port = var.service_configs.data_sharing.port image = local.ecr_urls[var.service_configs.data_sharing.name] lg_name = aws_cloudwatch_log_group.tasks[var.service_configs.data_sharing.name].name @@ -14,10 +18,6 @@ module "ecs_service_data_sharing" { lg_region = data.aws_region.current.name memory = var.service_configs.data_sharing.memory name = var.service_configs.data_sharing.name - oi_db_address = var.db_sirsi_address - oi_db_name = var.db_sirsi_name - oi_db_password = "${var.db_sirsi_credentials_arn}:username::" - oi_db_username = "${var.db_sirsi_credentials_arn}:password::" public_domain = var.public_domain s3_permanent_bucket = module.s3_bucket_permanent.bucket s3_staging_bucket = module.s3_bucket_staging.bucket diff --git a/terragrunt/modules/ecs/service-entity-verification.tf b/terragrunt/modules/ecs/service-entity-verification.tf index cdfb126a8..5569dd68b 100644 --- a/terragrunt/modules/ecs/service-entity-verification.tf +++ b/terragrunt/modules/ecs/service-entity-verification.tf @@ -7,10 +7,10 @@ module "ecs_service_entity_verification" { aspcore_environment = local.aspcore_environment container_port = var.service_configs.entity_verification.port cpu = var.service_configs.entity_verification.cpu - ev_db_address = var.db_entity_verification_address - ev_db_name = var.db_entity_verification_name - ev_db_password = "${var.db_entity_verification_credentials_arn}:username::" - ev_db_username = "${var.db_entity_verification_credentials_arn}:password::" + db_address = local.db_ev_address + db_name = local.db_ev_name + db_password = local.db_ev_password + db_username = local.db_ev_username host_port = var.service_configs.entity_verification.port image = local.ecr_urls[var.service_configs.entity_verification.name] lg_name = aws_cloudwatch_log_group.tasks[var.service_configs.entity_verification.name].name diff --git a/terragrunt/modules/ecs/service-forms.tf b/terragrunt/modules/ecs/service-forms.tf index ae0aa5cc2..d24b8b748 100644 --- a/terragrunt/modules/ecs/service-forms.tf +++ b/terragrunt/modules/ecs/service-forms.tf @@ -7,6 +7,10 @@ module "ecs_service_forms" { aspcore_environment = local.aspcore_environment container_port = var.service_configs.forms.port cpu = var.service_configs.forms.cpu + db_address = local.db_sirsi_address + db_name = local.db_sirsi_name + db_password = local.db_sirsi_password + db_username = local.db_sirsi_username host_port = var.service_configs.forms.port image = local.ecr_urls[var.service_configs.forms.name] lg_name = aws_cloudwatch_log_group.tasks[var.service_configs.forms.name].name @@ -14,10 +18,6 @@ module "ecs_service_forms" { lg_region = data.aws_region.current.name memory = var.service_configs.forms.memory name = var.service_configs.forms.name - oi_db_address = var.db_sirsi_address - oi_db_name = var.db_sirsi_name - oi_db_password = "${var.db_sirsi_credentials_arn}:username::" - oi_db_username = "${var.db_sirsi_credentials_arn}:password::" public_domain = var.public_domain s3_permanent_bucket = module.s3_bucket_permanent.bucket s3_staging_bucket = module.s3_bucket_staging.bucket diff --git a/terragrunt/modules/ecs/service-organisation.tf b/terragrunt/modules/ecs/service-organisation.tf index 13d3e01cb..0c9235ff8 100644 --- a/terragrunt/modules/ecs/service-organisation.tf +++ b/terragrunt/modules/ecs/service-organisation.tf @@ -7,6 +7,10 @@ module "ecs_service_organisation" { aspcore_environment = local.aspcore_environment container_port = var.service_configs.organisation.port cpu = var.service_configs.organisation.cpu + db_address = local.db_sirsi_address + db_name = local.db_sirsi_name + db_password = local.db_sirsi_password + db_username = local.db_sirsi_username govuknotify_apikey = data.aws_secretsmanager_secret_version.govuknotify_apikey.arn govuknotify_support_admin_email = data.aws_secretsmanager_secret_version.govuknotify_support_admin_email.arn host_port = var.service_configs.organisation.port @@ -16,10 +20,6 @@ module "ecs_service_organisation" { lg_region = data.aws_region.current.name memory = var.service_configs.organisation.memory name = var.service_configs.organisation.name - oi_db_address = var.db_sirsi_address - oi_db_name = var.db_sirsi_name - oi_db_password = "${var.db_sirsi_credentials_arn}:username::" - oi_db_username = "${var.db_sirsi_credentials_arn}:password::" public_domain = var.public_domain queue_entity_verification_queue_url = var.queue_entity_verification_queue_url queue_organisation_queue_url = var.queue_organisation_queue_url diff --git a/terragrunt/modules/ecs/service-person.tf b/terragrunt/modules/ecs/service-person.tf index 85d6bd20f..ad18d2c54 100644 --- a/terragrunt/modules/ecs/service-person.tf +++ b/terragrunt/modules/ecs/service-person.tf @@ -7,6 +7,10 @@ module "ecs_service_person" { aspcore_environment = local.aspcore_environment container_port = var.service_configs.person.port cpu = var.service_configs.person.cpu + db_address = local.db_sirsi_address + db_name = local.db_sirsi_name + db_password = local.db_sirsi_password + db_username = local.db_sirsi_username host_port = var.service_configs.person.port image = local.ecr_urls[var.service_configs.person.name] lg_name = aws_cloudwatch_log_group.tasks[var.service_configs.person.name].name @@ -14,10 +18,6 @@ module "ecs_service_person" { lg_region = data.aws_region.current.name memory = var.service_configs.person.memory name = var.service_configs.person.name - oi_db_address = var.db_sirsi_address - oi_db_name = var.db_sirsi_name - oi_db_password = "${var.db_sirsi_credentials_arn}:username::" - oi_db_username = "${var.db_sirsi_credentials_arn}:password::" public_domain = var.public_domain service_version = local.service_version vpc_cidr = var.vpc_cider diff --git a/terragrunt/modules/ecs/service-tenant.tf b/terragrunt/modules/ecs/service-tenant.tf index c231deaed..824a0f586 100644 --- a/terragrunt/modules/ecs/service-tenant.tf +++ b/terragrunt/modules/ecs/service-tenant.tf @@ -7,6 +7,10 @@ module "ecs_service_tenant" { aspcore_environment = local.aspcore_environment container_port = var.service_configs.tenant.port cpu = var.service_configs.tenant.cpu + db_address = local.db_sirsi_address + db_name = local.db_sirsi_name + db_password = local.db_sirsi_password + db_username = local.db_sirsi_username host_port = var.service_configs.tenant.port image = local.ecr_urls[var.service_configs.tenant.name] lg_name = aws_cloudwatch_log_group.tasks[var.service_configs.tenant.name].name @@ -14,10 +18,6 @@ module "ecs_service_tenant" { lg_region = data.aws_region.current.name memory = var.service_configs.tenant.memory name = var.service_configs.tenant.name - oi_db_address = var.db_sirsi_address - oi_db_name = var.db_sirsi_name - oi_db_password = "${var.db_sirsi_credentials_arn}:username::" - oi_db_username = "${var.db_sirsi_credentials_arn}:password::" public_domain = var.public_domain service_version = local.service_version vpc_cidr = var.vpc_cider diff --git a/terragrunt/modules/ecs/task-migrations.tf b/terragrunt/modules/ecs/task-migrations.tf index 25c384744..789301a88 100644 --- a/terragrunt/modules/ecs/task-migrations.tf +++ b/terragrunt/modules/ecs/task-migrations.tf @@ -14,10 +14,10 @@ module "ecs_migration_tasks" { lg_region = data.aws_region.current.name memory = each.value.memory name = each.value.name - db_address = each.value.name == "entity-verification-migrations" ? var.db_entity_verification_address : var.db_sirsi_address - db_name = each.value.name == "entity-verification-migrations" ? var.db_entity_verification_name : var.db_sirsi_name - db_password = each.value.name == "entity-verification-migrations" ? "${var.db_entity_verification_credentials_arn}:username::" : "${var.db_sirsi_credentials_arn}:username::" - db_username = each.value.name == "entity-verification-migrations" ? "${var.db_entity_verification_credentials_arn}:password::" : "${var.db_sirsi_credentials_arn}:password::" + db_address = each.value.name == "entity-verification-migrations" ? local.db_ev_address : local.db_sirsi_address + db_name = each.value.name == "entity-verification-migrations" ? local.db_ev_name : local.db_sirsi_name + db_password = each.value.name == "entity-verification-migrations" ? local.db_ev_password : local.db_sirsi_password + db_username = each.value.name == "entity-verification-migrations" ? local.db_ev_username : local.db_sirsi_username public_domain = var.public_domain service_version = local.service_version } diff --git a/terragrunt/modules/ecs/templates/task-definitions/authority.json.tftpl b/terragrunt/modules/ecs/templates/task-definitions/authority.json.tftpl index ec36babc8..be7a491fb 100644 --- a/terragrunt/modules/ecs/templates/task-definitions/authority.json.tftpl +++ b/terragrunt/modules/ecs/templates/task-definitions/authority.json.tftpl @@ -26,15 +26,15 @@ {"name": "Aws__CloudWatch__LogStream", "value": "${lg_prefix}-serilog"}, {"name": "ForwardedHeaders__KnownNetwork", "value": "${vpc_cidr}"}, {"name": "Issuer", "value": "https://authority.${public_domain}"}, - {"name": "OrganisationInformationDatabase__Database", "value": "${oi_db_name}"}, - {"name": "OrganisationInformationDatabase__Host", "value": "${oi_db_address}"}, - {"name": "OrganisationInformationDatabase__Server", "value": "${oi_db_address}"} + {"name": "OrganisationInformationDatabase__Database", "value": "${db_name}"}, + {"name": "OrganisationInformationDatabase__Host", "value": "${db_address}"}, + {"name": "OrganisationInformationDatabase__Server", "value": "${db_address}"} ], "secrets": [ {"name": "OneLogin__Authority", "valueFrom": "${onelogin_authority}"}, {"name": "OneLogin__ClientId", "valueFrom": "${onelogin_client_id}"}, - {"name": "OrganisationInformationDatabase__Password", "valueFrom": "${oi_db_username}"}, - {"name": "OrganisationInformationDatabase__Username", "valueFrom": "${oi_db_password}"}, + {"name": "OrganisationInformationDatabase__Password", "valueFrom": "${db_password}"}, + {"name": "OrganisationInformationDatabase__Username", "valueFrom": "${db_username}"}, {"name": "PrivateKey", "valueFrom": "${authority_private_key}"} ], "volumesFrom": [], diff --git a/terragrunt/modules/ecs/templates/task-definitions/data-sharing.json.tftpl b/terragrunt/modules/ecs/templates/task-definitions/data-sharing.json.tftpl index d1475bf56..9ca6bb639 100644 --- a/terragrunt/modules/ecs/templates/task-definitions/data-sharing.json.tftpl +++ b/terragrunt/modules/ecs/templates/task-definitions/data-sharing.json.tftpl @@ -28,14 +28,14 @@ {"name": "Aws__CloudWatch__LogStream", "value": "${lg_prefix}-serilog"}, {"name": "DataSharingApiUrl", "value": "https://data-sharing.${public_domain}"}, {"name": "ForwardedHeaders__KnownNetwork", "value": "${vpc_cidr}"}, - {"name": "OrganisationInformationDatabase__Database", "value": "${oi_db_name}"}, - {"name": "OrganisationInformationDatabase__Host", "value": "${oi_db_address}"}, - {"name": "OrganisationInformationDatabase__Server", "value": "${oi_db_address}"}, + {"name": "OrganisationInformationDatabase__Database", "value": "${db_name}"}, + {"name": "OrganisationInformationDatabase__Host", "value": "${db_address}"}, + {"name": "OrganisationInformationDatabase__Server", "value": "${db_address}"}, {"name": "Organisation__Authority", "value": "https://authority.${public_domain}"} ], "secrets": [ - {"name": "OrganisationInformationDatabase__Password", "valueFrom": "${oi_db_username}"}, - {"name": "OrganisationInformationDatabase__Username", "valueFrom": "${oi_db_password}"} + {"name": "OrganisationInformationDatabase__Password", "valueFrom": "${db_password}"}, + {"name": "OrganisationInformationDatabase__Username", "valueFrom": "${db_username}"} ], "volumesFrom": [], "mountPoints": [], diff --git a/terragrunt/modules/ecs/templates/task-definitions/entity-verification-migrations.json.tftpl b/terragrunt/modules/ecs/templates/task-definitions/entity-verification-migrations.json.tftpl index f3600de09..7695cf7a6 100644 --- a/terragrunt/modules/ecs/templates/task-definitions/entity-verification-migrations.json.tftpl +++ b/terragrunt/modules/ecs/templates/task-definitions/entity-verification-migrations.json.tftpl @@ -23,8 +23,8 @@ {"name": "Organisation__Authority", "value": "https://authority.${public_domain}"} ], "secrets": [ - {"name": "EntityVerificationDatabase__Password", "valueFrom": "${db_username}"}, - {"name": "EntityVerificationDatabase__Username", "valueFrom": "${db_password}"} + {"name": "EntityVerificationDatabase__Password", "valueFrom": "${db_password}"}, + {"name": "EntityVerificationDatabase__Username", "valueFrom": "${db_username}"} ], "volumesFrom": [], "mountPoints": [], diff --git a/terragrunt/modules/ecs/templates/task-definitions/entity-verification.json.tftpl b/terragrunt/modules/ecs/templates/task-definitions/entity-verification.json.tftpl index d2919ee4c..afa153d95 100644 --- a/terragrunt/modules/ecs/templates/task-definitions/entity-verification.json.tftpl +++ b/terragrunt/modules/ecs/templates/task-definitions/entity-verification.json.tftpl @@ -27,15 +27,15 @@ {"name": "Aws__SqsDispatcher__QueueUrl", "value": "${queue_organisation_queue_url}"}, {"name": "Aws__SqsPublisher__QueueUrl", "value": "${queue_entity_verification_queue_url}"}, {"name": "CdpApiKeys__0", "value": "a955a529-1433-4acf-92b2-342a3e5e8086"}, - {"name": "EntityVerificationDatabase__Database", "value": "${ev_db_name}"}, - {"name": "EntityVerificationDatabase__Host", "value": "${ev_db_address}"}, - {"name": "EntityVerificationDatabase__Server", "value": "${ev_db_address}"}, + {"name": "EntityVerificationDatabase__Database", "value": "${db_name}"}, + {"name": "EntityVerificationDatabase__Host", "value": "${db_address}"}, + {"name": "EntityVerificationDatabase__Server", "value": "${db_address}"}, {"name": "ForwardedHeaders__KnownNetwork", "value": "${vpc_cidr}"}, {"name": "Organisation__Authority", "value": "https://authority.${public_domain}"} ], "secrets": [ - {"name": "EntityVerificationDatabase__Password", "valueFrom": "${ev_db_username}"}, - {"name": "EntityVerificationDatabase__Username", "valueFrom": "${ev_db_password}"} + {"name": "EntityVerificationDatabase__Password", "valueFrom": "${db_password}"}, + {"name": "EntityVerificationDatabase__Username", "valueFrom": "${db_username}"} ], "volumesFrom": [], "mountPoints": [], diff --git a/terragrunt/modules/ecs/templates/task-definitions/forms.json.tftpl b/terragrunt/modules/ecs/templates/task-definitions/forms.json.tftpl index 40fb5969a..b57754833 100644 --- a/terragrunt/modules/ecs/templates/task-definitions/forms.json.tftpl +++ b/terragrunt/modules/ecs/templates/task-definitions/forms.json.tftpl @@ -28,14 +28,14 @@ {"name": "Aws__CloudWatch__LogStream", "value": "${lg_prefix}-serilog"}, {"name": "CdpApiKeys__0", "value": "a955a529-1433-4acf-92b2-342a3e5e8086"}, {"name": "ForwardedHeaders__KnownNetwork", "value": "${vpc_cidr}"}, - {"name": "OrganisationInformationDatabase__Database", "value": "${oi_db_name}"}, - {"name": "OrganisationInformationDatabase__Host", "value": "${oi_db_address}"}, - {"name": "OrganisationInformationDatabase__Server", "value": "${oi_db_address}"}, + {"name": "OrganisationInformationDatabase__Database", "value": "${db_name}"}, + {"name": "OrganisationInformationDatabase__Host", "value": "${db_address}"}, + {"name": "OrganisationInformationDatabase__Server", "value": "${db_address}"}, {"name": "Organisation__Authority", "value": "https://authority.${public_domain}"} ], "secrets": [ - {"name": "OrganisationInformationDatabase__Password", "valueFrom": "${oi_db_username}"}, - {"name": "OrganisationInformationDatabase__Username", "valueFrom": "${oi_db_password}"} + {"name": "OrganisationInformationDatabase__Password", "valueFrom": "${db_password}"}, + {"name": "OrganisationInformationDatabase__Username", "valueFrom": "${db_username}"} ], "volumesFrom": [], "mountPoints": [], diff --git a/terragrunt/modules/ecs/templates/task-definitions/organisation-information-migrations.json.tftpl b/terragrunt/modules/ecs/templates/task-definitions/organisation-information-migrations.json.tftpl index ee8c389fb..979583026 100644 --- a/terragrunt/modules/ecs/templates/task-definitions/organisation-information-migrations.json.tftpl +++ b/terragrunt/modules/ecs/templates/task-definitions/organisation-information-migrations.json.tftpl @@ -23,8 +23,8 @@ {"name": "Organisation__Authority", "value": "https://authority.${public_domain}"} ], "secrets": [ - {"name": "OrganisationInformationDatabase__Password", "valueFrom": "${db_username}"}, - {"name": "OrganisationInformationDatabase__Username", "valueFrom": "${db_password}"} + {"name": "OrganisationInformationDatabase__Password", "valueFrom": "${db_password}"}, + {"name": "OrganisationInformationDatabase__Username", "valueFrom": "${db_username}"} ], "volumesFrom": [], "mountPoints": [], diff --git a/terragrunt/modules/ecs/templates/task-definitions/organisation.json.tftpl b/terragrunt/modules/ecs/templates/task-definitions/organisation.json.tftpl index a65c0b108..94b842357 100644 --- a/terragrunt/modules/ecs/templates/task-definitions/organisation.json.tftpl +++ b/terragrunt/modules/ecs/templates/task-definitions/organisation.json.tftpl @@ -30,16 +30,16 @@ {"name": "ForwardedHeaders__KnownNetwork", "value": "${vpc_cidr}"}, {"name": "OrganisationApiUrl", "value": "https://organisation.${public_domain}"}, {"name": "OrganisationAppUrl", "value": "https://${public_domain}"}, - {"name": "OrganisationInformationDatabase__Database", "value": "${oi_db_name}"}, - {"name": "OrganisationInformationDatabase__Host", "value": "${oi_db_address}"}, - {"name": "OrganisationInformationDatabase__Server", "value": "${oi_db_address}"}, + {"name": "OrganisationInformationDatabase__Database", "value": "${db_name}"}, + {"name": "OrganisationInformationDatabase__Host", "value": "${db_address}"}, + {"name": "OrganisationInformationDatabase__Server", "value": "${db_address}"}, {"name": "Organisation__Authority", "value": "https://authority.${public_domain}"} ], "secrets": [ {"name": "GOVUKNotify__ApiKey", "valueFrom": "${govuknotify_apikey}"}, {"name": "GOVUKNotify__SupportAdminEmailAddress", "valueFrom": "${govuknotify_support_admin_email}"}, - {"name": "OrganisationInformationDatabase__Password", "valueFrom": "${oi_db_username}"}, - {"name": "OrganisationInformationDatabase__Username", "valueFrom": "${oi_db_password}"} + {"name": "OrganisationInformationDatabase__Password", "valueFrom": "${db_password}"}, + {"name": "OrganisationInformationDatabase__Username", "valueFrom": "${db_username}"} ], "volumesFrom": [], "mountPoints": [], diff --git a/terragrunt/modules/ecs/templates/task-definitions/person.json.tftpl b/terragrunt/modules/ecs/templates/task-definitions/person.json.tftpl index 99f125575..890cfc4d9 100644 --- a/terragrunt/modules/ecs/templates/task-definitions/person.json.tftpl +++ b/terragrunt/modules/ecs/templates/task-definitions/person.json.tftpl @@ -26,14 +26,14 @@ {"name": "Aws__CloudWatch__LogStream", "value": "${lg_prefix}-serilog"}, {"name": "CdpApiKeys__0", "value": "a955a529-1433-4acf-92b2-342a3e5e8086"}, {"name": "ForwardedHeaders__KnownNetwork", "value": "${vpc_cidr}"}, - {"name": "OrganisationInformationDatabase__Database", "value": "${oi_db_name}"}, - {"name": "OrganisationInformationDatabase__Host", "value": "${oi_db_address}"}, - {"name": "OrganisationInformationDatabase__Server", "value": "${oi_db_address}"}, + {"name": "OrganisationInformationDatabase__Database", "value": "${db_name}"}, + {"name": "OrganisationInformationDatabase__Host", "value": "${db_address}"}, + {"name": "OrganisationInformationDatabase__Server", "value": "${db_address}"}, {"name": "Organisation__Authority", "value": "https://authority.${public_domain}"} ], "secrets": [ - {"name": "OrganisationInformationDatabase__Password", "valueFrom": "${oi_db_username}"}, - {"name": "OrganisationInformationDatabase__Username", "valueFrom": "${oi_db_password}"} + {"name": "OrganisationInformationDatabase__Password", "valueFrom": "${db_password}"}, + {"name": "OrganisationInformationDatabase__Username", "valueFrom": "${db_username}"} ], "volumesFrom": [], "mountPoints": [], diff --git a/terragrunt/modules/ecs/templates/task-definitions/tenant.json.tftpl b/terragrunt/modules/ecs/templates/task-definitions/tenant.json.tftpl index 99f125575..890cfc4d9 100644 --- a/terragrunt/modules/ecs/templates/task-definitions/tenant.json.tftpl +++ b/terragrunt/modules/ecs/templates/task-definitions/tenant.json.tftpl @@ -26,14 +26,14 @@ {"name": "Aws__CloudWatch__LogStream", "value": "${lg_prefix}-serilog"}, {"name": "CdpApiKeys__0", "value": "a955a529-1433-4acf-92b2-342a3e5e8086"}, {"name": "ForwardedHeaders__KnownNetwork", "value": "${vpc_cidr}"}, - {"name": "OrganisationInformationDatabase__Database", "value": "${oi_db_name}"}, - {"name": "OrganisationInformationDatabase__Host", "value": "${oi_db_address}"}, - {"name": "OrganisationInformationDatabase__Server", "value": "${oi_db_address}"}, + {"name": "OrganisationInformationDatabase__Database", "value": "${db_name}"}, + {"name": "OrganisationInformationDatabase__Host", "value": "${db_address}"}, + {"name": "OrganisationInformationDatabase__Server", "value": "${db_address}"}, {"name": "Organisation__Authority", "value": "https://authority.${public_domain}"} ], "secrets": [ - {"name": "OrganisationInformationDatabase__Password", "valueFrom": "${oi_db_username}"}, - {"name": "OrganisationInformationDatabase__Username", "valueFrom": "${oi_db_password}"} + {"name": "OrganisationInformationDatabase__Password", "valueFrom": "${db_password}"}, + {"name": "OrganisationInformationDatabase__Username", "valueFrom": "${db_username}"} ], "volumesFrom": [], "mountPoints": [], diff --git a/terragrunt/modules/ecs/variables.tf b/terragrunt/modules/ecs/variables.tf index 618d871ac..3fad542b2 100644 --- a/terragrunt/modules/ecs/variables.tf +++ b/terragrunt/modules/ecs/variables.tf @@ -28,11 +28,26 @@ variable "db_entity_verification_name" { type = string } +variable "db_ev_cluster_address" { + description = "Entity Verification DB address" + type = string +} + +variable "db_ev_cluster_credentials_arn" { + description = "ARN of the secret holding Entity Verification DB credentials" + type = string +} + variable "db_ev_cluster_credentials_kms_key_id" { description = "Key ID of the KMS used to encrypt Entity Verification secrets" type = string } +variable "db_ev_cluster_name" { + description = "Entity Verification DB name" + type = string +} + variable "db_postgres_sg_id" { description = "Postgres DB security group ID" type = string @@ -43,11 +58,26 @@ variable "db_sirsi_address" { type = string } +variable "db_sirsi_cluster_address" { + description = "Sirsi DB address" + type = string +} + +variable "db_sirsi_cluster_credentials_arn" { + description = "ARN of the secret holding Sirsi DB credentials" + type = string +} + variable "db_sirsi_cluster_credentials_kms_key_id" { description = "Key ID of the KMS used to encrypt Sirsi secrets" type = string } +variable "db_sirsi_cluster_name" { + description = "Sirsi DB name" + type = string +} + variable "db_sirsi_credentials_arn" { description = "ARN of the secret holding Sirsi DB credentials" type = string