Skip to content

Commit

Permalink
[PRMP-639] - new resources
Browse files Browse the repository at this point in the history
  • Loading branch information
NogaNHS committed Jul 25, 2024
1 parent ef34064 commit 2e2a108
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 104 deletions.
33 changes: 0 additions & 33 deletions stacks/gp-registrations-mi/terraform/bulk-ods-update.tf

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
resource "aws_dynamodb_table" "mi-api-ods_dynamodb_table" {
resource "aws_dynamodb_table" "mi_api_gp_ods" {
name = "${var.environment}_mi_enrichment_practice_ods"
billing_mode = "PAY_PER_REQUEST"
deletion_protection_enabled = false

hash_key = "PracticeOdsCode"
hash_key = "PracticeOdsCode"

attribute {
name = "PracticeOdsCode"
type = "S"
}

attribute {
name = "PracticeName"
type = "S"
}

attribute {
name = "IcbOdsCode"
type = "S"
}

attribute {
name = "SupplierName"
type = "S"
}

attribute {
name = "SDSLastUpdated"
type = "N"
}

tags = {
Name = "mi_enrichment_practice_ods"
Environment = var.environment
}

import_table {
input_format = "CSV"
input_compression_type = "NONE"
s3_bucket_source {
bucket = aws_s3_bucket.ods_csv_files.id
key_prefix = aws_s3_object.initial_gp_ods.key
}
input_format_options {
csv {
delimiter = ","
header_list = ["PracticeOdsCode", "PracticeName", "IcbOdsCode"]
}
}
}
}

resource "aws_iam_policy" "dynamodb_policy_ods_enrichment_lambda" {
name = "${var.environment}_${aws_dynamodb_table.mi-api-ods_dynamodb_table.name}_policy"
name = "${var.environment}_${aws_dynamodb_table.mi_api_gp_ods.name}_policy"
path = "/"

policy = jsonencode({
Expand All @@ -52,10 +46,9 @@ resource "aws_iam_policy" "dynamodb_policy_ods_enrichment_lambda" {
"dynamodb:PutItem",
],
"Resource" : [
aws_dynamodb_table.mi-api-ods_dynamodb_table.arn
aws_dynamodb_table.mi_api_gp_ods.arn
]
}

]
})
}
Expand All @@ -73,10 +66,9 @@ resource "aws_iam_policy" "dynamodb_policy_bulk_ods_data_lambda" {
"dynamodb:UpdateItem",
],
"Resource" : [
aws_dynamodb_table.mi-api-ods_dynamodb_table.arn
aws_dynamodb_table.mi_api_gp_ods.arn
]
}

]
})
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
resource "aws_dynamodb_table" "mi-api-icb-ods_dynamodb_table" {
resource "aws_dynamodb_table" "mi_api_icb_ods" {
name = "${var.environment}_mi_enrichment_icb_ods"
billing_mode = "PAY_PER_REQUEST"
deletion_protection_enabled = false
hash_key = "IcbOdsCode"
hash_key = "IcbOdsCode"

attribute {
name = "IcbOdsCode"
type = "S"
}

attribute {
name = "IcbName"
type = "S"

import_table {
input_format = "CSV"
input_compression_type = "NONE"
s3_bucket_source {
bucket = aws_s3_bucket.ods_csv_files.id
key_prefix = aws_s3_object.initial_icb_ods.key
}

input_format_options {
csv {
delimiter = ","
header_list = ["IcbOdsCode", "IcbName"]
}
}
}

tags = {
Expand All @@ -21,7 +33,7 @@ resource "aws_dynamodb_table" "mi-api-icb-ods_dynamodb_table" {
}

resource "aws_iam_policy" "dynamodb_policy_icb_ods_enrichment_lambda" {
name = "${var.environment}_${aws_dynamodb_table.mi-api-icb-ods_dynamodb_table.name}_policy"
name = "${var.environment}_${aws_dynamodb_table.mi_api_icb_ods.name}_policy"
path = "/"

policy = jsonencode({
Expand All @@ -33,18 +45,17 @@ resource "aws_iam_policy" "dynamodb_policy_icb_ods_enrichment_lambda" {
"dynamodb:GetItem",
"dynamodb:UpdateItem",
"dynamodb:PutItem",

],
"Resource" : [
aws_dynamodb_table.mi-api-ods_dynamodb_table.arn
aws_dynamodb_table.mi_api_icb_ods.arn
]
}
]
})
}

resource "aws_iam_policy" "dynamodb_policy_bulk_icb_ods_data_lambda" {
name = "${var.environment}_mi_bulk_${aws_dynamodb_table.mi-api-icb-ods_dynamodb_table.name}_policy"
name = "${var.environment}_mi_bulk_${aws_dynamodb_table.mi_api_icb_ods.name}_policy"
path = "/"

policy = jsonencode({
Expand All @@ -56,7 +67,7 @@ resource "aws_iam_policy" "dynamodb_policy_bulk_icb_ods_data_lambda" {
"dynamodb:UpdateItem",
],
"Resource" : [
aws_dynamodb_table.mi-api-icb-ods_dynamodb_table.arn
aws_dynamodb_table.mi_api_icb_ods.arn
]
}
]
Expand Down
24 changes: 12 additions & 12 deletions stacks/gp-registrations-mi/terraform/event-enrichment-lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ variable "event_enrichment_lambda_name" {
}

resource "aws_lambda_function" "event_enrichment_lambda" {
filename = "${path.cwd}/${var.event_enrichment_lambda_zip}"
function_name = "${var.environment}-${var.event_enrichment_lambda_name}"
role = aws_iam_role.event_enrichment_lambda_role.arn
handler = "event_enrichment_main.lambda_handler"
filename = "${path.cwd}/${var.event_enrichment_lambda_zip}"
function_name = "${var.environment}-${var.event_enrichment_lambda_name}"
role = aws_iam_role.event_enrichment_lambda_role.arn
handler = "event_enrichment_main.lambda_handler"
source_code_hash = filebase64sha256("${path.cwd}/${var.event_enrichment_lambda_zip}")
runtime = "python3.12"
timeout = 300
runtime = "python3.12"
timeout = 300
tags = merge(
local.common_tags,
{
Name = "${var.environment}-gp-registrations-mi"
Name = "${var.environment}-gp-registrations-mi"
ApplicationRole = "AwsLambdaFunction"
}
)

environment {
variables = {
SPLUNK_CLOUD_EVENT_UPLOADER_SQS_QUEUE_URL = aws_sqs_queue.incoming_mi_events_for_splunk_cloud_event_uploader.url,
ENRICHED_EVENTS_SNS_TOPIC_ARN = aws_sns_topic.enriched_events_topic.arn,
SDS_FHIR_API_KEY_PARAM_NAME = var.sds_fhir_api_key_param_name,
SDS_FHIR_API_URL_PARAM_NAME = var.sds_fhir_api_url_param_name,
ENRICHED_EVENTS_SNS_TOPIC_ARN = aws_sns_topic.enriched_events_topic.arn,
SDS_FHIR_API_KEY_PARAM_NAME = var.sds_fhir_api_key_param_name,
SDS_FHIR_API_URL_PARAM_NAME = var.sds_fhir_api_url_param_name,
}
}
}
Expand All @@ -35,7 +35,7 @@ resource "aws_lambda_event_source_mapping" "sqs_queue_event_enrichment_lambda_tr
filter {
pattern = jsonencode({
body = {
eventType : [ { "anything-but": [ "DEGRADES" ] } ]
eventType : [{ "anything-but" : ["DEGRADES"] }]
}
})
}
Expand All @@ -47,7 +47,7 @@ resource "aws_cloudwatch_log_group" "event_enrichment_lambda" {
tags = merge(
local.common_tags,
{
Name = "${var.environment}-${var.event_enrichment_lambda_name}"
Name = "${var.environment}-${var.event_enrichment_lambda_name}"
ApplicationRole = "AwsCloudwatchLogGroup"
}
)
Expand Down
4 changes: 2 additions & 2 deletions stacks/gp-registrations-mi/terraform/iam-event-enrichment.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Lambda
resource "aws_iam_role" "event_enrichment_lambda_role" {
resource "aws_iam_role" "event_enrichment_lambda" {
name = "${var.environment}-event-enrichment-lambda-role"
assume_role_policy = data.aws_iam_policy_document.lambda_assume_role.json
managed_policy_arns = [
Expand All @@ -13,7 +13,7 @@ resource "aws_iam_role" "event_enrichment_lambda_role" {
]
}

resource "aws_iam_role" "bulk_ods_lambda_role" {
resource "aws_iam_role" "bulk_ods_lambda" {
name = "${var.environment}-bulk-ods-lambda-role"
assume_role_policy = data.aws_iam_policy_document.lambda_assume_role.json
managed_policy_arns = [
Expand Down
43 changes: 43 additions & 0 deletions stacks/gp-registrations-mi/terraform/lambda-bulk-ods-update.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
resource "aws_lambda_function" "ods_bulk_update" {
filename = "${path.cwd}/${var.ods_bulk_update_lambda_name}"
function_name = "${var.environment}-${var.ods_bulk_update_lambda_name}"
role = aws_iam_role.bulk_ods_lambda_role.arn
handler = "ods_bulk_update.lambda_handler"
source_code_hash = filebase64sha256("${path.cwd}/${var.bulk_ods_update_lambda_zip}")
runtime = "python3.12"
timeout = 300
environment {
variables = {
TRUD_API_KEY_PARAM_NAME = data.aws_ssm_parameter.trud_api_key,
TRUD_FHIR_API_URL_PARAM_NAME = data.aws_ssm_parameter.trud_api_endpoint,
}
}
tags = merge(
local.common_tags,
{
Name = "${var.environment}-gp-mi-ods_bulk"
ApplicationRole = "AwsLambdaFunction"
}
)
}


resource "aws_cloudwatch_log_group" "bulk_ods_update_lambda" {
name = "/aws/lambda/${var.environment}-${var.ods_bulk_update_lambda_name}"
tags = merge(
local.common_tags,
{
Name = "${var.environment}-${var.ods_bulk_update_lambda_name}"
ApplicationRole = "AwsCloudwatchLogGroup"
}
)
retention_in_days = 60
}

data "aws_ssm_parameter" "trud_api_key" {
name = "TRUD_api_secret_key"
}

data "aws_ssm_parameter" "trud_api_endpoint" {
name = "TRUD_api_download_endoint"
}
2 changes: 1 addition & 1 deletion stacks/gp-registrations-mi/terraform/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.59.0"
version = ">= 5.0"
}
}
}
Loading

0 comments on commit 2e2a108

Please sign in to comment.