Skip to content

Commit 07a74eb

Browse files
committed
Updated infra folder to handle new INT environment
1 parent db3656f commit 07a74eb

File tree

6 files changed

+83
-59
lines changed

6 files changed

+83
-59
lines changed

infra/.terraform.lock.hcl

Lines changed: 16 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/Makefile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
-include .env
2+
3+
environment=$(ENVIRONMENT)
4+
5+
tf_cmd = AWS_PROFILE=$(AWS_PROFILE) terraform
6+
7+
project_name = immunisation
8+
project_short_name = imms
9+
tf_state=-backend-config="bucket=immunisation-preprod-infra-terraform-state-files"
10+
11+
12+
.PHONY : lock-provider workspace init plan apply clean destroy output state-list lambda-zip catch-all-zip
13+
14+
lock-provider:
15+
# Run this only when you install a new terraform provider. This will generate sha code in lock file for all platform
16+
echo "This may take a while. Be patient!"
17+
$(tf_cmd) providers lock -platform=darwin_arm64 -platform=darwin_amd64 -platform=linux_amd64 -platform=windows_amd64
18+
19+
workspace:
20+
$(tf_cmd) workspace new $(environment) || $(tf_cmd) workspace select $(environment) && echo "Switched to workspace/environment: $(environment)"
21+
22+
init:
23+
$(tf_cmd) init $(tf_state) -upgrade
24+
25+
init-reconfigure:
26+
$(tf_cmd) init $(tf_state) -upgrade -reconfigure
27+
28+
plan:
29+
$(tf_cmd) plan
30+
31+
plan-changes: workspace
32+
$(tf_cmd) plan -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'
33+
34+
apply: workspace
35+
$(tf_cmd) apply -auto-approve
36+
37+
clean:
38+
rm -rf build .terraform upload-key
39+
40+
destroy: workspace
41+
$(tf_cmd) destroy -auto-approve
42+
$(tf_cmd) workspace select default
43+
$(tf_cmd) workspace delete $(environment)
44+
45+
output:
46+
$(tf_cmd) output -raw $(name)
47+
48+
#Make lambda zip file in /terraform/zips directory. Whenever code gets changed in lamdba_typescript directory , new zip file gets uploaded to s3. For local,you can you this make target
49+
lambda-zip:
50+
cd ../lambda_typescript && \
51+
chmod +x ./deploy.sh && \
52+
./deploy.sh

infra/endpoints.tf

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,6 @@ resource "aws_vpc_endpoint" "kinesis_stream_endpoint" {
218218
}
219219
}
220220

221-
# TODO - remove and use the key we manage in this Terraform workspace
222-
data "aws_kms_key" "existing_lambda_env_encryption" {
223-
count = local.account != "prod" ? 1 : 0
224-
225-
key_id = "648c8c6f-54bf-4b79-ad72-0be6e8d72423"
226-
}
227221

228222
resource "aws_vpc_endpoint" "kms_endpoint" {
229223
vpc_id = data.aws_vpc.default.id
@@ -247,13 +241,9 @@ resource "aws_vpc_endpoint" "kms_endpoint" {
247241
"kms:Encrypt",
248242
"kms:GenerateDataKey*"
249243
],
250-
Resource = local.account == "prod" ? [
244+
Resource = [
251245
aws_kms_key.lambda_env_encryption.arn,
252246
aws_kms_key.s3_shared_key.arn
253-
] : [
254-
aws_kms_key.lambda_env_encryption.arn,
255-
aws_kms_key.s3_shared_key.arn,
256-
data.aws_kms_key.existing_lambda_env_encryption[0].arn
257247
]
258248
}
259249
]

infra/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ terraform {
1313
}
1414

1515
provider "aws" {
16-
region = var.aws_region
17-
profile = "apim-dev"
16+
region = var.aws_region
17+
#profile = "apim-dev"
1818
default_tags {
1919
tags = {
2020
Project = "immunisation-fhir-api"

infra/s3_source_bucket.tf

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
locals {
2+
bucket_name = local.immunisation_account_id == "084828561157" ? "immunisation-batch-${local.account}-preprod-data-sources" : "immunisation-batch-${local.account}-data-sources"
3+
}
4+
15
# Overall entry point into batch in prod. Files are forwarded into the appropriate blue / green bucket.
26
resource "aws_s3_bucket" "batch_data_source_bucket" {
3-
count = local.account == "prod" ? 1 : 0
4-
bucket = "immunisation-batch-${local.account}-data-sources"
7+
count = 1
8+
bucket = local.bucket_name
59
}
610

711
resource "aws_s3_bucket_public_access_block" "batch_data_source_bucket_public_access_block" {
8-
count = local.account == "prod" ? 1 : 0
12+
count = 1
913
bucket = aws_s3_bucket.batch_data_source_bucket[0].id
1014

1115
block_public_acls = true
@@ -15,7 +19,7 @@ resource "aws_s3_bucket_public_access_block" "batch_data_source_bucket_public_ac
1519
}
1620

1721
resource "aws_s3_bucket_policy" "batch_data_source_bucket_policy" {
18-
count = local.account == "prod" ? 1 : 0
22+
count = 1
1923
bucket = aws_s3_bucket.batch_data_source_bucket[0].bucket
2024
policy = jsonencode({
2125
Version : "2012-10-17",
@@ -67,7 +71,7 @@ resource "aws_s3_bucket_policy" "batch_data_source_bucket_policy" {
6771
# }
6872

6973
resource "aws_s3_bucket_lifecycle_configuration" "datasources_lifecycle" {
70-
count = local.account == "prod" ? 1 : 0
74+
count = 1
7175
bucket = aws_s3_bucket.batch_data_source_bucket[0].bucket
7276

7377
rule {

infra/variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
data "aws_vpc" "default" {
2-
default = true
2+
id = "vpc-0c87d4383f6f013c3"
33
}
44

55
data "aws_subnets" "default" {
@@ -19,8 +19,8 @@ variable "aws_region" {
1919

2020
locals {
2121
account = terraform.workspace # non-prod or prod
22-
dspp_core_account_id = local.account == "prod" ? 232116723729 : 603871901111
23-
immunisation_account_id = local.account == "prod" ? 664418956997 : 084828561157
22+
dspp_core_account_id = local.account == "prod" ? "232116723729" : "603871901111"
23+
immunisation_account_id = local.account == "prod" ? "664418956997" : "084828561157"
2424
# TODO - add new accounts for CDP migration
2525
}
2626

0 commit comments

Comments
 (0)