Skip to content

Commit

Permalink
fargate spot capacity provider fix (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
nagagovindarajan authored Feb 2, 2024
1 parent 1f80005 commit f111628
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion examples/fargate/container.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ module "container_httpd" {
version = "0.58.1"
container_name = "container-httpd"
container_image = "httpd:latest"
essential = "true"

log_configuration = {
logDriver = "awslogs"
options = {
"awslogs-group" : "/aws/ecs/ecs-${var.name}/contaner-httpd",
"awslogs-group" : "/aws/ecs/${var.name}/contaner-httpd",
"awslogs-region" : "ap-southeast-1",
"awslogs-stream-prefix" : "aws",
"awslogs-create-group" : "true"
Expand Down
4 changes: 2 additions & 2 deletions examples/fargate/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ data "aws_caller_identity" "current" {}
data "aws_vpc" "default" {
filter {
name = "tag:Name"
values = ["*Main*"]
values = ["*aft-vpc*"]
}
}

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

Expand Down
9 changes: 6 additions & 3 deletions examples/fargate/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ locals {
service_container_definitions = jsonencode([
module.container_httpd.json_map_object
])
service_task_cpu = 256
service_task_memory = 512
service_desired_count = 1
service_task_cpu = 256
service_task_memory = 512
service_desired_count = 4
service_deployment_maximum_percent = 600
service_deployment_minimum_healthy_percent = 100

ecs_load_balancers = [
{
target_group_arn = element(module.alb.target_group_arns, 0),
Expand Down
8 changes: 8 additions & 0 deletions examples/fargate/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ module "fargate_cluster" {
service_map = local.service_map
service_subnets = data.aws_subnets.private.ids
service_security_groups = [aws_security_group.ecs_sg.id]

capacity_providers = ["FARGATE", "FARGATE_SPOT"]
default_capacity_provider_strategy = [
{ "capacity_provider" : "FARGATE_SPOT", "weight" : 2, "base" : 0 },
{ "capacity_provider" : "FARGATE", "weight" : 1, "base" : 1 }
]
}

module "ecs_task_execution_role" {
Expand All @@ -20,6 +26,8 @@ module "ecs_task_execution_role" {
custom_role_policy_arns = [
"arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
]
policy = data.aws_iam_policy_document.execution_custom_policy.json
policy_name = "ecs-task-execution-policy-${var.name}"
}

module "ecs_task_role" {
Expand Down
2 changes: 1 addition & 1 deletion modules/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ resource "aws_ecs_service" "this" {
data.aws_ecs_task_definition.this.revision,
)}"

launch_type = var.launch_type
launch_type = length(var.capacity_provider_strategy) > 0 ? null : var.launch_type
platform_version = var.launch_type == "FARGATE" ? var.platform_version : null
desired_count = var.desired_count
enable_ecs_managed_tags = var.enable_ecs_managed_tags
Expand Down

0 comments on commit f111628

Please sign in to comment.