Skip to content

Commit

Permalink
ECS: Use FARGATE_SPOT capacity provider
Browse files Browse the repository at this point in the history
  • Loading branch information
takano32 committed Feb 27, 2024
1 parent 9b9ded5 commit 9a197cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
3 changes: 3 additions & 0 deletions db.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ resource "aws_rds_cluster" "this" {
}

resource "aws_rds_cluster_instance" "cluster_instances" {
count = 3
availability_zone = module.vpc.azs[count.index % length(module.vpc.azs)]

engine = "aurora-mysql"
engine_version = "8.0.mysql_aurora.3.04.1"
cluster_identifier = "${var.prefix}-${var.environment}"
Expand Down
21 changes: 12 additions & 9 deletions fargate.tf
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ resource "aws_ecs_cluster" "this" {
}

resource "aws_ecs_cluster_capacity_providers" "cluster" {
cluster_name = "${var.prefix}-${var.environment}"

capacity_providers = ["FARGATE_SPOT", "FARGATE"]

cluster_name = "${var.prefix}-${var.environment}"
capacity_providers = ["FARGATE_SPOT"]
default_capacity_provider_strategy {
base = 0
weight = 10
capacity_provider = "FARGATE_SPOT"
}
}
Expand Down Expand Up @@ -148,14 +148,15 @@ resource "aws_ecs_service" "this" {
desired_count = var.desired_count
launch_type = "FARGATE"
enable_execute_command = true

network_configuration {
security_groups = [
aws_security_group.alb.id,
aws_security_group.db.id,
aws_security_group.efs.id,
aws_security_group.elasticache.id
]
subnets = module.vpc.private_subnets
]
subnets = module.vpc.private_subnets
}

load_balancer {
Expand All @@ -165,12 +166,14 @@ resource "aws_ecs_service" "this" {
}

lifecycle {
ignore_changes = [desired_count]
ignore_changes = [
task_definition,
desired_count,
capacity_provider_strategy
]
}

}


resource "aws_ecs_task_definition" "this" {
family = "${var.prefix}-${var.environment}"
execution_role_arn = aws_iam_role.task_execution_role.arn
Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ variable "error_ttl" {

variable "desired_count" {
description = "The number of instances of fargate tasks to keep running"
default = "2"
default = "3"
}
variable "log_retention_in_days" {
description = "The number of days to retain cloudwatch log"
Expand Down

0 comments on commit 9a197cf

Please sign in to comment.