Skip to content

Commit a4043e9

Browse files
committed
Fixed part of internal-dev resource references
1 parent cbb8758 commit a4043e9

File tree

10 files changed

+31
-38
lines changed

10 files changed

+31
-38
lines changed

terraform/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ init-reconfigure:
1919
$(tf_cmd) init $(tf_state) -upgrade $(tf_vars) -reconfigure
2020

2121
plan: workspace
22-
$(tf_cmd) plan $(tf_vars)
22+
$(tf_cmd) plan $(tf_vars) -out=tfplan
2323

2424
plan-changes: workspace
2525
$(tf_cmd) plan $(tf_vars) -out=plan && $(tf_cmd) show -no-color -json plan | jq -r '.resource_changes[] | select(.change.actions[0]=="update" or .change.actions[0]=="create" or .change.actions[0]=="add") | .address'

terraform/ack_lambda.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ resource "aws_lambda_function" "ack_processor_lambda" {
216216
variables = {
217217
ACK_BUCKET_NAME = aws_s3_bucket.batch_data_destination_bucket.bucket
218218
SPLUNK_FIREHOSE_NAME = module.splunk.firehose_stream_name
219-
ENVIRONMENT = terraform.workspace
219+
ENVIRONMENT = var.sub_environment
220220
AUDIT_TABLE_NAME = aws_dynamodb_table.audit-table.name
221221
FILE_NAME_PROC_LAMBDA_NAME = aws_lambda_function.file_processor_lambda.function_name
222222
}

terraform/endpoints.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ locals {
2323
imms_table_name = aws_dynamodb_table.events-dynamodb-table.name
2424
imms_lambda_env_vars = {
2525
"DYNAMODB_TABLE_NAME" = local.imms_table_name,
26-
"IMMUNIZATION_ENV" = var.environment,
27-
"IMMUNIZATION_BASE_PATH" = strcontains(var.environment, "pr-") ? "immunisation-fhir-api-${var.environment}" : "immunisation-fhir-api"
26+
"IMMUNIZATION_ENV" = var.sub_environment,
27+
"IMMUNIZATION_BASE_PATH" = strcontains(terraform.workspace, "pr-") ? "immunisation-fhir-api-${terraform.workspace}" : "immunisation-fhir-api"
2828
# except for prod and ref, any other env uses PDS int environment
29-
"PDS_ENV" = var.environment == "prod" ? "prod" : var.environment == "ref" ? "ref" : "int",
29+
"PDS_ENV" = var.pds_environment
3030
"PDS_CHECK_ENABLED" = tostring(var.environment != "int")
3131
"SPLUNK_FIREHOSE_NAME" = module.splunk.firehose_stream_name
3232
"SQS_QUEUE_URL" = "https://sqs.eu-west-2.amazonaws.com/${var.immunisation_account_id}/${local.short_prefix}-ack-metadata-queue.fifo"

terraform/environments/non-prod/ref/variables.tfvars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ environment = "dev"
22
sub_environment = "ref"
33
immunisation_account_id = "345594581768"
44
dspp_core_account_id = "603871901111"
5+
pds_environment = "ref"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
environment = "prod"
22
sub_environment = "blue"
33
immunisation_account_id = "664418956997"
4+
pds_environment = "prod"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
environment = "prod"
22
sub_environment = "green"
33
immunisation_account_id = "664418956997"
4+
pds_environment = "prod"

terraform/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ terraform {
1717
}
1818

1919
provider "aws" {
20-
region = var.aws_region
21-
profile = "apim-dev"
20+
region = var.aws_region
21+
#profile = "apim-dev"
2222
default_tags {
2323
tags = {
2424
Project = var.project_name
25-
Environment = var.environment
25+
Environment = var.sub_environment
2626
Service = var.service
2727
}
2828
}

terraform/mesh_processor.tf

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Note: This is all disabled in the preprod environment
21
# Define the directory containing the Docker image and calculate its SHA-256 hash for triggering redeployments
32
locals {
43
mesh_processor_lambda_dir = abspath("${path.root}/../mesh_processor")
@@ -8,7 +7,6 @@ locals {
87

98

109
resource "aws_ecr_repository" "mesh_file_converter_lambda_repository" {
11-
count = var.environment == "int" ? 0 : 1
1210
image_scanning_configuration {
1311
scan_on_push = true
1412
}
@@ -18,12 +16,11 @@ resource "aws_ecr_repository" "mesh_file_converter_lambda_repository" {
1816

1917
# Module for building and pushing Docker image to ECR
2018
module "mesh_processor_docker_image" {
21-
count = var.environment == "int" ? 0 : 1
2219
source = "terraform-aws-modules/lambda/aws//modules/docker-build"
2320
version = "8.0.1"
2421

2522
create_ecr_repo = false
26-
ecr_repo = aws_ecr_repository.mesh_file_converter_lambda_repository[0].name
23+
ecr_repo = aws_ecr_repository.mesh_file_converter_lambda_repository.name
2724
ecr_repo_lifecycle_policy = jsonencode({
2825
"rules" : [
2926
{
@@ -51,8 +48,7 @@ module "mesh_processor_docker_image" {
5148

5249
# Define the lambdaECRImageRetreival policy
5350
resource "aws_ecr_repository_policy" "mesh_processor_lambda_ECRImageRetreival_policy" {
54-
count = var.environment == "int" ? 0 : 1
55-
repository = aws_ecr_repository.mesh_file_converter_lambda_repository[0].name
51+
repository = aws_ecr_repository.mesh_file_converter_lambda_repository.name
5652

5753
policy = jsonencode({
5854
Version = "2012-10-17"
@@ -82,8 +78,7 @@ resource "aws_ecr_repository_policy" "mesh_processor_lambda_ECRImageRetreival_po
8278

8379
# IAM Role for Lambda
8480
resource "aws_iam_role" "mesh_processor_lambda_exec_role" {
85-
count = var.environment == "int" ? 0 : 1
86-
name = "${local.short_prefix}-mesh_processor-lambda-exec-role"
81+
name = "${local.short_prefix}-mesh_processor-lambda-exec-role"
8782
assume_role_policy = jsonencode({
8883
Version = "2012-10-17",
8984
Statement = [{
@@ -99,8 +94,7 @@ resource "aws_iam_role" "mesh_processor_lambda_exec_role" {
9994

10095
# Policy for Lambda execution role
10196
resource "aws_iam_policy" "mesh_processor_lambda_exec_policy" {
102-
count = var.environment == "int" ? 0 : 1
103-
name = "${local.short_prefix}-mesh_processor-lambda-exec-policy"
97+
name = "${local.short_prefix}-mesh_processor-lambda-exec-policy"
10498
policy = jsonencode({
10599
Version = "2012-10-17",
106100
Statement = [
@@ -146,7 +140,6 @@ resource "aws_iam_policy" "mesh_processor_lambda_exec_policy" {
146140
}
147141

148142
resource "aws_iam_policy" "mesh_processor_lambda_kms_access_policy" {
149-
count = var.environment == "int" ? 0 : 1
150143
name = "${local.short_prefix}-mesh_processor-lambda-kms-policy"
151144
description = "Allow Lambda to decrypt environment variables"
152145

@@ -161,7 +154,7 @@ resource "aws_iam_policy" "mesh_processor_lambda_kms_access_policy" {
161154
"kms:GenerateDataKey*"
162155
]
163156
Resource = [
164-
data.aws_kms_key.mesh_s3_encryption_key[0].arn
157+
data.aws_kms_key.mesh_s3_encryption_key.arn
165158
# "arn:aws:kms:eu-west-2:345594581768:key/9b756762-bc6f-42fb-ba56-2c0c00c15289"
166159
]
167160
}
@@ -171,44 +164,39 @@ resource "aws_iam_policy" "mesh_processor_lambda_kms_access_policy" {
171164

172165
# Attach the execution policy to the Lambda role
173166
resource "aws_iam_role_policy_attachment" "mesh_processor_lambda_exec_policy_attachment" {
174-
count = var.environment == "int" ? 0 : 1
175-
role = aws_iam_role.mesh_processor_lambda_exec_role[0].name
176-
policy_arn = aws_iam_policy.mesh_processor_lambda_exec_policy[0].arn
167+
role = aws_iam_role.mesh_processor_lambda_exec_role.name
168+
policy_arn = aws_iam_policy.mesh_processor_lambda_exec_policy.arn
177169
}
178170

179171

180172
# Attach the kms policy to the Lambda role
181173
resource "aws_iam_role_policy_attachment" "mesh_processor_lambda_kms_policy_attachment" {
182-
count = var.environment == "int" ? 0 : 1
183-
role = aws_iam_role.mesh_processor_lambda_exec_role[0].name
184-
policy_arn = aws_iam_policy.mesh_processor_lambda_kms_access_policy[0].arn
174+
role = aws_iam_role.mesh_processor_lambda_exec_role.name
175+
policy_arn = aws_iam_policy.mesh_processor_lambda_kms_access_policy.arn
185176
}
186177

187178
# Lambda Function with Security Group and VPC.
188179
resource "aws_lambda_function" "mesh_file_converter_lambda" {
189-
count = var.environment == "int" ? 0 : 1
190180
function_name = "${local.short_prefix}-mesh_processor_lambda"
191-
role = aws_iam_role.mesh_processor_lambda_exec_role[0].arn
181+
role = aws_iam_role.mesh_processor_lambda_exec_role.arn
192182
package_type = "Image"
193-
image_uri = module.mesh_processor_docker_image[0].image_uri
183+
image_uri = module.mesh_processor_docker_image.image_uri
194184
architectures = ["x86_64"]
195185
timeout = 360
196186

197187
environment {
198188
variables = {
199-
Destination_BUCKET_NAME = aws_s3_bucket.batch_data_source_bucket.bucket
200-
MESH_FILE_PROC_LAMBDA_NAME = "imms-${var.sub_environment}-meshfileproc_lambda"
189+
Destination_BUCKET_NAME = aws_s3_bucket.batch_data_source_bucket.bucket
201190
}
202191
}
203192

204193
}
205194

206195
# Permission for S3 to invoke Lambda function
207196
resource "aws_lambda_permission" "mesh_s3_invoke_permission" {
208-
count = var.environment == "int" ? 0 : 1
209197
statement_id = "AllowExecutionFromS3"
210198
action = "lambda:InvokeFunction"
211-
function_name = aws_lambda_function.mesh_file_converter_lambda[0].function_name
199+
function_name = aws_lambda_function.mesh_file_converter_lambda.function_name
212200
principal = "s3.amazonaws.com"
213201
source_arn = "arn:aws:s3:::local-immunisation-mesh"
214202
}
@@ -218,18 +206,16 @@ resource "aws_lambda_permission" "mesh_s3_invoke_permission" {
218206
# S3 Bucket notification to trigger Lambda function
219207
resource "aws_s3_bucket_notification" "mesh_datasources_lambda_notification" {
220208
# TODO - what is this bucket and why isn't it managed by Terraform?
221-
count = var.environment == "int" ? 0 : 1
222209
bucket = "local-immunisation-mesh"
223210

224211
lambda_function {
225-
lambda_function_arn = aws_lambda_function.mesh_file_converter_lambda[0].arn
212+
lambda_function_arn = aws_lambda_function.mesh_file_converter_lambda.arn
226213
events = ["s3:ObjectCreated:*"]
227214
#filter_prefix =""
228215
}
229216
}
230217

231218
resource "aws_cloudwatch_log_group" "mesh_file_converter_log_group" {
232-
count = var.environment == "int" ? 0 : 1
233219
name = "/aws/lambda/${local.short_prefix}-mesh_processor_lambda"
234220
retention_in_days = 30
235221
}

terraform/s3_config.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "datasources_lifecycle" {
9393

9494
resource "aws_s3_bucket" "batch_data_destination_bucket" {
9595
# Deliberately not using `local.batch_prefix` as we don't want separate blue / green destinations in prod.
96-
bucket = "immunisation-batch-${var.environment}-data-destinations"
96+
bucket = "immunisation-batch-${var.sub_environment}-data-destinations"
9797
force_destroy = local.is_temp
9898
}
9999

@@ -192,7 +192,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "data_destinations" {
192192
}
193193

194194
resource "aws_s3_bucket" "batch_config_bucket" {
195-
bucket = "imms-${var.environment}-fhir-config"
195+
bucket = "imms-${var.sub_environment}-fhir-config"
196196
}
197197

198198
resource "aws_s3_bucket_public_access_block" "batch_config_bucket_public_access_block" {

terraform/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ variable "aws_region" {
2626
default = "eu-west-2"
2727
}
2828

29+
variable "pds_environment" {
30+
default = "int"
31+
}
32+
2933
locals {
3034
prefix = "${var.project_name}-${var.service}-${var.sub_environment}"
3135
short_prefix = "${var.project_short_name}-${var.sub_environment}"

0 commit comments

Comments
 (0)