Limit workspace CPU and memory resources

Configuration Coder v2.19.0 self hosted, Terraform 1.9.8, DinD with Sysbox current main.tf Does not limit cpu, does not impose a hard limit, but adjusts the priority of the container relative to others.
resource "docker_container" "workspace" {
#
memory = 2048 # Memory limit at 2048 MB (2 GB)
cpu_shares = 1024 # Default CPU weight
#
}
resource "docker_container" "workspace" {
#
memory = 2048 # Memory limit at 2048 MB (2 GB)
cpu_shares = 1024 # Default CPU weight
#
}
main.tf desired, but in error
resource "docker_container" "workspace" {
#
resources {
limits {
memory = "512m" # Memory limit at 512 MB
cpu = 1 # CPU limit at 1 unit (equivalent to one CPU core)
}
reservations {
memory = "256m" # Memory reservation at 256 MB
cpu = 0.5 # CPU reservation at 0.5 units
}
}
#
}
resource "docker_container" "workspace" {
#
resources {
limits {
memory = "512m" # Memory limit at 512 MB
cpu = 1 # CPU limit at 1 unit (equivalent to one CPU core)
}
reservations {
memory = "256m" # Memory reservation at 256 MB
cpu = 0.5 # CPU reservation at 0.5 units
}
}
#
}
Error returned
Terraform 1.9.8

Error: Unsupported block type

on main.tf line 114, in resource "docker_container" "workspace": 114: resources {

Blocks of type "resources" are not expected here.
Terraform 1.9.8

Error: Unsupported block type

on main.tf line 114, in resource "docker_container" "workspace": 114: resources {

Blocks of type "resources" are not expected here.
Question Does anyone know how to limit the CPU and memory resources of workspaces with Terraform? THANKS a lot.
5 Replies
Codercord
Codercord3mo ago
<#1336645061030449163>
Category
Help needed
Product
Coder (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
Atif
Atif3mo ago
Please check the docs for docker_container resource. Specifically check cpu and memory properties.
Phorcys
Phorcys3mo ago
(@Monnomcjo)
Monnomcjo
MonnomcjoOP3mo ago
Unfortunately the cpu property does not exist. I see this subject is covered in other posts. And that there is no resolution without workaround.
Phorcys
Phorcys3mo ago
yes, you can only set cpu_set or cpu_shares unfortunately Docker dose not provide better control than this, if you really need to throttle workspaces you should be looking into Kubernetes

Did you find this page helpful?