Skip to content

Commit 856a802

Browse files
authored
chore: update fly-docker-image example template (#6661)
* update fly-docker-image example template * Add unites for volume storage
1 parent c3fb1b3 commit 856a802

File tree

1 file changed

+56
-9
lines changed
  • examples/templates/fly-docker-image

1 file changed

+56
-9
lines changed

examples/templates/fly-docker-image/main.tf

+56-9
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ resource "fly_app" "workspace" {
2727
org = var.fly_org
2828
}
2929

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+
# }
3434

3535
resource "fly_volume" "home-volume" {
3636
app = fly_app.workspace.name
@@ -46,11 +46,13 @@ resource "fly_machine" "workspace" {
4646
name = data.coder_workspace.me.name
4747
image = data.coder_parameter.docker-image.value
4848
cpus = data.coder_parameter.cpu.value
49+
cputype = data.coder_parameter.cputype.value
4950
memorymb = data.coder_parameter.memory.value * 1024
5051
env = {
5152
CODER_AGENT_TOKEN = "${coder_agent.main.token}"
5253
}
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]
5456
services = [
5557
{
5658
ports = [
@@ -125,15 +127,31 @@ data "coder_parameter" "cpu" {
125127
}
126128
}
127129

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+
128146
data "coder_parameter" "memory" {
129147
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)"
131149
type = "number"
132-
default = "1"
150+
default = "2"
133151
icon = "/icon/memory.svg"
134152
mutable = true
135153
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
137155
max = 16
138156
}
139157
}
@@ -142,7 +160,7 @@ data "coder_parameter" "volume-size" {
142160
name = "Volume Size"
143161
description = "The size of the volume to create for the workspace in GB (1-20)"
144162
type = "number"
145-
default = "3"
163+
default = "1"
146164
icon = "https://raw.githubusercontent.com/matifali/logos/main/database.svg"
147165
validation {
148166
min = 1
@@ -261,9 +279,38 @@ resource "coder_agent" "main" {
261279
code-server --auth none >/tmp/code-server.log 2>&1 &
262280
# Set the hostname to the workspace name
263281
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
264285
EOT
265286
}
266287

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+
267314
data "coder_provisioner" "me" {
268315
}
269316

0 commit comments

Comments
 (0)