Skip to content

Commit

Permalink
Merge pull request #3969 from ministryofjustice/date_2023_11_13
Browse files Browse the repository at this point in the history
GitHub Actions Code Formatter workflow
  • Loading branch information
ASTRobinson authored Nov 14, 2023
2 parents f819101 + 80eecd4 commit ca441ad
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 154 deletions.
4 changes: 2 additions & 2 deletions terraform/environments/apex/application_variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"ecs_scaling_mem_threshold": 80,
"region": "eu-west-2",
"docker_image_tag": "development",
"app_db_url":"db.apex.aws.dev.legalservices.gov.uk:1521:APEX",
"app_debug_enabled":"false"
"app_db_url": "db.apex.aws.dev.legalservices.gov.uk:1521:APEX",
"app_debug_enabled": "false"
},
"test": {
"example_var": "test-data"
Expand Down
52 changes: 26 additions & 26 deletions terraform/environments/apex/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ module "apex-ecs" {

source = "./modules/ecs"

subnet_set_name = local.subnet_set_name
vpc_all = local.vpc_all
app_name = local.application_name
container_instance_type = local.application_data.accounts[local.environment].container_instance_type
ami_image_id = local.application_data.accounts[local.environment].ami_image_id
instance_type = local.application_data.accounts[local.environment].instance_type
user_data = local.user_data
key_name = local.application_data.accounts[local.environment].key_name
task_definition = local.task_definition
ec2_desired_capacity = local.application_data.accounts[local.environment].ec2_desired_capacity
ec2_max_size = local.application_data.accounts[local.environment].ec2_max_size
ec2_min_size = local.application_data.accounts[local.environment].ec2_min_size
task_definition_volume = local.application_data.accounts[local.environment].task_definition_volume
network_mode = local.application_data.accounts[local.environment].network_mode
# server_port = local.application_data.accounts[local.environment].server_port
app_count = local.application_data.accounts[local.environment].app_count
ec2_ingress_rules = local.ec2_ingress_rules
ec2_egress_rules = local.ec2_egress_rules
# lb_tg_arn = module.alb.target_group_arn
tags_common = local.tags
appscaling_min_capacity = local.application_data.accounts[local.environment].appscaling_min_capacity
appscaling_max_capacity = local.application_data.accounts[local.environment].appscaling_max_capacity
ecs_scaling_cpu_threshold = local.application_data.accounts[local.environment].ecs_scaling_cpu_threshold
ecs_scaling_mem_threshold = local.application_data.accounts[local.environment].ecs_scaling_mem_threshold
ecs_target_capacity = local.ecs_target_capacity
environment = local.environment
subnet_set_name = local.subnet_set_name
vpc_all = local.vpc_all
app_name = local.application_name
container_instance_type = local.application_data.accounts[local.environment].container_instance_type
ami_image_id = local.application_data.accounts[local.environment].ami_image_id
instance_type = local.application_data.accounts[local.environment].instance_type
user_data = local.user_data
key_name = local.application_data.accounts[local.environment].key_name
task_definition = local.task_definition
ec2_desired_capacity = local.application_data.accounts[local.environment].ec2_desired_capacity
ec2_max_size = local.application_data.accounts[local.environment].ec2_max_size
ec2_min_size = local.application_data.accounts[local.environment].ec2_min_size
task_definition_volume = local.application_data.accounts[local.environment].task_definition_volume
network_mode = local.application_data.accounts[local.environment].network_mode
# server_port = local.application_data.accounts[local.environment].server_port
app_count = local.application_data.accounts[local.environment].app_count
ec2_ingress_rules = local.ec2_ingress_rules
ec2_egress_rules = local.ec2_egress_rules
# lb_tg_arn = module.alb.target_group_arn
tags_common = local.tags
appscaling_min_capacity = local.application_data.accounts[local.environment].appscaling_min_capacity
appscaling_max_capacity = local.application_data.accounts[local.environment].appscaling_max_capacity
ecs_scaling_cpu_threshold = local.application_data.accounts[local.environment].ecs_scaling_cpu_threshold
ecs_scaling_mem_threshold = local.application_data.accounts[local.environment].ecs_scaling_mem_threshold
ecs_target_capacity = local.ecs_target_capacity
environment = local.environment

}
2 changes: 1 addition & 1 deletion terraform/environments/apex/efs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ resource "aws_efs_file_system" "efs" {
local.environment != "production" ? { "snapshot-with-daily-35-day-retention" = "yes" } : { "snapshot-with-hourly-35-day-retention" = "yes" }
)

lifecycle_policy {
lifecycle_policy {
transition_to_ia = "AFTER_90_DAYS"
}
}
Expand Down
6 changes: 3 additions & 3 deletions terraform/environments/apex/event_triggers.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
resource "aws_cloudwatch_event_rule" "snapshotDBFunctionmon_sun" {

name = "laa-createSnapshotRule-${local.application_name}-${local.environment}-mp"
description = "Daily snapshots of Oracle volumes"
schedule_expression = "cron(00 04 ? * MON-SUN *)"
name = "laa-createSnapshotRule-${local.application_name}-${local.environment}-mp"
description = "Daily snapshots of Oracle volumes"
schedule_expression = "cron(00 04 ? * MON-SUN *)"


}
Expand Down
81 changes: 39 additions & 42 deletions terraform/environments/apex/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ module "s3_bucket_lambda" {
}

resource "aws_s3_object" "provision_files" {
bucket = "laa-${local.application_name}-${local.environment}-mp"
for_each = fileset("./zipfiles/", "**")
key = each.value
source = "./zipfiles/${each.value}"
bucket = "laa-${local.application_name}-${local.environment}-mp"
for_each = fileset("./zipfiles/", "**")
key = each.value
source = "./zipfiles/${each.value}"
content_type = each.value
}

Expand Down Expand Up @@ -56,7 +56,7 @@ data "archive_file" "deletesnapshot_file" {
type = "zip"
source_file = local.deletesnapshot_source_file
output_path = local.deletesnapshot_output_path

}

data "archive_file" "dbconnect_file" {
Expand All @@ -80,22 +80,22 @@ resource "aws_lambda_layer_version" "lambda_layer" {

resource "aws_lambda_function" "snapshotDBFunction" {

description = "Snapshot volumes for Oracle EC2"
function_name = local.snapshotDBFunctionname
role = module.iambackup.backuprole
handler = local.snapshotDBFunctionhandler
description = "Snapshot volumes for Oracle EC2"
function_name = local.snapshotDBFunctionname
role = module.iambackup.backuprole
handler = local.snapshotDBFunctionhandler
source_code_hash = data.archive_file.dbsnapshot_file.output_base64sha256
runtime = local.snapshotDBFunctionruntime
layers = [aws_lambda_layer_version.lambda_layer.arn]
s3_bucket = module.s3_bucket_lambda.lambdabucketname
s3_key = local.snapshotDBFunctionfilename
memory_size = 128
timeout = 900
depends_on = [ time_sleep.wait_for_provision_files ] #This resource will create (at least) 300 seconds after aws_s3_object.provision_files

runtime = local.snapshotDBFunctionruntime
layers = [aws_lambda_layer_version.lambda_layer.arn]
s3_bucket = module.s3_bucket_lambda.lambdabucketname
s3_key = local.snapshotDBFunctionfilename
memory_size = 128
timeout = 900
depends_on = [ time_sleep.wait_for_provision_files ] #This resource will create (at least) 300 seconds after aws_s3_object.provision_files





environment {
variables = {
LD_LIBRARY_PATH = "/opt/nodejs/node_modules/lib"
Expand All @@ -114,17 +114,17 @@ resource "aws_lambda_function" "snapshotDBFunction" {

resource "aws_lambda_function" "deletesnapshotFunction" {

description = "Clean up script to delete old unused snapshots"
function_name = local.deletesnapshotFunctionname
role = module.iambackup.backuprole
handler = local.deletesnapshotFunctionhandler
description = "Clean up script to delete old unused snapshots"
function_name = local.deletesnapshotFunctionname
role = module.iambackup.backuprole
handler = local.deletesnapshotFunctionhandler
source_code_hash = data.archive_file.deletesnapshot_file.output_base64sha256
runtime = local.deletesnapshotFunctionruntime
s3_bucket = module.s3_bucket_lambda.lambdabucketname
s3_key = local.deletesnapshotFunctionfilename
memory_size = 1024
timeout = 900
depends_on = [ time_sleep.wait_for_provision_files ] #This resource will create (at least) 300 seconds after aws_s3_object.provision_files
runtime = local.deletesnapshotFunctionruntime
s3_bucket = module.s3_bucket_lambda.lambdabucketname
s3_key = local.deletesnapshotFunctionfilename
memory_size = 1024
timeout = 900
depends_on = [ time_sleep.wait_for_provision_files ] #This resource will create (at least) 300 seconds after aws_s3_object.provision_files


environment {
Expand All @@ -146,18 +146,18 @@ resource "aws_lambda_function" "deletesnapshotFunction" {

resource "aws_lambda_function" "connectDBFunction" {

description = "SSH to the DB EC2"
function_name = local.connectDBFunctionname
role = module.iambackup.backuprole
handler = local.connectDBFunctionhandler
description = "SSH to the DB EC2"
function_name = local.connectDBFunctionname
role = module.iambackup.backuprole
handler = local.connectDBFunctionhandler
source_code_hash = data.archive_file.dbconnect_file.output_base64sha256
runtime = local.connectDBFunctionruntime
layers = [aws_lambda_layer_version.lambda_layer.arn]
s3_bucket = module.s3_bucket_lambda.lambdabucketname
s3_key = local.connectDBFunctionfilename
memory_size = 128
timeout = 900
depends_on = [ time_sleep.wait_for_provision_files ] #This resource will create (at least) 300 seconds after aws_s3_object.provision_files
runtime = local.connectDBFunctionruntime
layers = [aws_lambda_layer_version.lambda_layer.arn]
s3_bucket = module.s3_bucket_lambda.lambdabucketname
s3_key = local.connectDBFunctionfilename
memory_size = 128
timeout = 900
depends_on = [ time_sleep.wait_for_provision_files ] #This resource will create (at least) 300 seconds after aws_s3_object.provision_files



Expand All @@ -176,6 +176,3 @@ resource "aws_lambda_function" "connectDBFunction" {
{ Name = "laa-${local.application_name}-${local.environment}-lambda-connect-mp" }
)
}



26 changes: 13 additions & 13 deletions terraform/environments/apex/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ locals {
dbsnapshot_source_file = "dbsnapshot.js"
deletesnapshot_source_file = "deletesnapshots.py"
dbconnect_source_file = "dbconnect.js"

dbsnapshot_output_path = "dbsnapshot.zip"
deletesnapshot_output_path = "deletesnapshots.zip"
dbconnect_output_path = "dbconnect.zip"
Expand Down Expand Up @@ -37,11 +37,11 @@ locals {
# ECS local variables for ecs.tf
ec2_ingress_rules = {
"cluster_ec2_lb_ingress_3" = {
description = "Cluster EC2 ingress rule 3"
from_port = 32768
to_port = 61000
protocol = "tcp"
cidr_blocks = []
description = "Cluster EC2 ingress rule 3"
from_port = 32768
to_port = 61000
protocol = "tcp"
cidr_blocks = []
# Update the below SG to mention ALB SG
security_groups = []
}
Expand All @@ -62,13 +62,13 @@ locals {
}))

task_definition = templatefile("task_definition.json", {
app_name = local.application_name
ecr_url = "${local.environment_management.account_ids["core-shared-services-production"]}.dkr.ecr.eu-west-2.amazonaws.com/apex-ecr-repo"
docker_image_tag = local.application_data.accounts[local.environment].docker_image_tag
region = local.application_data.accounts[local.environment].region
app_db_url = local.application_data.accounts[local.environment].app_db_url
app_debug_enabled = local.application_data.accounts[local.environment].app_debug_enabled
db_secret_arn = "arn:aws:ssm:${local.application_data.accounts[local.environment].region}:${local.env_account_id}:parameter/${local.app_db_password_name}"
app_name = local.application_name
ecr_url = "${local.environment_management.account_ids["core-shared-services-production"]}.dkr.ecr.eu-west-2.amazonaws.com/apex-ecr-repo"
docker_image_tag = local.application_data.accounts[local.environment].docker_image_tag
region = local.application_data.accounts[local.environment].region
app_db_url = local.application_data.accounts[local.environment].app_db_url
app_debug_enabled = local.application_data.accounts[local.environment].app_debug_enabled
db_secret_arn = "arn:aws:ssm:${local.application_data.accounts[local.environment].region}:${local.env_account_id}:parameter/${local.app_db_password_name}"
})

env_account_id = local.environment_management.account_ids[terraform.workspace]
Expand Down
14 changes: 7 additions & 7 deletions terraform/environments/apex/modules/ecs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,13 @@ resource "aws_ecs_service" "ecs_service" {
type = "spread"
}

# Uncomment this section when the ALB for Apex is built
#
# load_balancer {
# target_group_arn = var.lb_tg_arn
# container_name = var.app_name
# container_port = var.server_port
# }
# Uncomment this section when the ALB for Apex is built
#
# load_balancer {
# target_group_arn = var.lb_tg_arn
# container_name = var.app_name
# container_port = var.server_port
# }

depends_on = [
aws_iam_role_policy_attachment.ecs_task_execution_role, aws_ecs_task_definition.windows_ecs_task_definition, aws_ecs_task_definition.linux_ecs_task_definition, aws_cloudwatch_log_group.cloudwatch_group
Expand Down
8 changes: 4 additions & 4 deletions terraform/environments/apex/modules/s3/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ resource "aws_s3_bucket" "laa-lambda-backup" {


resource "aws_s3_object" "provision_files" {
bucket = aws_s3_bucket.laa-lambda-backup.id
for_each = fileset("./zipfiles/", "**")
key = each.value
source = "./zipfiles/${each.value}"
bucket = aws_s3_bucket.laa-lambda-backup.id
for_each = fileset("./zipfiles/", "**")
key = each.value
source = "./zipfiles/${each.value}"
content_type = each.value
}

Expand Down
72 changes: 36 additions & 36 deletions terraform/environments/apex/task_definition.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
[
{
"name": "${app_name}",
"image": "${ecr_url}:${docker_image_tag}",
"essential": true,
"cpu": 1024,
"portMappings": [
{
"containerPort": 8080
}
],
"memory": 2000,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-region": "${region}",
"awslogs-stream-prefix": "${app_name}-app",
"awslogs-group": "${app_name}-ecs-log-group"
}
{
"name": "${app_name}",
"image": "${ecr_url}:${docker_image_tag}",
"essential": true,
"cpu": 1024,
"portMappings": [
{
"containerPort": 8080
}
],
"memory": 2000,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-region": "${region}",
"awslogs-stream-prefix": "${app_name}-app",
"awslogs-group": "${app_name}-ecs-log-group"
}
},
"environment": [
{
"name": "APP_DB_URL",
"value": "${app_db_url}"
},
"environment": [
{
"name": "APP_DB_URL",
"value": "${app_db_url}"
},
{
"name": "APP_DEBUG_ENABLED",
"value": "${app_debug_enabled}"
}
],
"secrets": [
{
"name": "APP_DB_PASSWORD",
"valueFrom": "${db_secret_arn}"
}
]
}
]
{
"name": "APP_DEBUG_ENABLED",
"value": "${app_debug_enabled}"
}
],
"secrets": [
{
"name": "APP_DB_PASSWORD",
"valueFrom": "${db_secret_arn}"
}
]
}
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_instance" "ec2_oracle_conc" {
instance_type = local.application_data.accounts[local.environment].ec2_oracle_instance_type_ebsconc
instance_type = local.application_data.accounts[local.environment].ec2_oracle_instance_type_ebsconc
ami = local.application_data.accounts[local.environment].ebsconc_ami_id
key_name = local.application_data.accounts[local.environment].key_name
vpc_security_group_ids = [aws_security_group.ec2_sg_ebsconc.id]
Expand Down
Loading

0 comments on commit ca441ad

Please sign in to comment.