Created
August 3, 2018 16:49
-
-
Save gambtho/3f65f44ebb79e3e1a0073eb5151c070a to your computer and use it in GitHub Desktop.
ECS cluster with fargate
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
locals { | |
autoscale_resource_id = "service/${aws_ecs_cluster.cluster.name}/${aws_ecs_service.service.name}" | |
} | |
resource "aws_ecr_repository" "app_ecr" { | |
name = "${var.api_name}-${var.environment}" | |
} | |
resource "aws_ecs_cluster" "cluster" { | |
depends_on = ["aws_ecs_task_definition.taskdef"] | |
name = "${var.api_name}-${var.environment}" | |
} | |
resource "aws_ecs_task_definition" "taskdef" { | |
family = "${var.api_name}" | |
container_definitions = "${var.container_def}" | |
cpu = "${var.taskdef_cpu}" | |
memory = "${var.taskdef_memory}" | |
execution_role_arn = "${aws_iam_role.role.arn}" | |
task_role_arn = "${aws_iam_role.role.arn}" | |
requires_compatibilities = ["FARGATE"] | |
network_mode = "awsvpc" | |
} | |
resource "aws_ecs_service" "service" { | |
depends_on = ["aws_ecs_task_definition.taskdef", "aws_alb_listener.http"] | |
name = "${var.api_name}-${var.environment}" | |
cluster = "${aws_ecs_cluster.cluster.name}" | |
desired_count = "${var.initial_desired_count}" | |
deployment_maximum_percent = "200" | |
deployment_minimum_healthy_percent = "100" | |
launch_type = "FARGATE" | |
load_balancer { | |
target_group_arn = "${aws_alb_target_group.http.arn}" | |
container_name = "${var.api_name}" | |
container_port = "8081" | |
} | |
network_configuration { | |
subnets = ["${var.private_subnets}"] | |
security_groups = ["${var.security_groups}"] | |
assign_public_ip = true | |
} | |
task_definition = "${aws_ecs_task_definition.taskdef.family}:${max("${aws_ecs_task_definition.taskdef.revision}", "${data.aws_ecs_task_definition.taskdef.revision}")}" | |
} | |
data "aws_ecs_task_definition" "taskdef" { | |
depends_on = ["aws_ecs_task_definition.taskdef"] | |
task_definition = "${aws_ecs_task_definition.taskdef.family}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment