Skip to content

Commit 26be64b

Browse files
committed
local (temp) id_sync KMS key
1 parent 8b4bf77 commit 26be64b

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

terraform/temp_id_sync_sqs_kms.tf

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# NOTE. This is a temporary file.
2+
# Eventually the aws_kms_key "id_sync_sqs_key" will go into infra/kms.tf
3+
4+
locals {
5+
policy_statement_allow_administration = {
6+
Sid = "AllowKeyAdministration",
7+
Effect = "Allow",
8+
Principal = {
9+
AWS = "arn:aws:iam::${var.imms_account_id}:${var.admin_role}"
10+
},
11+
Action = [
12+
"kms:Create*",
13+
"kms:Describe*",
14+
"kms:Enable*",
15+
"kms:List*",
16+
"kms:Put*",
17+
"kms:Update*",
18+
"kms:Revoke*",
19+
"kms:Disable*",
20+
"kms:Get*",
21+
"kms:Delete*",
22+
"kms:ScheduleKeyDeletion",
23+
"kms:CancelKeyDeletion",
24+
"kms:GenerateDataKey*",
25+
"kms:Decrypt",
26+
"kms:Tag*"
27+
],
28+
Resource = "*"
29+
}
30+
31+
policy_statement_allow_auto_ops = {
32+
Sid = "KMSKeyUserAccess",
33+
Effect = "Allow",
34+
Principal = {
35+
AWS = "arn:aws:iam::${var.imms_account_id}:${var.auto_ops_role}"
36+
},
37+
Action = [
38+
"kms:Encrypt",
39+
"kms:GenerateDataKey*"
40+
],
41+
Resource = "*"
42+
}
43+
44+
policy_statement_allow_devops = {
45+
Sid = "KMSKeyUserAccessForDevOps",
46+
Effect = "Allow",
47+
Principal = {
48+
AWS = "arn:aws:iam::${var.imms_account_id}:${var.dev_ops_role}"
49+
},
50+
Action = [
51+
"kms:Encrypt",
52+
"kms:GenerateDataKey*"
53+
],
54+
Resource = "*"
55+
}
56+
57+
# New elements relating to id_sync are below here
58+
59+
# mns_account_id: ultimately these should go in infra/environments/<env>/variables.tfvars
60+
mns_account_id = local.environment == "prod" ? 758334270304 : 631615744739
61+
mns_admin_role = "role"
62+
63+
policy_statement_allow_mns = {
64+
Sid = "AllowMNSLambdaDelivery",
65+
Effect = "Allow",
66+
Principal = {
67+
AWS = "arn:aws:iam::${local.mns_account_id}:${local.mns_admin_role}"/nhs-mns-events-lambda-delivery"
68+
},
69+
Action = "kms:GenerateDataKey",
70+
Resource = "*"
71+
}
72+
}
73+
74+
resource "aws_kms_key" "id_sync_sqs_encryption" {
75+
description = "KMS key for MNS service access"
76+
key_usage = "ENCRYPT_DECRYPT"
77+
enable_key_rotation = true
78+
policy = jsonencode({
79+
Version = "2012-10-17",
80+
Id = "key-consolepolicy-3",
81+
Statement = [
82+
local.policy_statement_allow_administration,
83+
local.policy_statement_allow_auto_ops,
84+
local.policy_statement_allow_devops,
85+
local.policy_statement_allow_mns
86+
]
87+
})
88+
}
89+
90+
resource "aws_kms_alias" "id_sync_sqs_encryption" {
91+
name = "alias/imms-event-id-sync-sqs-encryption"
92+
target_key_id = aws_kms_key.id_sync_sqs_encryption.key_id
93+
}

0 commit comments

Comments
 (0)