Skip to content

Commit

Permalink
add Hub-api into FARGATE
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed Mar 15, 2019
1 parent b3b0497 commit 653823d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 8 deletions.
13 changes: 13 additions & 0 deletions stage/services/metrics-api/input.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ data "aws_route53_zone" "production" {
name = "datacite.org"
}

data "aws_security_group" "datacite-private" {
id = "${var.security_group_id}"
}

data "aws_subnet" "datacite-private" {
id = "${var.subnet_datacite-private_id}"
}

data "aws_subnet" "datacite-alt" {
id = "${var.subnet_datacite-alt_id}"
}

data "aws_route53_zone" "internal" {
name = "datacite.org"
private_zone = true
Expand Down Expand Up @@ -38,6 +50,7 @@ data "template_file" "metrics-api_task" {
template = "${file("metrics-api.json")}"

vars {
public_key = "${var.public_key}"
jwt_public_key = "${var.jwt_public_key}"
jwt_private_key = "${var.jwt_private_key}"
memcache_servers = "${var.memcache_servers}"
Expand Down
45 changes: 39 additions & 6 deletions stage/services/metrics-api/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,36 @@ resource "aws_ecs_service" "metrics-api-stage" {
cluster = "${data.aws_ecs_cluster.stage.id}"
task_definition = "${aws_ecs_task_definition.metrics-api-stage.arn}"
desired_count = 1
iam_role = "${data.aws_iam_role.ecs_service.arn}"

ordered_placement_strategy {
type = "binpack"
field = "cpu"
}
launch_type = "FARGATE"

load_balancer {
target_group_arn = "${aws_lb_target_group.metrics-api-stage.id}"
container_name = "metrics-api-stage"
container_port = "80"
}

network_configuration {
security_groups = ["${data.aws_security_group.datacite-private.id}"]
subnets = [
"${data.aws_subnet.datacite-private.id}",
"${data.aws_subnet.datacite-alt.id}"
]
}

service_registries {
registry_arn = "${aws_service_discovery_service.metrics-api-stage.arn}"
}

depends_on = [
"data.aws_lb_listener.default",
]
}

resource "aws_lb_target_group" "metrics-api-stage" {
name = "metrics-api-stage"
port = 80
protocol = "HTTP"
target_type = "ip"
vpc_id = "${var.vpc_id}"

health_check {
Expand Down Expand Up @@ -55,6 +67,10 @@ resource "aws_lb_listener_rule" "metrics-api-stage" {
resource "aws_ecs_task_definition" "metrics-api-stage" {
family = "metrics-api-stage"
execution_role_arn = "${data.aws_iam_role.ecs_task_execution_role.arn}"
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = "512"
memory = "2048"
container_definitions = "${data.template_file.metrics-api_task.rendered}"
}

Expand All @@ -72,4 +88,21 @@ resource "aws_route53_record" "split-metrics-api-stage" {
type = "CNAME"
ttl = "${var.ttl}"
records = ["${data.aws_lb.stage.dns_name}"]
}

resource "aws_service_discovery_service" "levriero" {
name = "metrics-api.test"

health_check_custom_config {
failure_threshold = 3
}

dns_config {
namespace_id = "${var.namespace_id}"

dns_records {
ttl = 300
type = "A"
}
}
}
10 changes: 8 additions & 2 deletions stage/services/metrics-api/metrics-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"name": "metrics-api-stage",
"image": "datacite/sashimi",
"cpu": 512,
"memory": 1000,
"memory": 2048,
"essential": true,
"networkMode": "awsvpc",
"hostname": "metrics-api-stage",
"portMappings": [
{
"containerPort": 80
"containerPort": 80,
"hostPort": 80
}
],
"logConfiguration": {
Expand Down Expand Up @@ -88,6 +90,10 @@
"name" : "AWS_S3_BUCKET",
"value" : "${s3_bucket}"
},
{
"name" : "PUBLIC_KEY",
"value" : "${public_key}"
},
{
"name" : "USAGE_URL",
"value" : "${usage_url}"
Expand Down
8 changes: 8 additions & 0 deletions stage/services/metrics-api/var.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ variable "mysql_database" {
default = "metrics"
}
variable "mysql_host" {}
variable "public_key" {}
variable "datacite_usage_source_token" {}

variable "security_group_id" {}
variable "subnet_datacite-private_id" {}
variable "subnet_datacite-alt_id" {}

variable "namespace_id" {}

0 comments on commit 653823d

Please sign in to comment.