Skip to content

Commit 1c13597

Browse files
committed
CCM-8637: add sftp utils
1 parent 81c5dc7 commit 1c13597

23 files changed

+874
-5
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
resource "aws_ssm_parameter" "sftp_mock_config" {
2+
name = format(
3+
"/%s/sftp-mock-config",
4+
local.csi,
5+
)
6+
description = "Configuration values for accessing an SFTP mock server"
7+
type = "SecureString"
8+
9+
/*
10+
JSON object matching:
11+
{
12+
"host": string
13+
"username": string,
14+
"privateKey": string,
15+
"baseUploadDir": "WTM_MOCK/Incoming,
16+
"baseDownloadDir": "WTM_MOCK/Outgoing"
17+
}
18+
*/
19+
value = "placeholder"
20+
21+
lifecycle {
22+
ignore_changes = [value]
23+
}
24+
}

infrastructure/terraform/components/app/module_backend_api.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ module "backend_api" {
1616

1717
enable_backup = var.destination_vault_arn != null ? true : false
1818

19-
enable_letters = var.enable_letters
19+
enable_letters = var.enable_letters
20+
letter_suppliers = var.letter_suppliers
2021
}

infrastructure/terraform/components/app/variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,12 @@ variable "observability_account_id" {
192192
type = string
193193
description = "The Observability Account ID that needs access"
194194
}
195+
196+
variable "letter_suppliers" {
197+
type = map(object({
198+
enable_polling = bool
199+
default_supplier = optional(bool)
200+
}))
201+
default = {}
202+
description = "Letter suppliers enabled in the environment"
203+
}

infrastructure/terraform/components/sandbox/module_backend_api.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ module "backend_api" {
1515
USER_POOL_CLIENT_ID = aws_cognito_user_pool_client.sandbox.id
1616
}
1717

18-
enable_letters = true
18+
enable_letters = true
19+
letter_suppliers = var.letter_suppliers
1920

2021
kms_key_arn = data.aws_kms_key.sandbox.arn
2122
dynamodb_kms_key_arn = data.aws_kms_key.sandbox.arn

infrastructure/terraform/components/sandbox/variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,18 @@ variable "kms_deletion_window" {
6262
description = "When a kms key is deleted, how long should it wait in the pending deletion state?"
6363
default = "30"
6464
}
65+
66+
variable "letter_suppliers" {
67+
type = map(object({
68+
enable_polling = bool
69+
default_supplier = optional(bool)
70+
}))
71+
default = {
72+
"WTMMOCK" = {
73+
enable_polling = true
74+
default_supplier = true
75+
}
76+
}
77+
description = "Letter suppliers enabled in the environment"
78+
}
79+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
data "aws_ssm_parameter" "sftp_mock_config_acct" {
2+
count = local.use_sftp_letter_supplier_mock ? 1 : 0
3+
name = "/nhs-notify-main-acct/sftp-mock-config"
4+
}

infrastructure/terraform/modules/backend-api/locals.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ locals {
2525
}
2626

2727
dynamodb_kms_key_arn = var.dynamodb_kms_key_arn == "" ? aws_kms_key.dynamo[0].arn : var.dynamodb_kms_key_arn
28+
29+
mock_letter_supplier_name = "WTMMOCK"
30+
use_sftp_letter_supplier_mock = lookup(var.letter_suppliers, local.mock_letter_supplier_name, null) != null
31+
default_letter_supplier = [
32+
for k, v in var.letter_suppliers : merge(v, { name = k }) if v.default_supplier
33+
][0]
2834
}

infrastructure/terraform/modules/backend-api/module_lambda_send_letter_proof.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ module "lambda_send_letter_proof" {
1010
log_retention_in_days = var.log_retention_in_days
1111

1212
execution_role_policy_document = data.aws_iam_policy_document.send_letter_proof.json
13+
14+
environment_variables = {
15+
CSI = local.csi
16+
}
1317
}
1418

1519
data "aws_iam_policy_document" "send_letter_proof" {
@@ -38,6 +42,17 @@ data "aws_iam_policy_document" "send_letter_proof" {
3842
resources = ["${module.s3bucket_internal.arn}/*"]
3943
}
4044

45+
statement {
46+
sid = "AllowSSMParameterRead"
47+
effect = "Allow"
48+
actions = [
49+
"ssm:GetParameter",
50+
]
51+
resources = [
52+
"arn:aws:ssm:${var.region}:${var.aws_account_id}:parameter/${local.csi}/*/sftp-config"
53+
]
54+
}
55+
4156
statement {
4257
sid = "AllowKMSDynamoAccess"
4358
effect = "Allow"

infrastructure/terraform/modules/backend-api/sftp_upload_queue.tf renamed to infrastructure/terraform/modules/backend-api/module_sqs_sftp_upload_queue.tf

File renamed without changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
resource "aws_ssm_parameter" "sftp_config" {
2+
for_each = { for k, v in var.letter_suppliers : k => v if k != local.mock_letter_supplier_name }
3+
4+
name = "/${local.csi}/sftp-config/${each.key}"
5+
description = "Configuration values for accessing an SFTP server"
6+
type = "SecureString"
7+
value = "placeholder"
8+
9+
lifecycle {
10+
ignore_changes = [value]
11+
}
12+
}
13+
14+
resource "aws_ssm_parameter" "sftp_mock_config" {
15+
count = local.use_sftp_letter_supplier_mock ? 1 : 0
16+
17+
name = "/${local.csi}/sftp-config/${local.mock_letter_supplier_name}"
18+
description = "Configuration values for accessing the mock SFTP server"
19+
type = "SecureString"
20+
value = data.aws_ssm_parameter.sftp_mock_config_acct[0].value
21+
}

0 commit comments

Comments
 (0)