diff --git a/examples/fargate/container.tf b/examples/fargate/container.tf index 5082f83..deaef30 100644 --- a/examples/fargate/container.tf +++ b/examples/fargate/container.tf @@ -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" diff --git a/examples/fargate/data.tf b/examples/fargate/data.tf index 47aa142..2468a9a 100644 --- a/examples/fargate/data.tf +++ b/examples/fargate/data.tf @@ -5,7 +5,7 @@ data "aws_caller_identity" "current" {} data "aws_vpc" "default" { filter { name = "tag:Name" - values = ["*Main*"] + values = ["*aft-vpc*"] } } @@ -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}/*"] } } diff --git a/examples/fargate/locals.tf b/examples/fargate/locals.tf index 6879d19..7be002b 100644 --- a/examples/fargate/locals.tf +++ b/examples/fargate/locals.tf @@ -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), diff --git a/examples/fargate/main.tf b/examples/fargate/main.tf index 61f27fd..76e00ed 100644 --- a/examples/fargate/main.tf +++ b/examples/fargate/main.tf @@ -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" { @@ -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" { diff --git a/modules/service/main.tf b/modules/service/main.tf index 0e41010..bfb5332 100644 --- a/modules/service/main.tf +++ b/modules/service/main.tf @@ -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