Skip to content

Commit 2be3314

Browse files
committed
Merge branch 'master' into VED-358-github-actions-for-int
2 parents 9c9a86f + 1008fd9 commit 2be3314

File tree

7 files changed

+92
-0
lines changed

7 files changed

+92
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
imms_account_id = "084828561157"
22
dspp_account_id = "603871901111"
3+
mns_account_id = "631615744739"
34
admin_role = "role/aws-reserved/sso.amazonaws.com/eu-west-2/AWSReservedSSO_PREPROD-IMMS-Admin_acce656dcacf6f4c"
45
dev_ops_role = "role/aws-reserved/sso.amazonaws.com/eu-west-2/AWSReservedSSO_PREPROD-IMMS-Devops_1d28e4f37b940bcd"
56
auto_ops_role = "role/auto-ops"
67
dspp_admin_role = "root"
8+
mns_admin_role = "role/nhs-mns-events-lambda-delivery"
79
environment = "int"
810
parent_route53_zone_name = "int.vds.platform.nhs.uk"
911
child_route53_zone_name = "imms.int.vds.platform.nhs.uk"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
imms_account_id = "345594581768"
22
dspp_account_id = "603871901111"
3+
mns_account_id = "631615744739"
34
admin_role = "root" # We shouldn't be using the root account. There should be an Admin role
45
dev_ops_role = "role/DevOps"
56
auto_ops_role = "role/auto-ops"
67
dspp_admin_role = "root"
8+
mns_admin_role = "role/nhs-mns-events-lambda-delivery"
79
environment = "dev"
810
parent_route53_zone_name = "dev.vds.platform.nhs.uk"
911
child_route53_zone_name = "imms.dev.vds.platform.nhs.uk"

infra/environments/prod/variables.tfvars

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
imms_account_id = "664418956997"
22
dspp_account_id = "232116723729"
3+
mns_account_id = "758334270304"
34
admin_role = "role/aws-reserved/sso.amazonaws.com/eu-west-2/AWSReservedSSO_PROD-IMMS-Admin_edd6691e4b74064e"
45
dev_ops_role = "role/aws-reserved/sso.amazonaws.com/eu-west-2/AWSReservedSSO_PROD-IMMS-Devops_8f32c62195d56b76"
56
auto_ops_role = "role/auto-ops"
67
dspp_admin_role = "root"
8+
mns_admin_role = "role/nhs-mns-events-lambda-delivery"
79
environment = "prod"
810
parent_route53_zone_name = "prod.vds.platform.nhs.uk"
911
child_route53_zone_name = "imms.prod.vds.platform.nhs.uk"

infra/kms.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ locals {
6666
],
6767
Resource = "*"
6868
}
69+
70+
policy_statement_allow_mns = {
71+
Sid = "AllowMNSLambdaDelivery",
72+
Effect = "Allow",
73+
Principal = {
74+
AWS = "arn:aws:iam::${var.mns_account_id}:${var.mns_admin_role}"
75+
},
76+
Action = "kms:GenerateDataKey",
77+
Resource = "*"
78+
}
6979
}
7080

7181

@@ -147,3 +157,25 @@ resource "aws_kms_alias" "s3_shared_key" {
147157
name = "alias/imms-batch-s3-shared-key"
148158
target_key_id = aws_kms_key.s3_shared_key.key_id
149159
}
160+
161+
resource "aws_kms_key" "id_sync_sqs_encryption" {
162+
description = "KMS key for MNS service access"
163+
key_usage = "ENCRYPT_DECRYPT"
164+
enable_key_rotation = true
165+
policy = jsonencode({
166+
Version = "2012-10-17",
167+
Id = "key-consolepolicy-3",
168+
Statement = [
169+
local.policy_statement_allow_administration,
170+
local.policy_statement_allow_auto_ops,
171+
local.policy_statement_allow_devops,
172+
local.policy_statement_allow_mns
173+
]
174+
})
175+
}
176+
177+
resource "aws_kms_alias" "id_sync_sqs_encryption" {
178+
name = "alias/imms-event-id-sync-encryption"
179+
target_key_id = aws_kms_key.id_sync_sqs_encryption.key_id
180+
}
181+

infra/variables.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ variable "build_agent_account_id" {
1616
variable "environment" {
1717
default = "non-prod"
1818
}
19+
20+
variable "mns_account_id" {}
21+
variable "mns_admin_role" {}

terraform/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ data "aws_kms_key" "existing_kinesis_encryption_key" {
9797
key_id = "alias/imms-batch-kinesis-stream-encryption"
9898
}
9999

100+
data "aws_kms_key" "existing_id_sync_sqs_encryption_key" {
101+
key_id = "alias/imms-event-id-sync-encryption"
102+
}
103+
100104
data "aws_kms_key" "mesh_s3_encryption_key" {
101105
key_id = "alias/local-immunisation-mesh"
102106
}

terraform/sqs_id_sync.tf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
resource "aws_sqs_queue" "id_sync_queue" {
2+
name = "${local.short_prefix}-id-sync-queue"
3+
kms_master_key_id = data.aws_kms_key.existing_id_sync_sqs_encryption_key.arn
4+
visibility_timeout_seconds = 60
5+
redrive_policy = jsonencode({
6+
deadLetterTargetArn = aws_sqs_queue.id_sync_dlq.arn
7+
maxReceiveCount = 4
8+
})
9+
}
10+
11+
resource "aws_sqs_queue" "id_sync_dlq" {
12+
name = "${local.short_prefix}-id-sync-dlq"
13+
}
14+
15+
resource "aws_sqs_queue_redrive_allow_policy" "id_sync_queue_redrive_allow_policy" {
16+
queue_url = aws_sqs_queue.id_sync_dlq.id
17+
18+
redrive_allow_policy = jsonencode({
19+
redrivePermission = "byQueue",
20+
sourceQueueArns = [aws_sqs_queue.id_sync_queue.arn]
21+
})
22+
}
23+
24+
data "aws_iam_policy_document" "id_sync_sqs_policy" {
25+
statement {
26+
sid = "id-sync-queue SQS statement"
27+
effect = "Allow"
28+
29+
principals {
30+
type = "AWS"
31+
identifiers = ["*"]
32+
}
33+
34+
actions = [
35+
"sqs:SendMessage",
36+
"sqs:ReceiveMessage"
37+
]
38+
resources = [
39+
aws_sqs_queue.id_sync_queue.arn
40+
]
41+
}
42+
}
43+
44+
resource "aws_sqs_queue_policy" "id_sync_sqs_policy" {
45+
queue_url = aws_sqs_queue.id_sync_queue.id
46+
policy = data.aws_iam_policy_document.id_sync_sqs_policy.json
47+
}

0 commit comments

Comments
 (0)