-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add iac folder * Generate terraform lock file and add batch role * Add compute resources for batch * Add dumped db * Add instructions about manual resources in README * Add terraform plan as iac test * Add alb and ecs * Add ECR parameter * Add task role arn * Add more variables, add tomcat as allowed port in alb * Change instance class from small to medium * Fix security group in ecs and make the task finally available * Remove iac test as it will fail for forks * Add variable for bucket * Add code deploy * Add some permissions for code dpeloy * Add event bridge * Add output url * Put back ALB for statistics using https
- Loading branch information
Showing
18 changed files
with
291 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.terraform/ | ||
app-spec/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
resource "aws_iam_role" "statistics_server_code_deploy_role" { | ||
name = "statistics-server-code-deploy-role-${terraform.workspace}" | ||
|
||
inline_policy { | ||
name = "statistics-inline-cd-${terraform.workspace}" | ||
policy = templatefile("${path.module}/templates/policies/code-deploy-statistics.json", { | ||
bucket_name = var.bucket_name | ||
aws_region = var.aws_region | ||
app_spec_folder = var.app_spec_folder | ||
cluster_name = aws_ecs_cluster.statistics_server_cluster.name | ||
service_name = aws_ecs_service.statistics_server_service.name | ||
}) | ||
} | ||
|
||
assume_role_policy = templatefile("${path.module}/templates/policies/assume-role-code-deploy.json", {}) | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "statistics_server_code_deploy_role" { | ||
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" | ||
role = aws_iam_role.statistics_server_code_deploy_role.name | ||
} | ||
|
||
resource "aws_codedeploy_app" "statistics_server_code_deploy_app" { | ||
name = "statistics-server-code-deploy-app-${terraform.workspace}" | ||
compute_platform = "ECS" | ||
} | ||
|
||
resource "aws_codedeploy_deployment_group" "statistics_server_code_deployment_group" { | ||
app_name = aws_codedeploy_app.statistics_server_code_deploy_app.name | ||
deployment_config_name = "CodeDeployDefault.ECSAllAtOnce" | ||
deployment_group_name = "statistics-server-code-deployment-group-${terraform.workspace}" | ||
service_role_arn = aws_iam_role.statistics_server_code_deploy_role.arn | ||
|
||
auto_rollback_configuration { | ||
enabled = true | ||
events = ["DEPLOYMENT_FAILURE"] | ||
} | ||
|
||
blue_green_deployment_config { | ||
deployment_ready_option { | ||
action_on_timeout = "CONTINUE_DEPLOYMENT" | ||
} | ||
|
||
terminate_blue_instances_on_deployment_success { | ||
action = "TERMINATE" | ||
termination_wait_time_in_minutes = 5 | ||
} | ||
} | ||
|
||
deployment_style { | ||
deployment_option = "WITH_TRAFFIC_CONTROL" | ||
deployment_type = "BLUE_GREEN" | ||
} | ||
|
||
ecs_service { | ||
cluster_name = aws_ecs_cluster.statistics_server_cluster.name | ||
service_name = aws_ecs_service.statistics_server_service.name | ||
} | ||
|
||
load_balancer_info { | ||
target_group_pair_info { | ||
prod_traffic_route { | ||
listener_arns = [aws_alb_listener.statistics_server_https_listener.arn] | ||
} | ||
|
||
target_group { | ||
name = aws_alb_target_group.statistics_server_target_group.name | ||
} | ||
|
||
target_group { | ||
name = aws_alb_target_group.statistics_server_target_group_blue_green.name | ||
} | ||
} | ||
} | ||
} | ||
|
||
resource "local_file" "statistics_app_spec" { | ||
content = <<EOF | ||
version: 0.0 | ||
Resources: | ||
- TargetService: | ||
Type: AWS::ECS::Service | ||
Properties: | ||
TaskDefinition: "${replace(aws_ecs_task_definition.statistics_server_task_definition.arn, "/:[0-9]+$/", "")}" | ||
LoadBalancerInfo: | ||
ContainerName: "${var.container_name}" | ||
ContainerPort: "${var.default_tomcat_port}" | ||
PlatformVersion: "LATEST" | ||
EOF | ||
filename = "${var.app_spec_folder}/statistics-spec-${terraform.workspace}.yaml" | ||
} | ||
|
||
resource "aws_s3_object" "api_app_spec_file" { | ||
bucket = var.bucket_name | ||
key = local_file.statistics_app_spec.filename | ||
source = local_file.statistics_app_spec.filename | ||
|
||
etag = md5(local_file.statistics_app_spec.content) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
resource "aws_cloudwatch_event_rule" "statistics_cron" { | ||
name = "statistics-cron-${terraform.workspace}" | ||
description = "Statistics cron" | ||
schedule_expression = "cron(0 5 ? * TUE,FRI *)" # Tuesday, Friday. Kind of before competitions and after results posted | ||
} | ||
|
||
resource "aws_cloudwatch_event_target" "statistics_cron" { | ||
rule = aws_cloudwatch_event_rule.statistics_cron.name | ||
target_id = "SubmitStatisticsJob" | ||
arn = aws_batch_job_queue.statistics_cron_job_queue.arn | ||
role_arn = aws_iam_role.event_bus_invoke_remote_event_bus.arn | ||
batch_target { | ||
job_definition = aws_batch_job_definition.statistics_cron_job_definition.arn | ||
job_name = "statistics-cron-${terraform.workspace}" | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "event_bus_invoke_remote_event_bus" { | ||
name = "event-bus-statistics-${terraform.workspace}" | ||
assume_role_policy = templatefile("${path.module}/templates/policies/assume-role-events.json", {}) | ||
} | ||
|
||
data "aws_iam_policy_document" "event_bus_invoke_remote_event_bus" { | ||
statement { | ||
effect = "Allow" | ||
actions = ["batch:SubmitJob"] | ||
resources = [ | ||
aws_batch_job_definition.statistics_cron_job_definition.arn, | ||
aws_batch_job_queue.statistics_cron_job_queue.arn | ||
] | ||
} | ||
} | ||
|
||
resource "aws_iam_policy" "event_bus_invoke_remote_event_bus" { | ||
name = "event-bus-invoke-statistics-${terraform.workspace}" | ||
policy = data.aws_iam_policy_document.event_bus_invoke_remote_event_bus.json | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "event_bus_invoke_remote_event_bus" { | ||
role = aws_iam_role.event_bus_invoke_remote_event_bus.name | ||
policy_arn = aws_iam_policy.event_bus_invoke_remote_event_bus.arn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "access_url" { | ||
value = aws_alb.statistics_server_load_balancer.dns_name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "codedeploy.amazonaws.com" | ||
}, | ||
"Action": "sts:AssumeRole" | ||
} | ||
] | ||
} |
Oops, something went wrong.