Skip to content

Commit fed583c

Browse files
fargate spot capacity provider fix
1 parent 1f80005 commit fed583c

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

examples/fargate/container.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ module "container_httpd" {
33
version = "0.58.1"
44
container_name = "container-httpd"
55
container_image = "httpd:latest"
6+
essential = "true"
67

78
log_configuration = {
89
logDriver = "awslogs"
910
options = {
10-
"awslogs-group" : "/aws/ecs/ecs-${var.name}/contaner-httpd",
11+
"awslogs-group" : "/aws/ecs/${var.name}/contaner-httpd",
1112
"awslogs-region" : "ap-southeast-1",
1213
"awslogs-stream-prefix" : "aws",
1314
"awslogs-create-group" : "true"

examples/fargate/data.tf

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ data "aws_caller_identity" "current" {}
55
data "aws_vpc" "default" {
66
filter {
77
name = "tag:Name"
8-
values = ["*Main*"]
8+
values = ["*aft-vpc*"]
99
}
1010
}
1111

@@ -27,7 +27,7 @@ data "aws_subnets" "private" {
2727
data "aws_iam_policy_document" "execution_custom_policy" {
2828
statement {
2929
actions = ["logs:CreateLogGroup"]
30-
resources = ["arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/aws/ecs/ecs-${var.name}/*"]
30+
resources = ["arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:*"]
3131
}
3232
}
3333

@@ -37,9 +37,7 @@ data "aws_iam_policy_document" "task_ecs_exec_policy" {
3737
"kms:Decrypt",
3838
]
3939

40-
resources = [
41-
module.fargate_cluster.ecs_cluster_kms_arn
42-
]
40+
resources = ["*"]
4341
}
4442
statement {
4543
actions = [

examples/fargate/locals.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ locals {
1818
])
1919
service_task_cpu = 256
2020
service_task_memory = 512
21-
service_desired_count = 1
21+
service_desired_count = 4
22+
service_deployment_maximum_percent = 600
23+
service_deployment_minimum_healthy_percent = 100
2224
ecs_load_balancers = [
2325
{
2426
target_group_arn = element(module.alb.target_group_arns, 0),

examples/fargate/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ module "fargate_cluster" {
1010
service_map = local.service_map
1111
service_subnets = data.aws_subnets.private.ids
1212
service_security_groups = [aws_security_group.ecs_sg.id]
13+
14+
capacity_providers = ["FARGATE", "FARGATE_SPOT"]
15+
default_capacity_provider_strategy = [
16+
{ "capacity_provider" : "FARGATE_SPOT", "weight" : 2, "base" : 0 },
17+
{ "capacity_provider" : "FARGATE", "weight" : 1, "base" : 1 }
18+
]
1319
}
1420

1521
module "ecs_task_execution_role" {
@@ -20,6 +26,8 @@ module "ecs_task_execution_role" {
2026
custom_role_policy_arns = [
2127
"arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
2228
]
29+
policy = data.aws_iam_policy_document.execution_custom_policy.json
30+
policy_name = "ecs-task-execution-policy-${var.name}"
2331
}
2432

2533
module "ecs_task_role" {

modules/service/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ resource "aws_ecs_service" "this" {
8383
data.aws_ecs_task_definition.this.revision,
8484
)}"
8585

86-
launch_type = var.launch_type
86+
launch_type = length(var.capacity_provider_strategy) > 0 ? null : var.launch_type
8787
platform_version = var.launch_type == "FARGATE" ? var.platform_version : null
8888
desired_count = var.desired_count
8989
enable_ecs_managed_tags = var.enable_ecs_managed_tags

0 commit comments

Comments
 (0)