Skip to content

Commit

Permalink
Working Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisthetechie committed Jun 21, 2024
1 parent a2d442b commit a073e8d
Show file tree
Hide file tree
Showing 33 changed files with 480 additions and 377 deletions.
65 changes: 0 additions & 65 deletions infrastructure/api_deployment.tf

This file was deleted.

57 changes: 0 additions & 57 deletions infrastructure/api_enquiry.tf

This file was deleted.

43 changes: 0 additions & 43 deletions infrastructure/api_gateway.tf

This file was deleted.

18 changes: 9 additions & 9 deletions infrastructure/cw_alarm.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
locals {
service_name = "${local.csi}-enquiry-evl-push-lambda"
service_name = "${local.csi}-${var.api_service_name}-evl-push-lambda"
}

resource "aws_sqs_queue" "enquiry_evl_push_lambda" {
resource "aws_sqs_queue" "evl_push_lambda" {
name = "${local.service_name}-dlq"
message_retention_seconds = 1209600
tags = local.default_tags
sqs_managed_sse_enabled = true
}

resource "aws_cloudwatch_metric_alarm" "deadletter_alarm_enquiry_evl_push_lambda" {
resource "aws_cloudwatch_metric_alarm" "deadletter_alarm_evl_push_lambda" {
alarm_name = "${local.service_name}-dlq-not-empty-alarm"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
Expand All @@ -18,15 +18,15 @@ resource "aws_cloudwatch_metric_alarm" "deadletter_alarm_enquiry_evl_push_lambda
period = "120"
statistic = "Sum"
threshold = "1"
alarm_description = "Items are on the ${aws_sqs_queue.enquiry_evl_push_lambda.name} queue"
alarm_description = "Items are on the ${aws_sqs_queue.evl_push_lambda.name} queue"
treat_missing_data = "notBreaching"
tags = local.default_tags
dimensions = {
"QueueName" = aws_sqs_queue.enquiry_evl_push_lambda.name
"QueueName" = aws_sqs_queue.evl_push_lambda.name
}
}

resource "aws_cloudwatch_metric_alarm" "enquiry_evl_push_lambda_errors" {
resource "aws_cloudwatch_metric_alarm" "evl_push_lambda_errors" {
alarm_name = "${local.service_name}-errors-alarm"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 2
Expand All @@ -38,11 +38,11 @@ resource "aws_cloudwatch_metric_alarm" "enquiry_evl_push_lambda_errors" {
metric_name = "Errors"
statistic = "Maximum"
dimensions = {
FunctionName = module.enquiry_sftp_file_push.function_name
FunctionName = module.sftp_file_push.function_name
}
}

resource "aws_cloudwatch_metric_alarm" "enquiry_evl_push_lambda_timeouts" {
resource "aws_cloudwatch_metric_alarm" "evl_push_lambda_timeouts" {
alarm_name = "${local.service_name}-timeouts-alarm"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 2
Expand All @@ -55,6 +55,6 @@ resource "aws_cloudwatch_metric_alarm" "enquiry_evl_push_lambda_timeouts" {
statistic = "Maximum"
dimensions = {
Environment = terraform.workspace
Service = "/aws/lambda/${module.enquiry_sftp_file_push.function_name}"
Service = "/aws/lambda/${module.sftp_file_push.function_name}"
}
}
32 changes: 22 additions & 10 deletions infrastructure/data.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
data "aws_api_gateway_rest_api" "remote_gateway" {
name = "cb2-11925"
name = terraform.workspace
}

output "gateway" {
value = data.aws_api_gateway_rest_api.remote_gateway
}

data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
Expand Down Expand Up @@ -36,7 +33,7 @@ data "aws_iam_policy_document" "fh_cw_assume" {

data "terraform_remote_state" "current_or_dev" {
backend = "s3"
workspace = var.remote_state
workspace = terraform.workspace
config = {
bucket = "cvs-tf-environment"
key = "tf_state"
Expand All @@ -58,19 +55,34 @@ data "aws_iam_role" "firehose_metrics" {
}

## Secrets Data
data "aws_secretsmanager_secret" "enquiry-api-key" {
name = "${var.GITHUB_ENVIRONMENT}/enquiry/api-key"
data "aws_secretsmanager_secret" "api-key" {
name = "${var.GITHUB_ENVIRONMENT}/${var.api_service_name}/api-key"
}

data "aws_secretsmanager_secret_version" "enquiry-api-key" {
secret_id = data.aws_secretsmanager_secret.enquiry-api-key.id
data "aws_secretsmanager_secret_version" "api-key" {
secret_id = data.aws_secretsmanager_secret.api-key.id
}


data "aws_appconfig_environments" "app_config_environments" {
application_id = var.app_config_ids["app_config_id"]
}


data "aws_api_gateway_authorizer" "lambda_auth" {
rest_api_id = data.aws_api_gateway_rest_api.remote_gateway.id
authorizer_id = data.terraform_remote_state.current_or_dev.outputs.lambda_authorizer_id
}
# output "app_env" {
# value = data.aws_appconfig_environments.app_config_environments
# }
# }

## S3 Access Logging
data "aws_kms_key" "access_logging_s3" {
key_id = "alias/s3-access-logging-${terraform.workspace}"
}

data "aws_s3_bucket" "access_logging" {
#checkov:skip=CKV_AWS_144:This bucket does not require cross region replication.
bucket = "cvs-s3-access-logs-${terraform.workspace}"
}
2 changes: 1 addition & 1 deletion infrastructure/data/iam_s3.json.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CVSS3Bucket${ title(action)}",
"Sid": "CVSS3Bucket${title(action)}",
"Effect": "Allow",

"Action": [
Expand Down
6 changes: 3 additions & 3 deletions infrastructure/data/iam_secrets_manager.json.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"Effect": "Allow",

"Action": [
"secretsmanager:ListSecrets",
"secretsmanager:DescribeSecret",
"secretsmanager:GetSecretValue"
"SecretsManager:ListSecrets",
"SecretsManager:DescribeSecret",
"SecretsManager:GetSecretValue"
],

"Resource": ${ jsonencode(resource) }
Expand Down
12 changes: 11 additions & 1 deletion infrastructure/environments/develop.tfvars
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
aws_account = "006106226016"
aws_environment = "nonprod"
sub_domain = "develop"
app_config_ids = {
app_config_id = "j7jocye",
vtx_profile_id = "t5s9wuc",
vtm_profile_id = "4j8oc9c",
vta_profile_id = "mlkqqmj",
}
app_config_environment_id = "42yaqu1"
api_version = "v1"
api_service_name = "enquiry"
13 changes: 8 additions & 5 deletions infrastructure/environments/feature.tfvars
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
aws_environment = "nonprod"
sub_domain = "develop"
app_config = {
app_config_id = "j7jocye",
vtx_profile_id = "t5s9wuc",
vtm_profile_id = "4j8oc9c",
vta_profile_id = "mlkqqmj",
app_config_ids = {
app_config_id = "j7jocye",
vtx_profile_id = "t5s9wuc",
vtm_profile_id = "4j8oc9c",
vta_profile_id = "mlkqqmj",
}
app_config_environment_id = "42yaqu1"
api_version = "v1"
api_service_name = "enquiry"
10 changes: 5 additions & 5 deletions infrastructure/eventbridge_schedule.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
resource "aws_cloudwatch_event_rule" "enquiry_lambda_trigger" {
for_each = toset(["evl", "tfl"])
resource "aws_cloudwatch_event_rule" "lambda_trigger" {
for_each = local.scheduled_tasks
name = "${terraform.workspace}-trigger-${each.value}-feed-every-day"
description = "${var.schedule_day[each.value]} at ${var.schedule_hour[var.aws_environment]}00hrs"
schedule_expression = "cron(0 ${var.schedule_hour[var.aws_environment]} ? * ${var.schedule_day[each.value]} *)"
}

resource "aws_cloudwatch_event_target" "enquiry_lambda_trigger" {
for_each = toset(["evl", "tfl"])
rule = aws_cloudwatch_event_rule.enquiry_lambda_trigger[each.value].name
resource "aws_cloudwatch_event_target" "lambda_trigger" {
for_each = local.scheduled_tasks
rule = aws_cloudwatch_event_rule.lambda_trigger[each.value].name
arn = module.enquiry_lambda.arn
input = templatefile("./data/enquiry_lambda_trigger.json.tftpl", { client = each.value })
}
Expand Down
Loading

0 comments on commit a073e8d

Please sign in to comment.