Skip to content

Instantly share code, notes, and snippets.

@vthub
Created January 4, 2020 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vthub/6eadac0b0ea3d837b4b22f73748df067 to your computer and use it in GitHub Desktop.
Save vthub/6eadac0b0ea3d837b4b22f73748df067 to your computer and use it in GitHub Desktop.
resource "aws_ecs_cluster" "cluster" {
name = "${local.service_name}-cluster"
}
data "template_file" "definition" {
template = file("${path.module}/task-def/def.json")
vars = {
region = var.region
log_group = aws_cloudwatch_log_group.task_log_group.name
image_tag = data.aws_ecr_repository.ecr_repository.repository_url
definition_name = local.service_name
}
}
resource "aws_ecs_task_definition" "definition" {
family = local.service_name
container_definitions = data.template_file.definition.rendered
task_role_arn = aws_iam_role.task_role.arn
execution_role_arn = aws_iam_role.service_role.arn
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
cpu = "512"
memory = "1024"
}
resource "aws_ecs_service" "service" {
name = "${local.service_name}-service"
task_definition = aws_ecs_task_definition.definition.arn
cluster = aws_ecs_cluster.cluster.id
deployment_maximum_percent = 200
deployment_minimum_healthy_percent = 100
desired_count = 0
launch_type = "FARGATE"
network_configuration {
subnets = data.aws_subnet_ids.subnets.ids
assign_public_ip = true
security_groups = [aws_security_group.ecs.id]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment