Skip to content

Commit 38a0251

Browse files
committed
scripts support
1 parent 8a1f50f commit 38a0251

File tree

7 files changed

+841
-4
lines changed

7 files changed

+841
-4
lines changed

provisioner/terraform/resources.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
463463
for _, agents := range resourceAgents {
464464
for _, agent := range agents {
465465
// Find agents with the matching ID and associate them!
466-
if agent.Id != attrs.AgentID {
466+
if !dependsOnAgent(graph, agent, attrs.AgentID, resource) {
467467
continue
468468
}
469469
agent.ExtraEnvs = append(agent.ExtraEnvs, &proto.Env{
@@ -751,12 +751,12 @@ func convertAddressToLabel(address string) string {
751751
}
752752

753753
func dependsOnAgent(graph *gographviz.Graph, agent *proto.Agent, appAgentID string, resource *tfjson.StateResource) bool {
754-
// Plan: we need to find if there is edge between the agent and the app.
754+
// Plan: we need to find if there is edge between the agent and the resource.
755755
if agent.Id == "" && appAgentID == "" {
756-
appNodeSuffix := fmt.Sprintf(`] coder_app.%s (expand)"`, resource.Name)
756+
appNodeSuffix := fmt.Sprintf(`] %s.%s (expand)"`, resource.Type, resource.Name)
757757
agentNodeSuffix := fmt.Sprintf(`] coder_agent.%s (expand)"`, agent.Name)
758758

759-
// Traverse the graph to check if the coder_app depends on coder_agent.
759+
// Traverse the graph to check if the coder_<resource_type> depends on coder_agent.
760760
for _, dst := range graph.Edges.SrcToDsts {
761761
for _, edges := range dst {
762762
for _, edge := range edges {

provisioner/terraform/resources_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,56 @@ func TestConvertResources(t *testing.T) {
269269
}},
270270
}},
271271
},
272+
"multiple-agents-multiple-envs": {
273+
resources: []*proto.Resource{{
274+
Name: "dev1",
275+
Type: "null_resource",
276+
Agents: []*proto.Agent{{
277+
Name: "dev1",
278+
OperatingSystem: "linux",
279+
Architecture: "amd64",
280+
ExtraEnvs: []*proto.Env{
281+
{
282+
Name: "ENV_1",
283+
Value: "Env 1",
284+
},
285+
{
286+
Name: "ENV_2",
287+
Value: "Env 2",
288+
},
289+
},
290+
Auth: &proto.Agent_Token{},
291+
ConnectionTimeoutSeconds: 120,
292+
DisplayApps: &displayApps,
293+
}},
294+
}, {
295+
Name: "dev2",
296+
Type: "null_resource",
297+
Agents: []*proto.Agent{{
298+
Name: "dev2",
299+
OperatingSystem: "linux",
300+
Architecture: "amd64",
301+
ExtraEnvs: []*proto.Env{
302+
{
303+
Name: "ENV_3",
304+
Value: "Env 3",
305+
},
306+
},
307+
Auth: &proto.Agent_Token{},
308+
ConnectionTimeoutSeconds: 120,
309+
DisplayApps: &displayApps,
310+
}},
311+
}, {
312+
Name: "env1",
313+
Type: "coder_env",
314+
}, {
315+
Name: "env2",
316+
Type: "coder_env",
317+
}, {
318+
Name: "env3",
319+
Type: "coder_env",
320+
}},
321+
},
272322
// Tests fetching metadata about workspace resources.
273323
"resource-metadata": {
274324
resources: []*proto.Resource{{
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
version = "0.22.0"
6+
}
7+
}
8+
}
9+
10+
resource "coder_agent" "dev1" {
11+
os = "linux"
12+
arch = "amd64"
13+
}
14+
15+
resource "coder_agent" "dev2" {
16+
os = "linux"
17+
arch = "amd64"
18+
}
19+
20+
resource "coder_env" "env1" {
21+
agent_id = coder_agent.dev1.id
22+
name = "ENV_1"
23+
value = "Env 1"
24+
}
25+
26+
resource "coder_env" "env2" {
27+
agent_id = coder_agent.dev1.id
28+
name = "ENV_2"
29+
value = "Env 2"
30+
}
31+
32+
resource "coder_env" "env3" {
33+
agent_id = coder_agent.dev2.id
34+
name = "ENV_3"
35+
value = "Env 3"
36+
}
37+
38+
resource "null_resource" "dev1" {
39+
depends_on = [
40+
coder_agent.dev1
41+
]
42+
}
43+
44+
resource "null_resource" "dev2" {
45+
depends_on = [
46+
coder_agent.dev2
47+
]
48+
}

provisioner/terraform/testdata/multiple-agents-multiple-envs/multiple-agents-multiple-envs.tfplan.dot

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)