This repository has been archived by the owner on Dec 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from givanovexpe/feature/apiary-replication_enh…
…ancements Feature/apiary replication enhancements
- Loading branch information
Showing
18 changed files
with
532 additions
and
231 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 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,169 @@ | ||
/** | ||
* Copyright (C) 2019 Expedia, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
*/ | ||
|
||
data "template_file" "ecs_widgets" { | ||
template = <<EOF | ||
{ | ||
"type":"metric", | ||
"width":12, | ||
"height":6, | ||
"properties":{ | ||
"metrics":[ | ||
[ "AWS/ECS", "CPUUtilization", "ServiceName", "${local.instance_alias}-service", "ClusterName", "${local.instance_alias}" ] | ||
], | ||
"period":300, | ||
"stat":"Average", | ||
"region":"${var.aws_region}", | ||
"title":"Shunting Yard ECS CPU Utilization" | ||
} | ||
}, | ||
{ | ||
"type":"metric", | ||
"width":12, | ||
"height":6, | ||
"properties":{ | ||
"metrics":[ | ||
[ "AWS/ECS", "MemoryUtilization", "ServiceName", "${local.instance_alias}-service", "ClusterName", "${local.instance_alias}" ] | ||
], | ||
"period":300, | ||
"stat":"Average", | ||
"region":"${var.aws_region}", | ||
"title":"Shunting Yard ECS Memory Utilization" | ||
} | ||
}, | ||
EOF | ||
} | ||
|
||
data "template_file" "sqs_widgets" { | ||
template = <<EOF | ||
{ | ||
"type":"metric", | ||
"width":12, | ||
"height":6, | ||
"properties":{ | ||
"metrics": [ | ||
[ "AWS/SQS", "NumberOfMessagesSent", "QueueName", "${local.instance_alias}-sqs-queue" ], | ||
[ "AWS/SQS", "NumberOfMessagesReceived", "QueueName", "${local.instance_alias}-sqs-queue" ] | ||
], | ||
"period":300, | ||
"stat":"Average", | ||
"region": "${var.aws_region}", | ||
"title": "Shunting Yard SQS Sent & Received Messages" | ||
} | ||
}, | ||
{ | ||
"type":"metric", | ||
"width":12, | ||
"height":6, | ||
"properties":{ | ||
"metrics": [ | ||
[ "AWS/SQS", "ApproximateNumberOfMessagesVisible", "QueueName", "${local.instance_alias}-sqs-queue" ], | ||
[ "AWS/SQS", "ApproximateNumberOfMessagesDelayed", "QueueName", "${local.instance_alias}-sqs-queue" ], | ||
[ "AWS/SQS", "ApproximateNumberOfMessagesNotVisible", "QueueName", "${local.instance_alias}-sqs-queue" ] | ||
], | ||
"period":300, | ||
"stat":"Average", | ||
"region": "${var.aws_region}", | ||
"title": "Shunting Yard SQS Queue Size Metrics" | ||
} | ||
}, | ||
{ | ||
"type":"metric", | ||
"width":12, | ||
"height":6, | ||
"properties":{ | ||
"metrics": [ | ||
[ "AWS/SQS", "NumberOfMessagesDeleted", "QueueName", "${local.instance_alias}-sqs-queue" ] | ||
], | ||
"period":300, | ||
"stat":"Average", | ||
"region": "${var.aws_region}", | ||
"title": "Shunting Yard SQS Deleted Messages" | ||
} | ||
}, | ||
{ | ||
"type":"metric", | ||
"width":12, | ||
"height":6, | ||
"properties":{ | ||
"metrics": [ | ||
[ "AWS/SQS", "ApproximateAgeOfOldestMessage", "QueueName", "${local.instance_alias}-sqs-queue" ] | ||
], | ||
"period":300, | ||
"stat":"Average", | ||
"view": "singleValue", | ||
"region": "${var.aws_region}", | ||
"title": "Shunting Yard SQS Age of Oldest Message (s)" | ||
} | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_cloudwatch_dashboard" "shuntingyard" { | ||
dashboard_name = "${local.instance_alias}-${var.aws_region}" | ||
|
||
dashboard_body = <<EOF | ||
{ | ||
"widgets": [ | ||
${join("", data.template_file.ecs_widgets.*.rendered)} | ||
${join("", data.template_file.sqs_widgets.*.rendered)} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
locals { | ||
alerts = [ | ||
{ | ||
alarm_name = "${local.instance_alias}-cpu" | ||
namespace = "AWS/ECS" | ||
metric_name = "CPUUtilization" | ||
threshold = "90" | ||
}, | ||
{ | ||
alarm_name = "${local.instance_alias}-memory" | ||
namespace = "AWS/ECS" | ||
metric_name = "MemoryUtilization" | ||
threshold = "80" | ||
}, | ||
{ | ||
alarm_name = "${local.instance_alias}-stale-messages" | ||
namespace = "AWS/SQS" | ||
metric_name = "ApproximateAgeOfOldestMessage" | ||
threshold = "${var.shuntingyard_sqs_queue_stale_messages_timeout}" | ||
}, | ||
] | ||
|
||
dimensions = [ | ||
{ | ||
ClusterName = "${local.instance_alias}" | ||
ServiceName = "${local.instance_alias}-service" | ||
}, | ||
{ | ||
ClusterName = "${local.instance_alias}" | ||
ServiceName = "${local.instance_alias}-service" | ||
}, | ||
{ | ||
QueueName = "${local.instance_alias}-sqs-queue" | ||
}, | ||
] | ||
} | ||
|
||
resource "aws_cloudwatch_metric_alarm" "shuntingyard_alert" { | ||
count = "${length(local.alerts)}" | ||
alarm_name = "${lookup(local.alerts[count.index], "alarm_name")}" | ||
comparison_operator = "${lookup(local.alerts[count.index], "comparison_operator", "GreaterThanOrEqualToThreshold")}" | ||
metric_name = "${lookup(local.alerts[count.index], "metric_name")}" | ||
namespace = "${lookup(local.alerts[count.index], "namespace")}" | ||
period = "${lookup(local.alerts[count.index], "period", "120")}" | ||
evaluation_periods = "${lookup(local.alerts[count.index], "evaluation_periods", "2")}" | ||
statistic = "Average" | ||
threshold = "${lookup(local.alerts[count.index], "threshold")}" | ||
|
||
insufficient_data_actions = [] | ||
dimensions = "${local.dimensions[count.index]}" | ||
alarm_actions = ["${aws_sns_topic.shuntingyard_ops_sns.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,40 @@ | ||
/** | ||
* Copyright (C) 2019 Expedia, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
*/ | ||
|
||
resource "aws_ecs_cluster" "shuntingyard" { | ||
name = "${local.instance_alias}" | ||
tags = "${var.shuntingyard_tags}" | ||
} | ||
|
||
resource "aws_cloudwatch_log_group" "shuntingyard_ecs" { | ||
name = "${local.instance_alias}" | ||
tags = "${var.shuntingyard_tags}" | ||
} | ||
|
||
resource "aws_ecs_task_definition" "shuntingyard" { | ||
family = "${local.instance_alias}" | ||
task_role_arn = "${aws_iam_role.shuntingyard_task.arn}" | ||
execution_role_arn = "${aws_iam_role.shuntingyard_task_exec.arn}" | ||
network_mode = "awsvpc" | ||
memory = "${var.memory}" | ||
cpu = "${var.cpu}" | ||
requires_compatibilities = ["EC2", "FARGATE"] | ||
container_definitions = "${data.template_file.shuntingyard.rendered}" | ||
tags = "${var.shuntingyard_tags}" | ||
} | ||
|
||
resource "aws_ecs_service" "shuntingyard_service" { | ||
name = "${local.instance_alias}-service" | ||
launch_type = "FARGATE" | ||
cluster = "${aws_ecs_cluster.shuntingyard.id}" | ||
task_definition = "${aws_ecs_task_definition.shuntingyard.arn}" | ||
desired_count = "1" | ||
|
||
network_configuration { | ||
security_groups = ["${aws_security_group.shuntingyard_sg.id}"] | ||
subnets = ["${var.subnets}"] | ||
} | ||
} |
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,39 @@ | ||
/** | ||
* Copyright (C) 2019 Expedia, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
*/ | ||
|
||
resource "aws_iam_role_policy" "s3_for_shuntingyard" { | ||
name = "s3" | ||
role = "${aws_iam_role.shuntingyard_task.id}" | ||
|
||
policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"s3:DeleteObject", | ||
"s3:DeleteObjectVersion", | ||
"s3:Get*", | ||
"s3:List*", | ||
"s3:PutBucketLogging", | ||
"s3:PutBucketNotification", | ||
"s3:PutBucketVersioning", | ||
"s3:PutObject", | ||
"s3:PutObjectAcl", | ||
"s3:PutObjectTagging", | ||
"s3:PutObjectVersionAcl", | ||
"s3:PutObjectVersionTagging" | ||
], | ||
"Resource": [ | ||
"${join("\",\"", formatlist("arn:aws:s3:::%s",var.allowed_s3_buckets))}", | ||
"${join("\",\"", formatlist("arn:aws:s3:::%s/*",var.allowed_s3_buckets))}" | ||
] | ||
} | ||
] | ||
} | ||
EOF | ||
} |
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,22 @@ | ||
/** | ||
* Copyright (C) 2019 Expedia, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
*/ | ||
|
||
resource "aws_iam_role_policy" "secretsmanager_for_ecs_task_exec" { | ||
count = "${var.docker_registry_auth_secret_name != "" ? 1 : 0}" | ||
name = "secretsmanager-exec" | ||
role = "${aws_iam_role.shuntingyard_task_exec.id}" | ||
|
||
policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": { | ||
"Effect": "Allow", | ||
"Action": "secretsmanager:GetSecretValue", | ||
"Resource": [ "${join("\",\"", concat(data.aws_secretsmanager_secret.docker_registry.*.arn))}" ] | ||
} | ||
} | ||
EOF | ||
} |
Oops, something went wrong.