Skip to content

Commit ac8492d

Browse files
committed
Support Fargate Spot
1 parent 16e5a00 commit ac8492d

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

terraform/prod/ecs_cluster.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
resource "aws_ecs_cluster" "cluster" {
2-
name = "${local.env}-cluster"
2+
name = "${local.env}-cluster"
3+
capacity_providers = ["FARGATE", "FARGATE_SPOT"]
34
}
45

56
module "ecs_task_execution_iam" {

terraform/prod/ecs_service_api.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ resource "aws_ecs_service" "api" {
4747
cluster = aws_ecs_cluster.cluster.id
4848
task_definition = aws_ecs_task_definition.api.arn
4949
desired_count = 0 # desired_count will be updated by autoscaling
50-
launch_type = "FARGATE"
5150

5251
load_balancer {
5352
target_group_arn = aws_lb_target_group.api_blue.arn
@@ -64,6 +63,17 @@ resource "aws_ecs_service" "api" {
6463
type = "CODE_DEPLOY"
6564
}
6665

66+
capacity_provider_strategy {
67+
capacity_provider = "FARGATE"
68+
weight = 2
69+
base = 1
70+
}
71+
72+
capacity_provider_strategy {
73+
capacity_provider = "FARGATE_SPOT"
74+
weight = 1
75+
}
76+
6777
lifecycle {
6878
# This parameter will be chaned by CodeDeploy
6979
ignore_changes = [
@@ -86,8 +96,8 @@ module "api_autoscaling" {
8696

8797
cluster_name = aws_ecs_cluster.cluster.name
8898
service_name = aws_ecs_service.api.name
89-
min_capacity = 1
90-
max_capacity = 1
99+
min_capacity = 3
100+
max_capacity = 6
91101
cpu_target_value = 60
92102
role_arn = data.terraform_remote_state.common.outputs.ecs_application_autoscaling_role_arn
93103
}

terraform/prod/ecs_service_web.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ resource "aws_ecs_service" "web" {
4747
cluster = aws_ecs_cluster.cluster.id
4848
task_definition = aws_ecs_task_definition.web.arn
4949
desired_count = 0 # desired_count will be updated by autoscaling
50-
launch_type = "FARGATE"
5150

5251
load_balancer {
5352
target_group_arn = aws_lb_target_group.web_blue.arn
@@ -64,6 +63,17 @@ resource "aws_ecs_service" "web" {
6463
type = "CODE_DEPLOY"
6564
}
6665

66+
capacity_provider_strategy {
67+
capacity_provider = "FARGATE"
68+
weight = 2
69+
base = 1
70+
}
71+
72+
capacity_provider_strategy {
73+
capacity_provider = "FARGATE_SPOT"
74+
weight = 1
75+
}
76+
6777
lifecycle {
6878
# This parameter will be chaned by CodeDeploy
6979
ignore_changes = [
@@ -86,8 +96,8 @@ module "web_autoscaling" {
8696

8797
cluster_name = aws_ecs_cluster.cluster.name
8898
service_name = aws_ecs_service.web.name
89-
min_capacity = 1
90-
max_capacity = 1
99+
min_capacity = 3
100+
max_capacity = 6
91101
cpu_target_value = 60
92102
role_arn = data.terraform_remote_state.common.outputs.ecs_application_autoscaling_role_arn
93103
}

terraform/stg/ecs_cluster.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
resource "aws_ecs_cluster" "cluster" {
2-
name = "${local.env}-cluster"
2+
name = "${local.env}-cluster"
3+
capacity_providers = ["FARGATE", "FARGATE_SPOT"]
34
}
45

56
module "ecs_task_execution_iam" {

terraform/stg/ecs_service_api.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ resource "aws_ecs_service" "api" {
4747
cluster = aws_ecs_cluster.cluster.id
4848
task_definition = aws_ecs_task_definition.api.arn
4949
desired_count = 0 # desired_count will be updated by autoscaling
50-
launch_type = "FARGATE"
5150

5251
load_balancer {
5352
target_group_arn = aws_lb_target_group.api_blue.arn
@@ -64,6 +63,11 @@ resource "aws_ecs_service" "api" {
6463
type = "CODE_DEPLOY"
6564
}
6665

66+
capacity_provider_strategy {
67+
capacity_provider = "FARGATE_SPOT"
68+
weight = 100
69+
}
70+
6771
lifecycle {
6872
# This parameter will be chaned by CodeDeploy
6973
ignore_changes = [

terraform/stg/ecs_service_web.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ resource "aws_ecs_service" "web" {
4747
cluster = aws_ecs_cluster.cluster.id
4848
task_definition = aws_ecs_task_definition.web.arn
4949
desired_count = 0 # desired_count will be updated by autoscaling
50-
launch_type = "FARGATE"
5150

5251
load_balancer {
5352
target_group_arn = aws_lb_target_group.web_blue.arn
@@ -64,6 +63,11 @@ resource "aws_ecs_service" "web" {
6463
type = "CODE_DEPLOY"
6564
}
6665

66+
capacity_provider_strategy {
67+
capacity_provider = "FARGATE_SPOT"
68+
weight = 100
69+
}
70+
6771
lifecycle {
6872
# This parameter will be chaned by CodeDeploy
6973
ignore_changes = [

0 commit comments

Comments
 (0)