Skip to content

Commit 6005b17

Browse files
committed
config update and refactor mesh
1 parent 55e97ce commit 6005b17

File tree

10 files changed

+41
-26
lines changed

10 files changed

+41
-26
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
environment = "dev"
22
immunisation_account_id = "345594581768"
33
dspp_core_account_id = "603871901111"
4+
pds_environment = "int"
45
pds_check_enabled = false
6+
create_mesh_processor = true
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
environment = "dev"
22
immunisation_account_id = "345594581768"
33
dspp_core_account_id = "603871901111"
4-
create_config_bucket = true
4+
pds_environment = "int"
5+
pds_check_enabled = true
6+
create_mesh_processor = false
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
environment = "dev"
22
immunisation_account_id = "345594581768"
33
dspp_core_account_id = "603871901111"
4+
pds_environment = "int"
5+
pds_check_enabled = true
6+
create_mesh_processor = false

terraform/environments/dev/ref/variables.tfvars

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ environment = "dev"
22
immunisation_account_id = "345594581768"
33
dspp_core_account_id = "603871901111"
44
pds_environment = "ref"
5+
pds_check_enabled = true
6+
create_mesh_processor = false
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
environment = "int"
22
immunisation_account_id = "084828561157"
33
dspp_core_account_id = "603871901111"
4+
pds_environment = "int"
45
pds_check_enabled = false
6+
create_mesh_processor = true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
environment = "int"
22
immunisation_account_id = "084828561157"
33
dspp_core_account_id = "603871901111"
4+
pds_environment = "int"
45
pds_check_enabled = false
6+
create_mesh_processor = true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
environment = "prod"
22
immunisation_account_id = "664418956997"
3+
dspp_core_account_id = "603871901111"
34
pds_environment = "prod"
5+
pds_check_enabled = true
6+
create_mesh_processor = true
7+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
environment = "prod"
22
immunisation_account_id = "664418956997"
3+
dspp_core_account_id = "603871901111"
34
pds_environment = "prod"
5+
pds_check_enabled = true
6+
create_mesh_processor = true

terraform/mesh_processor.tf

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
# Define the directory containing the Docker image and calculate its SHA-256 hash for triggering redeployments
22
locals {
3-
create_mesh_processor = local.environment == "int" || local.environment == "prod"
43
mesh_processor_lambda_dir = abspath("${path.root}/../mesh_processor")
54
mesh_processor_lambda_files = fileset(local.mesh_processor_lambda_dir, "**")
65
mesh_processor_lambda_dir_sha = sha1(join("", [for f in local.mesh_processor_lambda_files : filesha1("${local.mesh_processor_lambda_dir}/${f}")]))
76
# This should match the prefix used in the infra Terraform
8-
mesh_module_prefix = "imms-${local.config_env}"
7+
mesh_s3_bucket_name = "imms-${var.environment}-mesh"
98
}
109

1110
data "aws_s3_bucket" "mesh" {
12-
count = local.create_mesh_processor ? 1 : 0
11+
count = var.create_mesh_processor ? 1 : 0
1312

14-
bucket = "${local.mesh_module_prefix}-mesh"
13+
bucket = local.mesh_s3_bucket_name
1514
}
1615

1716
data "aws_kms_key" "mesh" {
18-
count = local.create_mesh_processor ? 1 : 0
17+
count = var.create_mesh_processor ? 1 : 0
1918

20-
key_id = "alias/${local.mesh_module_prefix}-mesh"
19+
key_id = "alias/${local.mesh_s3_bucket_name}"
2120
}
2221

2322
resource "aws_ecr_repository" "mesh_file_converter_lambda_repository" {
24-
count = local.create_mesh_processor ? 1 : 0
23+
count = var.create_mesh_processor ? 1 : 0
2524

2625
image_scanning_configuration {
2726
scan_on_push = true
@@ -32,7 +31,7 @@ resource "aws_ecr_repository" "mesh_file_converter_lambda_repository" {
3231

3332
# Module for building and pushing Docker image to ECR
3433
module "mesh_processor_docker_image" {
35-
count = local.create_mesh_processor ? 1 : 0
34+
count = var.create_mesh_processor ? 1 : 0
3635

3736
source = "terraform-aws-modules/lambda/aws//modules/docker-build"
3837
version = "8.0.1"
@@ -66,7 +65,7 @@ module "mesh_processor_docker_image" {
6665

6766
# Define the lambdaECRImageRetreival policy
6867
resource "aws_ecr_repository_policy" "mesh_processor_lambda_ECRImageRetreival_policy" {
69-
count = local.create_mesh_processor ? 1 : 0
68+
count = var.create_mesh_processor ? 1 : 0
7069

7170
repository = aws_ecr_repository.mesh_file_converter_lambda_repository[0].name
7271

@@ -98,7 +97,7 @@ resource "aws_ecr_repository_policy" "mesh_processor_lambda_ECRImageRetreival_po
9897

9998
# IAM Role for Lambda
10099
resource "aws_iam_role" "mesh_processor_lambda_exec_role" {
101-
count = local.create_mesh_processor ? 1 : 0
100+
count = var.create_mesh_processor ? 1 : 0
102101

103102
name = "${local.short_prefix}-mesh_processor-lambda-exec-role"
104103
assume_role_policy = jsonencode({
@@ -116,7 +115,7 @@ resource "aws_iam_role" "mesh_processor_lambda_exec_role" {
116115

117116
# Policy for Lambda execution role
118117
resource "aws_iam_policy" "mesh_processor_lambda_exec_policy" {
119-
count = local.create_mesh_processor ? 1 : 0
118+
count = var.create_mesh_processor ? 1 : 0
120119

121120
name = "${local.short_prefix}-mesh_processor-lambda-exec-policy"
122121
policy = jsonencode({
@@ -163,7 +162,7 @@ resource "aws_iam_policy" "mesh_processor_lambda_exec_policy" {
163162
}
164163

165164
resource "aws_iam_policy" "mesh_processor_lambda_kms_access_policy" {
166-
count = local.create_mesh_processor ? 1 : 0
165+
count = var.create_mesh_processor ? 1 : 0
167166

168167
name = "${local.short_prefix}-mesh_processor-lambda-kms-policy"
169168
description = "Allow Lambda to decrypt environment variables"
@@ -188,7 +187,7 @@ resource "aws_iam_policy" "mesh_processor_lambda_kms_access_policy" {
188187

189188
# Attach the execution policy to the Lambda role
190189
resource "aws_iam_role_policy_attachment" "mesh_processor_lambda_exec_policy_attachment" {
191-
count = local.create_mesh_processor ? 1 : 0
190+
count = var.create_mesh_processor ? 1 : 0
192191

193192
role = aws_iam_role.mesh_processor_lambda_exec_role[0].name
194193
policy_arn = aws_iam_policy.mesh_processor_lambda_exec_policy[0].arn
@@ -197,15 +196,15 @@ resource "aws_iam_role_policy_attachment" "mesh_processor_lambda_exec_policy_att
197196

198197
# Attach the kms policy to the Lambda role
199198
resource "aws_iam_role_policy_attachment" "mesh_processor_lambda_kms_policy_attachment" {
200-
count = local.create_mesh_processor ? 1 : 0
199+
count = var.create_mesh_processor ? 1 : 0
201200

202201
role = aws_iam_role.mesh_processor_lambda_exec_role[0].name
203202
policy_arn = aws_iam_policy.mesh_processor_lambda_kms_access_policy[0].arn
204203
}
205204

206205
# Lambda Function with Security Group and VPC.
207206
resource "aws_lambda_function" "mesh_file_converter_lambda" {
208-
count = local.create_mesh_processor ? 1 : 0
207+
count = var.create_mesh_processor ? 1 : 0
209208

210209
function_name = "${local.short_prefix}-mesh_processor_lambda"
211210
role = aws_iam_role.mesh_processor_lambda_exec_role[0].arn
@@ -223,7 +222,7 @@ resource "aws_lambda_function" "mesh_file_converter_lambda" {
223222

224223
# Permission for S3 to invoke Lambda function
225224
resource "aws_lambda_permission" "mesh_s3_invoke_permission" {
226-
count = local.create_mesh_processor ? 1 : 0
225+
count = var.create_mesh_processor ? 1 : 0
227226

228227
statement_id = "AllowExecutionFromS3"
229228
action = "lambda:InvokeFunction"
@@ -233,7 +232,7 @@ resource "aws_lambda_permission" "mesh_s3_invoke_permission" {
233232
}
234233

235234
resource "aws_s3_bucket_notification" "mesh_datasources_lambda_notification" {
236-
count = local.create_mesh_processor ? 1 : 0
235+
count = var.create_mesh_processor ? 1 : 0
237236

238237
bucket = data.aws_s3_bucket.mesh[0].bucket
239238

@@ -244,7 +243,7 @@ resource "aws_s3_bucket_notification" "mesh_datasources_lambda_notification" {
244243
}
245244

246245
resource "aws_cloudwatch_log_group" "mesh_file_converter_log_group" {
247-
count = local.create_mesh_processor ? 1 : 0
246+
count = var.create_mesh_processor ? 1 : 0
248247

249248
name = "/aws/lambda/${local.short_prefix}-mesh_processor_lambda"
250249
retention_in_days = 30

terraform/variables.tf

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
variable "environment" {}
22

33
variable "sub_environment" {
4-
description = "The value is passed in the makefile"
4+
description = "The value is set in the makefile"
55
}
66

77
variable "immunisation_account_id" {}
88
variable "dspp_core_account_id" {}
9-
# For now, only create the config bucket in internal-dev and prod as we only have one Redis instance per account.
10-
variable "create_config_bucket" {
9+
10+
variable "create_mesh_processor" {
1111
default = false
1212
}
1313

@@ -38,10 +38,6 @@ variable "pds_check_enabled" {
3838
default = true
3939
}
4040

41-
variable "root_domain" {
42-
default = "imms.dev.vds.platform.nhs.uk"
43-
}
44-
4541
locals {
4642
prefix = "${var.project_name}-${var.service}-${var.sub_environment}"
4743
short_prefix = "${var.project_short_name}-${var.sub_environment}"

0 commit comments

Comments
 (0)