Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba91a95

Browse files
authored
feat(examples/templates/gcp-vm-container): add GCP region selector, code-server and JetBrains modules (#15551)
1 parent ffb0ebb commit ba91a95

File tree

1 file changed

+41
-62
lines changed
  • examples/templates/gcp-vm-container

1 file changed

+41
-62
lines changed

examples/templates/gcp-vm-container/main.tf

+41-62
Original file line numberDiff line numberDiff line change
@@ -9,58 +9,26 @@ terraform {
99
}
1010
}
1111

12-
provider "coder" {
13-
}
12+
provider "coder" {}
1413

1514
variable "project_id" {
1615
description = "Which Google Compute Project should your workspace live in?"
1716
}
1817

19-
data "coder_parameter" "zone" {
20-
name = "zone"
21-
display_name = "Zone"
22-
description = "Which zone should your workspace live in?"
23-
type = "string"
24-
default = "us-central1-a"
25-
icon = "/emojis/1f30e.png"
26-
mutable = false
27-
option {
28-
name = "North America (Northeast)"
29-
value = "northamerica-northeast1-a"
30-
icon = "/emojis/1f1fa-1f1f8.png"
31-
}
32-
option {
33-
name = "North America (Central)"
34-
value = "us-central1-a"
35-
icon = "/emojis/1f1fa-1f1f8.png"
36-
}
37-
option {
38-
name = "North America (West)"
39-
value = "us-west2-c"
40-
icon = "/emojis/1f1fa-1f1f8.png"
41-
}
42-
option {
43-
name = "Europe (West)"
44-
value = "europe-west4-b"
45-
icon = "/emojis/1f1ea-1f1fa.png"
46-
}
47-
option {
48-
name = "South America (East)"
49-
value = "southamerica-east1-a"
50-
icon = "/emojis/1f1e7-1f1f7.png"
51-
}
18+
module "gcp_region" {
19+
source = "registry.coder.com/modules/gcp-region/coder"
20+
version = "1.0.12"
21+
regions = ["us", "europe"]
5222
}
5323

5424
provider "google" {
55-
zone = data.coder_parameter.zone.value
25+
zone = module.gcp_region.value
5626
project = var.project_id
5727
}
5828

59-
data "google_compute_default_service_account" "default" {
60-
}
29+
data "google_compute_default_service_account" "default" {}
6130

62-
data "coder_workspace" "me" {
63-
}
31+
data "coder_workspace" "me" {}
6432
data "coder_workspace_owner" "me" {}
6533

6634
resource "coder_agent" "main" {
@@ -70,32 +38,43 @@ resource "coder_agent" "main" {
7038
startup_script = <<-EOT
7139
set -e
7240
73-
# Install the latest code-server.
74-
# Append "--version x.x.x" to install a specific version of code-server.
75-
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server
76-
77-
# Start code-server in the background.
78-
/tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
41+
# Add any commands that should be executed at workspace startup (e.g install requirements, start a program, etc) here
7942
EOT
8043
}
8144

82-
# code-server
83-
resource "coder_app" "code-server" {
84-
agent_id = coder_agent.main.id
85-
slug = "code-server"
86-
display_name = "code-server"
87-
icon = "/icon/code.svg"
88-
url = "http://localhost:13337?folder=/home/coder"
89-
subdomain = false
90-
share = "owner"
91-
92-
healthcheck {
93-
url = "http://localhost:13337/healthz"
94-
interval = 3
95-
threshold = 10
96-
}
45+
# See https://registry.coder.com/modules/code-server
46+
module "code-server" {
47+
count = data.coder_workspace.me.start_count
48+
source = "registry.coder.com/modules/code-server/coder"
49+
50+
# This ensures that the latest version of the module gets downloaded, you can also pin the module version to prevent breaking changes in production.
51+
version = ">= 1.0.0"
52+
53+
agent_id = coder_agent.main.id
54+
order = 1
55+
}
56+
57+
# See https://registry.coder.com/modules/jetbrains-gateway
58+
module "jetbrains_gateway" {
59+
count = data.coder_workspace.me.start_count
60+
source = "registry.coder.com/modules/jetbrains-gateway/coder"
61+
62+
# JetBrains IDEs to make available for the user to select
63+
jetbrains_ides = ["IU", "PY", "WS", "PS", "RD", "CL", "GO", "RM"]
64+
default = "IU"
65+
66+
# Default folder to open when starting a JetBrains IDE
67+
folder = "/home/coder"
68+
69+
# This ensures that the latest version of the module gets downloaded, you can also pin the module version to prevent breaking changes in production.
70+
version = ">= 1.0.0"
71+
72+
agent_id = coder_agent.main.id
73+
agent_name = "main"
74+
order = 2
9775
}
9876

77+
# See https://registry.terraform.io/modules/terraform-google-modules/container-vm
9978
module "gce-container" {
10079
source = "terraform-google-modules/container-vm/google"
10180
version = "3.0.0"
@@ -111,7 +90,7 @@ module "gce-container" {
11190
}
11291

11392
resource "google_compute_instance" "dev" {
114-
zone = data.coder_parameter.zone.value
93+
zone = module.gcp_region.value
11594
count = data.coder_workspace.me.start_count
11695
name = "coder-${lower(data.coder_workspace_owner.me.name)}-${lower(data.coder_workspace.me.name)}"
11796
machine_type = "e2-medium"

0 commit comments

Comments
 (0)