Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6021430
Refactor
robertnovac1 Jul 10, 2025
fda28c6
overhaul
robertnovac1 Jul 11, 2025
24feded
Refactoring
robertnovac1 Jul 11, 2025
24caab8
Merge branch 'master' into VED-357-terraform-folder-changes-only
robertnovac1 Jul 11, 2025
cbb8758
Environment var value changed to dev
robertnovac1 Jul 11, 2025
a4043e9
Fixed part of internal-dev resource references
robertnovac1 Jul 11, 2025
175ee54
Cleanup and removed unused resources
robertnovac1 Jul 15, 2025
854947f
PDS check variable
robertnovac1 Jul 15, 2025
76fa46f
Sub envs value coming from makefile
robertnovac1 Jul 15, 2025
93dcb30
Renamed non-prod to dev
robertnovac1 Jul 15, 2025
34a1a0b
Updated readme, pipeline and makefile
robertnovac1 Jul 15, 2025
ea142fe
readme.md
robertnovac1 Jul 15, 2025
97e8cb5
Switched to apply
robertnovac1 Jul 16, 2025
8845e06
Space
robertnovac1 Jul 16, 2025
55e97ce
Merge branch 'master' into VED-357-terraform-folder-changes-only
robertnovac1 Jul 16, 2025
6005b17
config update and refactor mesh
robertnovac1 Jul 16, 2025
c6d099f
Merge branch 'master' into VED-357-terraform-folder-changes-only
robertnovac1 Jul 16, 2025
ecde31a
Comments sorted
robertnovac1 Jul 16, 2025
95fb1c5
Set scope for s3 and dynamo resources
robertnovac1 Jul 16, 2025
95b2e06
Merge branch 'master' into VED-357-terraform-folder-changes-only
robertnovac1 Jul 22, 2025
b5e2bd3
Resolved comments
robertnovac1 Jul 23, 2025
1825f36
Merge branch 'master' into VED-357-terraform-folder-changes-only
robertnovac1 Jul 23, 2025
66f916b
Resolved cooment
robertnovac1 Jul 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions azure/templates/post-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ steps:
set -e
if ! [[ $APIGEE_ENVIRONMENT =~ .*-*sandbox ]]; then
export AWS_PROFILE=apim-dev
aws_account_no="$(aws sts get-caller-identity --query Account --output text)"

service_name=$(FULLY_QUALIFIED_SERVICE_NAME)

pr_no=$(echo $service_name | { grep -oE '[0-9]+$' || true; })
Expand All @@ -58,10 +56,10 @@ steps:
echo Apigee environment: $APIGEE_ENVIRONMENT
echo pr_no: $pr_no

cd terraform
cd terraform

make init
make apply aws_account_no=${aws_account_no} environment=$workspace
make apply environment=${{ parameters.aws_account_type }} sub_environment=$workspace

AWS_DOMAIN_NAME=$(make -s output name=service_domain_name)
IMMS_DELTA_TABLE_NAME=$(make -s output name=imms_delta_table_name)
Expand Down
37 changes: 20 additions & 17 deletions terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 16 additions & 11 deletions terraform/Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
-include .env

interactionId=$(environment)
environment ?= $(ENVIRONMENT)
sub_environment ?= $(SUB_ENVIRONMENT)
sub_environment_dir := $(if $(findstring pr-,$(sub_environment)),pr,$(sub_environment))

aws_profile = apim-dev
tf_cmd = AWS_PROFILE=$(aws_profile) terraform
tf_cmd = AWS_PROFILE=$(AWS_PROFILE) terraform

project_name = immunisation
project_short_name = imms
state_bucket = $(project_name)-$(APIGEE_ENVIRONMENT)-terraform-state-files
tf_state= -backend-config="bucket=$(state_bucket)"
bucket_name = $(if $(filter dev,$(environment)),immunisation-$(sub_environment),immunisation-$(environment))-terraform-state-files

tf_vars= -var="project_name=$(project_name)" -var="project_short_name=$(project_short_name)"
tf_state = -backend-config="bucket=$(bucket_name)"

.PHONY : lock-provider workspace init plan apply clean destroy output state-list lambda-zip catch-all-zip
tf_vars = \
-var="sub_environment=$(sub_environment)" \
-var-file="./environments/$(environment)/$(sub_environment_dir)/variables.tfvars"

lock-provider:
# Run this only when you install a new terraform provider. This will generate sha code in lock file for all platform
echo "This may take a while. Be patient!"
$(tf_cmd) providers lock -platform=darwin_arm64 -platform=darwin_amd64 -platform=linux_amd64 -platform=windows_amd64

workspace:
$(tf_cmd) workspace new $(environment) || $(tf_cmd) workspace select $(environment) && echo "Switched to workspace/environment: $(environment)"
$(tf_cmd) workspace new $(sub_environment) || $(tf_cmd) workspace select $(sub_environment) && echo "Switched to workspace/environment: $(sub_environment)"

init:
$(tf_cmd) init $(tf_state) -upgrade $(tf_vars)

init-reconfigure:
$(tf_cmd) init $(tf_state) -upgrade $(tf_vars) -reconfigure

plan: workspace
$(tf_cmd) plan $(tf_vars)

Expand All @@ -40,7 +43,7 @@ clean:
destroy: workspace
$(tf_cmd) destroy $(tf_vars) -auto-approve
$(tf_cmd) workspace select default
$(tf_cmd) workspace delete $(environment)
$(tf_cmd) workspace delete $(sub_environment)

output:
$(tf_cmd) output -raw $(name)
Expand All @@ -59,3 +62,5 @@ catch-all-zip:

tf-%:
$(tf_cmd) $*

.PHONY : lock-provider workspace init plan apply clean destroy output state-list lambda-zip catch-all-zip
34 changes: 24 additions & 10 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
# immunisation-fhir-api Terraform
# About
The Terraform configuration in this folder is executed in each PR and sets up lambdas associated with the PR. Once the PR is merged, it will be used by the release pipeline to deploy to INT and REF. This is also run by the production release pipeline to deploy the lambdas to the prod blue and green sub environments.

## Setup for local dev
## Environments Structure

Add your workspace name to the env file. This is usually your shortcode.
Terraform is executed via a `Makefile`.
The environment-specific configuration is structured as follows:

```shell
echo environment=your-shortcode >> .env
make init
make workspace
make apply
environments/
└── <ENVIRONMENT>/ # e.g. dev, int, prod (AWS account name)
└── <SUB_ENVIRONMENT_DIR> / # e.g. pr, internal-dev
└── variables.tfvars

The `Makefile` automatically reads the `.env` file to determine the correct `variables.tfvars` file to use, allowing customization of infrastructure for each sub-environment.

## Run locally
1. Create a `.env` file with the following values:
```dotenv
ENVIRONMENT=dev # Target AWS account (e.g., dev, int, prod)
SUB_ENVIRONMENT=pr-123 # Sub-environment (e.g., pr-57, internal-dev)
AWS_REGION=eu-west-2
AWS_PROFILE=your-aws-profile
```
2. Run `make init` to download providers and dependencies
3. Run `make plan` to output plan with the changes that terraform will perform
4. **WARNING**: Run `make apply` only after thoroughly reviewing the plan as this might destroy or modify existing infrastructure

See the Makefile for other commands.
Note: If you switch environment configuration in .env ensure that you run `make init-reconfigure` to reconfigure the backend to prevent migrating the existing state to the new backend.

If you want to apply Terraform to a workspace created by a PR you can set the above environment to the PR number.
If you want to apply Terraform to a workspace created by a PR you can set the above SUB_ENVIRONMENT to the `PR-number` and ENVIRONMENT set to `dev`.
E.g. `pr-57`. You can use this to test out changes when tests fail in CI.
8 changes: 4 additions & 4 deletions terraform/ack_lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ resource "aws_ecr_repository_policy" "ack_lambda_ECRImageRetreival_policy" {
],
"Condition" : {
"StringLike" : {
"aws:sourceArn" : "arn:aws:lambda:eu-west-2:${local.immunisation_account_id}:function:${local.short_prefix}-ack-lambda"
"aws:sourceArn" : "arn:aws:lambda:eu-west-2:${var.immunisation_account_id}:function:${local.short_prefix}-ack-lambda"
}
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ resource "aws_iam_policy" "ack_lambda_exec_policy" {
"logs:CreateLogStream",
"logs:PutLogEvents"
]
Resource = "arn:aws:logs:eu-west-2:${local.immunisation_account_id}:log-group:/aws/lambda/${local.short_prefix}-ack-lambda:*"
Resource = "arn:aws:logs:eu-west-2:${var.immunisation_account_id}:log-group:/aws/lambda/${local.short_prefix}-ack-lambda:*"
},
{
Effect = "Allow"
Expand Down Expand Up @@ -148,7 +148,7 @@ resource "aws_iam_policy" "ack_lambda_exec_policy" {
"sqs:DeleteMessage",
"sqs:GetQueueAttributes"
],
Resource = "arn:aws:sqs:eu-west-2:${local.immunisation_account_id}:${local.short_prefix}-ack-metadata-queue.fifo" },
Resource = "arn:aws:sqs:eu-west-2:${var.immunisation_account_id}:${local.short_prefix}-ack-metadata-queue.fifo" },
{
"Effect" : "Allow",
"Action" : [
Expand Down Expand Up @@ -216,7 +216,7 @@ resource "aws_lambda_function" "ack_processor_lambda" {
variables = {
ACK_BUCKET_NAME = aws_s3_bucket.batch_data_destination_bucket.bucket
SPLUNK_FIREHOSE_NAME = module.splunk.firehose_stream_name
ENVIRONMENT = terraform.workspace
ENVIRONMENT = var.sub_environment
AUDIT_TABLE_NAME = aws_dynamodb_table.audit-table.name
FILE_NAME_PROC_LAMBDA_NAME = aws_lambda_function.file_processor_lambda.function_name
}
Expand Down
31 changes: 0 additions & 31 deletions terraform/api_gateway/acm_cert.tf

This file was deleted.

66 changes: 0 additions & 66 deletions terraform/api_gateway/api.tf

This file was deleted.

11 changes: 0 additions & 11 deletions terraform/api_gateway/variables.tf

This file was deleted.

6 changes: 0 additions & 6 deletions terraform/configs.tf

This file was deleted.

2 changes: 1 addition & 1 deletion terraform/delta.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ resource "aws_ecr_repository_policy" "delta_lambda_ECRImageRetreival_policy" {
],
"Condition" : {
"StringLike" : {
"aws:sourceArn" : "arn:aws:lambda:eu-west-2:${local.immunisation_account_id}:function:${local.short_prefix}-${local.function_name}"
"aws:sourceArn" : "arn:aws:lambda:eu-west-2:${var.immunisation_account_id}:function:${local.short_prefix}-${local.function_name}"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions terraform/dps_role_creation.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "aws_iam_role" "dynamo_s3_access_role" {
{
Effect : "Allow",
Principal : {
AWS : "arn:aws:iam::${local.dspp_core_account_id}:root"
AWS : "arn:aws:iam::${var.dspp_core_account_id}:root"
},
Action : "sts:AssumeRole"
}
Expand All @@ -22,7 +22,7 @@ resource "aws_iam_role_policy" "dynamo_s3_access_policy" {
Statement = [
{
Effect = "Allow",
Action = local.environment == "prod" ? [
Action = var.environment == "prod" ? [
"dynamodb:GetItem",
"dynamodb:Query"
] : [
Expand Down
Loading
Loading