Coder.comC
Coder.com12mo ago
6 replies
Monnomcjo

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
  #
}


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
    }
  }
  #
}


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.


Question


Does anyone know how to limit the CPU and memory resources of workspaces with Terraform? THANKS a lot.
Was this page helpful?