Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions infra/modules/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ resource "aws_ecs_task_definition" "app" {
{
name = local.container_name,
image = local.image_url,
memory = var.memory,
cpu = var.cpu,
memory = var.app_memory,
cpu = var.app_cpu,
networkMode = "awsvpc",
essential = true,
readonlyRootFilesystem = !var.enable_command_execution,
Expand Down Expand Up @@ -147,8 +147,8 @@ resource "aws_ecs_task_definition" "app" {
}
}

cpu = var.cpu
memory = var.memory
cpu = var.task_cpu
memory = var.task_memory

requires_compatibilities = ["FARGATE"]

Expand Down
20 changes: 16 additions & 4 deletions infra/modules/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ variable "container_port" {
default = 8000
}

variable "cpu" {
variable "app_cpu" {
type = number
default = 256
description = "Number of cpu units used by the task, expessed as an integer value, e.g 512 "
description = "Number of cpu units used by the primary application container, expessed as an integer value, e.g 512 "
}

variable "task_cpu" {
type = number
default = 256
description = "Number of cpu units used by the task definition, expessed as an integer value, e.g 512. Identical to app_cpu if you are not running any sidecar containers."
}

variable "db_vars" {
Expand Down Expand Up @@ -124,10 +130,16 @@ variable "is_temporary" {
default = false
}

variable "memory" {
variable "app_memory" {
type = number
default = 512
description = "Amount (in MiB) of memory used by the primary application container. e.g. 2048"
}

variable "task_memory" {
type = number
default = 512
description = "Amount (in MiB) of memory used by the task. e.g. 2048"
description = "Amount (in MiB) of memory used by the task definition. e.g. 2048. Identical to app_cpu if you are not running any sidecar containers."
}

variable "network_name" {
Expand Down
6 changes: 4 additions & 2 deletions infra/{{app_name}}/app-config/env-config/service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ locals {
service_config = {
service_name = "${var.app_name}-${var.environment}"
region = var.default_region
cpu = var.service_cpu
memory = var.service_memory
app_cpu = var.app_cpu
task_cpu = var.task_cpu
app_memory = var.app_memory
task_memory = var.task_memory
desired_instance_count = var.service_desired_instance_count
enable_command_execution = var.enable_command_execution

Expand Down
14 changes: 12 additions & 2 deletions infra/{{app_name}}/app-config/env-config/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ variable "project_name" {
type = string
}

variable "service_cpu" {
variable "app_cpu" {
type = number
default = 256
}

variable "task_cpu" {
type = number
default = 256
}
Expand All @@ -97,7 +102,12 @@ variable "service_desired_instance_count" {
default = 1
}

variable "service_memory" {
variable "app_memory" {
type = number
default = 512
}

variable "task_memory" {
type = number
default = 512
}
Expand Down
9 changes: 7 additions & 2 deletions infra/{{app_name}}/app-config/prod.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ module "prod_config" {
# These numbers are a starting point based on this article
# Update the desired instance size and counts based on the project's specific needs
# https://conchchow.medium.com/aws-ecs-fargate-compute-capacity-planning-a5025cb40bd0
service_cpu = 1024
service_memory = 4096
#
# See the following link for a description of the cpu and memory constraints.
# https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#task_size
app_cpu = 1024
task_cpu = 1024
app_memory = 4096
task_memory = 4096
service_desired_instance_count = 3

# Enables ECS Exec access for debugging or jump access.
Expand Down
6 changes: 4 additions & 2 deletions infra/{{app_name}}/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ module "service" {

enable_waf = module.app_config.enable_waf

cpu = local.service_config.cpu
memory = local.service_config.memory
app_cpu = local.service_config.app_cpu
task_cpu = local.service_config.task_cpu
app_memory = local.service_config.app_memory
task_memory = local.service_config.task_memory
desired_instance_count = local.service_config.desired_instance_count
enable_command_execution = local.service_config.enable_command_execution

Expand Down
Loading