Skip to content

Commit 8e1e46c

Browse files
jasonwalshbnchdrff
andauthored
feat: allow task definitions to be used by Fargate (#37)
* set cpu and memory at task level, for fargate compatibility * set fargate-incompatible variables to null by default * style: run terraform fmt * fix: use default values for cpu and memory * test: update fixture data Co-authored-by: Benjamin Chodoroff <[email protected]>
1 parent 0649a56 commit 8e1e46c

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ resource "aws_ecs_task_definition" "ecs_task_definition" {
135135
ipc_mode = var.ipc_mode
136136
network_mode = var.network_mode
137137
pid_mode = var.pid_mode
138+
139+
# Fargate requires cpu and memory to be defined at the task level
140+
cpu = var.cpu
141+
memory = var.memory
142+
138143
dynamic "placement_constraints" {
139144
for_each = var.placement_constraints
140145
content {

test/fixtures/multiple.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"command": null,
4-
"cpu": null,
4+
"cpu": 256,
55
"disableNetworking": false,
66
"dnsSearchDomains": null,
77
"dnsServers": null,
@@ -42,7 +42,7 @@
4242
},
4343
{
4444
"command": null,
45-
"cpu": null,
45+
"cpu": 256,
4646
"disableNetworking": false,
4747
"dnsSearchDomains": null,
4848
"dnsServers": null,

test/fixtures/single.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"command": null,
4-
"cpu": null,
4+
"cpu": 256,
55
"disableNetworking": false,
66
"dnsSearchDomains": null,
77
"dnsServers": null,
@@ -68,7 +68,7 @@
6868
"awslogs-region": "us-east-1"
6969
}
7070
},
71-
"memory": null,
71+
"memory": 512,
7272
"memoryReservation": 512,
7373
"mountPoints": [
7474
{

variables.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ variable "command" {
88
}
99

1010
variable "cpu" {
11-
default = 0
11+
default = 256
1212
description = "The number of cpu units reserved for the container"
13+
type = number
1314
}
1415

1516
variable "disableNetworking" {
@@ -95,7 +96,7 @@ variable "interactive" {
9596
}
9697

9798
variable "ipc_mode" {
98-
default = "host"
99+
default = null
99100
description = "The IPC resource namespace to use for the containers in the task"
100101
}
101102

@@ -118,8 +119,9 @@ variable "logConfiguration" {
118119
}
119120

120121
variable "memory" {
121-
default = 0
122+
default = 512
122123
description = "The hard limit (in MiB) of memory to present to the container"
124+
type = number
123125
}
124126

125127
variable "memoryReservation" {
@@ -144,7 +146,7 @@ variable "network_mode" {
144146
}
145147

146148
variable "pid_mode" {
147-
default = "host"
149+
default = null
148150
description = "The process namespace to use for the containers in the task"
149151
}
150152

0 commit comments

Comments
 (0)