Last active
February 28, 2020 16:29
-
-
Save ezaurum/c070bbed8421f7c1550d76c614d75c77 to your computer and use it in GitHub Desktop.
api.tf
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
resource "aws_ecs_cluster" "api" { | |
name = "${var.organization}-api-${var.stage}" | |
tags = { | |
Name: "${var.organization} API cluster ${var.stage}" | |
Organization:var.organization | |
Stage : var.stage | |
} | |
} | |
resource "aws_ecs_task_definition" "api" { | |
network_mode = "awsvpc" | |
requires_compatibilities = [ | |
"EC2", | |
"FARGATE"] | |
cpu = 256 | |
memory = 512 | |
container_definitions = <<EOF | |
[ | |
{ | |
"logConfiguration": { | |
"logDriver": "awslogs", | |
"options": { | |
"awslogs-group": "/ecs/${var.organization}-api-${var.stage}", | |
"awslogs-region": "ap-northeast-2", | |
"awslogs-stream-prefix": "ecs" | |
} | |
}, | |
"portMappings": [ | |
{ | |
"hostPort": 80, | |
"protocol": "tcp", | |
"containerPort": 80 | |
} | |
], | |
"environment": [ ], | |
"image": "${aws_ecr_repository.api.repository_url}:latest", | |
"name": "${var.organization}-api-${var.stage}" | |
} | |
] | |
EOF | |
family = "${var.organization}-api-${var.stage}" | |
tags = { | |
Name: "${var.organization} API task ${var.stage}" | |
Organization:var.organization | |
Stage : var.stage | |
} | |
execution_role_arn = "arn:aws:iam::222222:role/ecsTaskExecutionRole" | |
task_role_arn = "arn:aws:iam::22222:role/ecsTaskExecutionRole" | |
} | |
resource "aws_ecs_service" "api" { | |
name = "api" | |
cluster = aws_ecs_cluster.api.id | |
task_definition = aws_ecs_task_definition.api.arn | |
desired_count = 1 | |
network_configuration { | |
subnets = [ | |
aws_subnet.lb0.id, | |
aws_subnet.lb1.id, | |
aws_subnet.lb2.id, | |
] | |
security_groups = [ | |
aws_security_group.internal.id] | |
} | |
load_balancer { | |
target_group_arn = aws_lb_target_group.api.arn | |
# https://github.com/aws/amazon-ecs-agent/issues/1276 | |
container_name = "${var.organization}-api-${var.stage}" | |
container_port = 80 | |
} | |
launch_type = "FARGATE" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment