coder / modules

A collection of Terraform Modules to work with Coder.
https://registry.coder.com
Apache License 2.0
23 stars 19 forks source link

Template terms of usage #261

Open stirby opened 1 week ago

stirby commented 1 week ago

We can add a little module that adds a required terms of service for template usage:

data "coder_parameter" "terms_of_use" {
  name         = "terms-of-use"
  display_name = "Terms of use"
  description  = "Please type \"yes\" to accept the [data privacy agreement](https://coder.com/) before using this template. Otherwise, **the workspace build will fail**."
  type         = "string"
}

Then users can use a precondition in their resource lifecycle:

  lifecycle {
    # The user must accept a 
    precondition {
      condition     = regex("(?i)^\\s*yes\\s*$", data.coder_parameter.terms_of_use.value)
      error_message = "Build prevented. You must accept the terms of use before creating a workspace from this template." 
    }
  }

Once https://github.com/coder/coder/issues/12686 is shipped, we can make it fully contained within the module and prevent workspace creation if it's not accepted.