Skip to content

Commit d978111

Browse files
committed
add advanced dev containers
1 parent 5a4ca2f commit d978111

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Advanced Dev Container Configuration
2+
3+
This page extends the [dev containers documentation](./devcontainers.md) with patterns for multiple dev containers,
4+
user-controlled startup, repository selection, and infrastructure tuning.
5+
6+
## Run Multiple Dev Containers
7+
8+
Run independent dev containers in the same workspace so each component appears as its own agent.
9+
10+
In this example, there are two: repositories called `frontend` and `backend`:
11+
12+
```terraform
13+
# Clone each repo
14+
module "git-clone-frontend" {
15+
count = data.coder_workspace.me.start_count
16+
source = "dev.registry.coder.com/modules/git-clone/coder"
17+
18+
agent_id = coder_agent.main.id
19+
url = "https://github.com/your-org/frontend.git"
20+
}
21+
22+
module "git-clone-backend" {
23+
count = data.coder_workspace.me.start_count
24+
source = "dev.registry.coder.com/modules/git-clone/coder"
25+
26+
agent_id = coder_agent.main.id
27+
url = "https://github.com/your-org/backend.git"
28+
}
29+
30+
# Dev container resources
31+
resource "coder_devcontainer" "frontend" {
32+
count = data.coder_workspace.me.start_count
33+
agent_id = coder_agent.main.id
34+
workspace_folder = module.git-clone-frontend[0].repo_dir
35+
}
36+
37+
resource "coder_devcontainer" "backend" {
38+
count = data.coder_workspace.me.start_count
39+
agent_id = coder_agent.main.id
40+
workspace_folder = module.git-clone-backend[0].repo_dir
41+
}
42+
```
43+
44+
Each dev container appears as a separate agent, so developers can connect to each separately.
45+
46+
## Conditional Startup
47+
48+
Use `coder_parameter` booleans to let workspace creators choose which dev containers start automatically,
49+
reducing resource usage for unneeded components:
50+
51+
```terraform
52+
data "coder_parameter" "autostart_frontend" {
53+
type = "bool"
54+
name = "Autostart frontend container"
55+
default = true
56+
mutable = true
57+
order = 3
58+
}
59+
60+
resource "coder_devcontainer" "frontend" {
61+
count = data.coder_parameter.autostart_frontend.value ? data.coder_workspace.me.start_count : 0
62+
agent_id = coder_agent.main.id
63+
workspace_folder = module.git-clone-frontend[0].repo_dir
64+
}
65+
```
66+
67+
## Repository-selection Patterns
68+
69+
Prompt users to pick a repository or team at workspace creation time and clone the selected repo(s) automatically into the workspace:
70+
71+
1. Add a parameter to the template:
72+
73+
```terraform
74+
data "coder_parameter" "project" {
75+
name = "project"
76+
display_name = "Choose a project"
77+
type = "string"
78+
default = "https://github.com/coder/coder.git"
79+
80+
option {
81+
name = "coder/coder"
82+
value = "https://github.com/coder/coder.git"
83+
}
84+
option {
85+
name = "terraform-provider-coder"
86+
value = "https://github.com/coder/terraform-provider-coder.git"
87+
}
88+
}
89+
```
90+
91+
1. Change the `git-clone` module to accept the `value` as the `url`:
92+
93+
```terraform
94+
module "git-clone" {
95+
count = data.coder_workspace.me.start_count
96+
source = "dev.registry.coder.com/modules/git-clone/coder"
97+
agent_id = coder_agent.main.id
98+
url = data.coder_parameter.project.value
99+
}
100+
```

0 commit comments

Comments
 (0)