@@ -27,10 +27,10 @@ resource "fly_app" "workspace" {
27
27
org = var. fly_org
28
28
}
29
29
30
- resource "fly_ip" "workspace-ip4" {
31
- app = fly_app. workspace . name
32
- type = " v4"
33
- }
30
+ # resource "fly_ip" "workspace-ip4" {
31
+ # app = fly_app.workspace.name
32
+ # type = "v4"
33
+ # }
34
34
35
35
resource "fly_volume" "home-volume" {
36
36
app = fly_app. workspace . name
@@ -46,11 +46,13 @@ resource "fly_machine" "workspace" {
46
46
name = data. coder_workspace . me . name
47
47
image = data. coder_parameter . docker-image . value
48
48
cpus = data. coder_parameter . cpu . value
49
+ cputype = data. coder_parameter . cputype . value
49
50
memorymb = data. coder_parameter . memory . value * 1024
50
51
env = {
51
52
CODER_AGENT_TOKEN = " ${ coder_agent . main . token } "
52
53
}
53
- entrypoint = [" sh" , " -c" , replace (coder_agent. main . init_script , " /localhost|127\\ .0\\ .0\\ .1/" , " ${ fly_ip . workspace-ip4 . address } " )] # replace localhost with the IP of the workspace
54
+ # entrypoint = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "${fly_ip.workspace-ip4.address}")] # replace localhost with the IP of the workspace
55
+ entrypoint = [" sh" , " -c" , coder_agent . main . init_script ]
54
56
services = [
55
57
{
56
58
ports = [
@@ -125,15 +127,31 @@ data "coder_parameter" "cpu" {
125
127
}
126
128
}
127
129
130
+ data "coder_parameter" "cputype" {
131
+ name = " CPU Type"
132
+ description = " Which CPU type do you want?"
133
+ default = " shared"
134
+ icon = " https://raw.githubusercontent.com/matifali/logos/main/cpu-1.svg"
135
+ mutable = true
136
+ option {
137
+ name = " Shared"
138
+ value = " shared"
139
+ }
140
+ option {
141
+ name = " Performance"
142
+ value = " performance"
143
+ }
144
+ }
145
+
128
146
data "coder_parameter" "memory" {
129
147
name = " Memory (GB)"
130
- description = " The amount of memory to allocate to the workspace in GB (1-16 )"
148
+ description = " The amount of memory to allocate to the workspace in GB (up to 16GB )"
131
149
type = " number"
132
- default = " 1 "
150
+ default = " 2 "
133
151
icon = " /icon/memory.svg"
134
152
mutable = true
135
153
validation {
136
- min = 1
154
+ min = data . coder_parameter . cputype . value == " performance " ? 2 : 1 # if the CPU type is performance, the minimum memory is 2GB
137
155
max = 16
138
156
}
139
157
}
@@ -142,7 +160,7 @@ data "coder_parameter" "volume-size" {
142
160
name = " Volume Size"
143
161
description = " The size of the volume to create for the workspace in GB (1-20)"
144
162
type = " number"
145
- default = " 3 "
163
+ default = " 1 "
146
164
icon = " https://raw.githubusercontent.com/matifali/logos/main/database.svg"
147
165
validation {
148
166
min = 1
@@ -261,9 +279,38 @@ resource "coder_agent" "main" {
261
279
code-server --auth none >/tmp/code-server.log 2>&1 &
262
280
# Set the hostname to the workspace name
263
281
sudo hostname -b "${ data . coder_workspace . me . name } -fly"
282
+ # Install the Fly CLI and add it to the PATH
283
+ curl -L https://fly.io/install.sh | sh
284
+ echo "export PATH=\$PATH:/home/coder/.fly" >> ~/.bashrc
264
285
EOT
265
286
}
266
287
288
+ resource "coder_metadata" "workspace" {
289
+ count = data. coder_workspace . me . start_count
290
+ resource_id = fly_app. workspace . id
291
+ icon = data. coder_parameter . region . option [index (data. coder_parameter . region . option . * . value , data. coder_parameter . region . value )]. icon
292
+ item {
293
+ key = " Region"
294
+ value = data. coder_parameter . region . option [index (data. coder_parameter . region . option . * . value , data. coder_parameter . region . value )]. name
295
+ }
296
+ item {
297
+ key = " CPU Type"
298
+ value = data. coder_parameter . cputype . option [index (data. coder_parameter . cputype . option . * . value , data. coder_parameter . cputype . value )]. name
299
+ }
300
+ item {
301
+ key = " CPU Count"
302
+ value = data. coder_parameter . cpu . value
303
+ }
304
+ item {
305
+ key = " Memory (GB)"
306
+ value = data. coder_parameter . memory . value
307
+ }
308
+ item {
309
+ key = " Volume Size (GB)"
310
+ value = data. coder_parameter . volume-size . value
311
+ }
312
+ }
313
+
267
314
data "coder_provisioner" "me" {
268
315
}
269
316
0 commit comments