TemplatesModules
Back to Templates
Scratch Icon

Scratch

By:
A minimal starter template for Coder
Source
README

Copy and paste the following into main.tf and run coder template push:

1terraform {
2  required_providers {
3    coder = {
4      source = "coder/coder"
5    }
6  }
7}
8
9data "coder_provisioner" "me" {}
10
11data "coder_workspace" "me" {}
12
13resource "coder_agent" "main" {
14  arch = data.coder_provisioner.me.arch
15  os   = data.coder_provisioner.me.os
16
17  metadata {
18    display_name = "CPU Usage"
19    key          = "0_cpu_usage"
20    script       = "coder stat cpu"
21    interval     = 10
22    timeout      = 1
23  }
24
25  metadata {
26    display_name = "RAM Usage"
27    key          = "1_ram_usage"
28    script       = "coder stat mem"
29    interval     = 10
30    timeout      = 1
31  }
32}
33
34# Use this to set environment variables in your workspace
35# details: https://registry.terraform.io/providers/coder/coder/latest/docs/resources/env
36resource "coder_env" "welcome_message" {
37  agent_id = coder_agent.main.id
38  name     = "WELCOME_MESSAGE"
39  value    = "Welcome to your Coder workspace!"
40}
41
42# Adds code-server
43# See all available modules at https://registry.coder.com
44module "code-server" {
45  source   = "registry.coder.com/modules/code-server/coder"
46  version  = "1.0.2"
47  agent_id = coder_agent.main.id
48}
49
50# Runs a script at workspace start/stop or on a cron schedule
51# details: https://registry.terraform.io/providers/coder/coder/latest/docs/resources/script
52resource "coder_script" "startup_script" {
53  agent_id           = coder_agent.main.id
54  display_name       = "Startup Script"
55  script             = <<-EOF
56    #!/bin/sh
57    set -e
58    # Run programs at workspace startup
59  EOF
60  run_on_start       = true
61  start_blocks_login = true
62}
63