|
| 1 | +terraform { |
| 2 | + required_version = ">= 1.0" |
| 3 | + |
| 4 | + required_providers { |
| 5 | + coder = { |
| 6 | + source = "coder/coder" |
| 7 | + version = ">= 0.12" |
| 8 | + } |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +locals { |
| 13 | + # A built-in icon like "/icon/code.svg" or a full URL of icon |
| 14 | + icon_url = "https://raw.githubusercontent.com/coder/coder/main/site/static/icon/code.svg" |
| 15 | + # a map of all possible values |
| 16 | + options = { |
| 17 | + "Option 1" = { |
| 18 | + "name" = "Option 1", |
| 19 | + "value" = "1" |
| 20 | + "icon" = "/emojis/1.png" |
| 21 | + } |
| 22 | + "Option 2" = { |
| 23 | + "name" = "Option 2", |
| 24 | + "value" = "2" |
| 25 | + "icon" = "/emojis/2.png" |
| 26 | + } |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +# Add required variables for your modules and remove any unneeded variables |
| 31 | +variable "agent_id" { |
| 32 | + type = string |
| 33 | + description = "The ID of a Coder agent." |
| 34 | +} |
| 35 | + |
| 36 | +variable "log_path" { |
| 37 | + type = string |
| 38 | + description = "The path to log MODULE_NAME to." |
| 39 | + default = "/tmp/MODULE_NAME.log" |
| 40 | +} |
| 41 | + |
| 42 | +variable "port" { |
| 43 | + type = number |
| 44 | + description = "The port to run MODULE_NAME on." |
| 45 | + default = 19999 |
| 46 | +} |
| 47 | + |
| 48 | +variable "mutable" { |
| 49 | + type = bool |
| 50 | + description = "Whether the parameter is mutable." |
| 51 | + default = true |
| 52 | +} |
| 53 | +# Add other variables here |
| 54 | + |
| 55 | + |
| 56 | +resource "coder_script" "MODULE_NAME" { |
| 57 | + agent_id = var.agent_id |
| 58 | + display_name = "MODULE_NAME" |
| 59 | + icon = local.icon_url |
| 60 | + script = templatefile("${path.module}/run.sh", { |
| 61 | + LOG_PATH : var.log_path, |
| 62 | + }) |
| 63 | + run_on_start = true |
| 64 | + run_on_stopt = false |
| 65 | +} |
| 66 | + |
| 67 | +resource "coder_app" "MODULE_NAME" { |
| 68 | + agent_id = var.agent_id |
| 69 | + slug = "MODULE_NAME" |
| 70 | + display_name = "MODULE_NAME" |
| 71 | + url = "http://localhost:${var.port}" |
| 72 | + icon = loocal.icon_url |
| 73 | + subdomain = false |
| 74 | + share = "owner" |
| 75 | + |
| 76 | + # Remove if the app does not have a healthcheck endpoint |
| 77 | + healthcheck { |
| 78 | + url = "http://localhost:${var.port}/healthz" |
| 79 | + interval = 5 |
| 80 | + threshold = 6 |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +data "coder_parameter" "MODULE_NAME" { |
| 85 | + type = "list(string)" |
| 86 | + name = "MODULE_NAME" |
| 87 | + display_name = "MODULE_NAME" |
| 88 | + icon = local.icon_url |
| 89 | + mutable = var.mutable |
| 90 | + default = local.options["Option 1"]["value"] |
| 91 | + |
| 92 | + dynamic "option" { |
| 93 | + for_each = local.options |
| 94 | + content { |
| 95 | + icon = option.value.icon |
| 96 | + name = option.value.name |
| 97 | + value = option.value.value |
| 98 | + } |
| 99 | + } |
| 100 | +} |
| 101 | + |
0 commit comments