Coder.comC
Coder.com12mo ago
25 replies
Zoker

How to use coder_parameter to force_rebuild docker images?

Hi there,

I saw this in the docs:
data "coder_parameter" "force_rebuild" {
  name         = "force_rebuild"
  type         = "bool"
  description  = "Rebuild the Docker image rather than use the cached one."
  mutable      = true
  default      = false
  ephemeral    = true
}

(source: https://coder.com/docs/@v2.19.0/admin/templates/extending-templates/parameters#ephemeral-parameters)

How I want to add this feature to my current template.
I guess I need to use the force_rebuild somewhere in order to really force the rebuild of the image, right?
Probably in the triggers here:
resource "docker_image" "main" {
  name = "coder-${data.coder_workspace.me.id}"
  build {
    context = "."
    build_args = {
      USER = local.username
    }
  }
  triggers = {
    docker_sha1 = sha1(filesha1("./Dockerfile"))
    terraform_sha1 = sha1(filesha1("./Base.tf"))
    rebuild_sha1 = sha1(data.coder_parameter.force_rebuild.value)      <-- something like this? 
    assets_sha1 = sha1(join("", [for f in fileset(path.module, "./assets/*") : filesha1(f)]))
  }
}


Would this work? Thanks!
Use parameters to customize workspaces at build
Build Parameters | Coder Docs
Preview image
Was this page helpful?