Skip to content

Instantly share code, notes, and snippets.

@david7482
Created April 18, 2020 20:14
Show Gist options
  • Save david7482/d0b6e1fe13ca275773ff4730e6b40925 to your computer and use it in GitHub Desktop.
Save david7482/d0b6e1fe13ca275773ff4730e6b40925 to your computer and use it in GitHub Desktop.
resource "aws_ecs_cluster" "cluster" {
name = "stateful-fargate"
setting {
name = "containerInsights"
value = "enabled"
}
tags = {
Name = "stateful-fargate"
}
}
################################
# ECS service
################################
resource "random_id" "ecs_service_random" {
keepers = {
service_version = "1"
}
byte_length = 2
}
resource "aws_ecs_service" "main" {
name = "filebrowser-${random_id.ecs_service_random.hex}"
cluster = aws_ecs_cluster.cluster.id
task_definition = aws_ecs_task_definition.main.arn
desired_count = 1
launch_type = "FARGATE"
platform_version = "1.4.0"
deployment_maximum_percent = 200
deployment_minimum_healthy_percent = 100
network_configuration {
security_groups = [data.aws_security_group.default.id, aws_security_group.alb_sg.id]
subnets = data.aws_subnet_ids.default.ids
assign_public_ip = true
}
load_balancer {
target_group_arn = aws_alb_target_group.alb_tg.id
container_name = local.task_container_name
container_port = local.task_container_port
}
lifecycle {
create_before_destroy = true
}
enable_ecs_managed_tags = true
propagate_tags = "SERVICE"
tags = {
Name = "filebrowser-${random_id.ecs_service_random.hex}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment