|
| 1 | +terraform { |
| 2 | + required_version = ">= 1.0" |
| 3 | + |
| 4 | + required_providers { |
| 5 | + coder = { |
| 6 | + source = "coder/coder" |
| 7 | + version = ">= 2.5" |
| 8 | + } |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +# Add required variables for your modules and remove any unneeded variables |
| 13 | +variable "agent_id" { |
| 14 | + type = string |
| 15 | + description = "The ID of a Coder agent." |
| 16 | +} |
| 17 | + |
| 18 | +variable "docker_socket" { |
| 19 | + type = string |
| 20 | + description = "(Optional) Docker socket URI" |
| 21 | + default = "" |
| 22 | +} |
| 23 | + |
| 24 | +variable "rstudio_server_version" { |
| 25 | + type = string |
| 26 | + description = "RStudio Server version" |
| 27 | + default = "4.5.1" |
| 28 | +} |
| 29 | + |
| 30 | +variable "disable_auth" { |
| 31 | + type = bool |
| 32 | + description = "Disable auth" |
| 33 | + default = true |
| 34 | +} |
| 35 | + |
| 36 | +variable "rstudio_user" { |
| 37 | + type = string |
| 38 | + description = "RStudio user" |
| 39 | + default = "rstudio" |
| 40 | + sensitive = true |
| 41 | +} |
| 42 | + |
| 43 | +variable "rstudio_password" { |
| 44 | + type = string |
| 45 | + description = "RStudio password" |
| 46 | + default = "rstudio" |
| 47 | + sensitive = true |
| 48 | +} |
| 49 | + |
| 50 | +variable "project_path" { |
| 51 | + type = string |
| 52 | + description = "The path to RStudio project, it will be mounted in the container." |
| 53 | + default = null |
| 54 | +} |
| 55 | + |
| 56 | +variable "port" { |
| 57 | + type = number |
| 58 | + description = "The port to run rstudio-server on." |
| 59 | + default = 8787 |
| 60 | +} |
| 61 | + |
| 62 | +variable "enable_renv" { |
| 63 | + type = bool |
| 64 | + description = "If renv.lock exists, renv will restore the environment and install dependencies" |
| 65 | + default = true |
| 66 | +} |
| 67 | + |
| 68 | +variable "renv_cache_volume" { |
| 69 | + type = string |
| 70 | + description = "The name of the volume used by Renv to preserve dependencies between container restarts" |
| 71 | + default = "renv-cache-volume" |
| 72 | +} |
| 73 | + |
| 74 | +variable "share" { |
| 75 | + type = string |
| 76 | + default = "owner" |
| 77 | + validation { |
| 78 | + condition = var.share == "owner" || var.share == "authenticated" || var.share == "public" |
| 79 | + error_message = "Incorrect value. Please set either 'owner', 'authenticated', or 'public'." |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +variable "order" { |
| 84 | + type = number |
| 85 | + description = "The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order)." |
| 86 | + default = null |
| 87 | +} |
| 88 | + |
| 89 | +variable "group" { |
| 90 | + type = string |
| 91 | + description = "The name of a group that this app belongs to." |
| 92 | + default = null |
| 93 | +} |
| 94 | + |
| 95 | +resource "coder_script" "rstudio-server" { |
| 96 | + agent_id = var.agent_id |
| 97 | + display_name = "rstudio-server" |
| 98 | + icon = "/icon/rstudio.svg" |
| 99 | + script = templatefile("${path.module}/run.sh", { |
| 100 | + DOCKER_HOST : var.docker_socket, |
| 101 | + SERVER_VERSION : var.rstudio_server_version, |
| 102 | + DISABLE_AUTH : var.disable_auth, |
| 103 | + RSTUDIO_USER : var.rstudio_user, |
| 104 | + RSTUDIO_PASSWORD : var.rstudio_password, |
| 105 | + PROJECT_PATH : var.project_path, |
| 106 | + PORT : var.port, |
| 107 | + ENABLE_RENV : var.enable_renv, |
| 108 | + RENV_CACHE_VOLUME : var.renv_cache_volume, |
| 109 | + }) |
| 110 | + run_on_start = true |
| 111 | +} |
| 112 | + |
| 113 | +resource "coder_app" "rstudio-server" { |
| 114 | + agent_id = var.agent_id |
| 115 | + slug = "rstudio-server" |
| 116 | + display_name = "RStudio Server" |
| 117 | + url = "http://localhost:${var.port}" |
| 118 | + icon = "/icon/rstudio.svg" |
| 119 | + subdomain = true |
| 120 | + share = var.share |
| 121 | + order = var.order |
| 122 | + group = var.group |
| 123 | +} |
0 commit comments