Skip to content

Commit 157d13b

Browse files
committed
WIP
1 parent 38a0251 commit 157d13b

8 files changed

+1460
-3
lines changed

provisioner/terraform/resources.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
489489
for _, agents := range resourceAgents {
490490
for _, agent := range agents {
491491
// Find agents with the matching ID and associate them!
492-
if agent.Id != attrs.AgentID {
492+
if !dependsOnAgent(graph, agent, attrs.AgentID, resource) {
493493
continue
494494
}
495495
agent.Scripts = append(agent.Scripts, &proto.Script{

provisioner/terraform/resources_test.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,47 @@ func TestConvertResources(t *testing.T) {
319319
Type: "coder_env",
320320
}},
321321
},
322+
"multiple-agents-multiple-scripts": {
323+
resources: []*proto.Resource{{
324+
Name: "dev1",
325+
Type: "null_resource",
326+
Agents: []*proto.Agent{{
327+
Name: "dev1",
328+
OperatingSystem: "linux",
329+
Architecture: "amd64",
330+
Scripts: []*proto.Script{
331+
{
332+
DisplayName: "Foobar Script 1",
333+
Script: "echo foobar 1",
334+
},
335+
{
336+
DisplayName: "Foobar Script 2",
337+
Script: "echo foobar 2",
338+
},
339+
},
340+
Auth: &proto.Agent_Token{},
341+
ConnectionTimeoutSeconds: 120,
342+
DisplayApps: &displayApps,
343+
}},
344+
}, {
345+
Name: "dev2",
346+
Type: "null_resource",
347+
Agents: []*proto.Agent{{
348+
Name: "dev2",
349+
OperatingSystem: "linux",
350+
Architecture: "amd64",
351+
Scripts: []*proto.Script{
352+
{
353+
DisplayName: "Foobar Script 3",
354+
Script: "echo foobar 3",
355+
},
356+
},
357+
Auth: &proto.Agent_Token{},
358+
ConnectionTimeoutSeconds: 120,
359+
DisplayApps: &displayApps,
360+
}},
361+
}},
362+
},
322363
// Tests fetching metadata about workspace resources.
323364
"resource-metadata": {
324365
resources: []*proto.Resource{{
@@ -636,7 +677,7 @@ func TestConvertResources(t *testing.T) {
636677
}},
637678
},
638679
} {
639-
if folderName != "multiple-agents-multiple-apps" {
680+
if folderName != "multiple-agents-multiple-scripts" {
640681
continue
641682
}
642683
folderName := folderName

provisioner/terraform/testdata/generate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -euo pipefail
44
cd "$(dirname "${BASH_SOURCE[0]}")"
55

6-
for d in */; do
6+
for d in multiple-agents-multiple-scripts/; do
77
pushd "$d"
88
name=$(basename "$(pwd)")
99

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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_script" "script1" {
21+
agent_id = coder_agent.dev1.id
22+
display_name = "Foobar Script 1"
23+
script = "echo foobar 1"
24+
25+
run_on_start = true
26+
}
27+
28+
resource "coder_script" "script2" {
29+
agent_id = coder_agent.dev1.id
30+
display_name = "Foobar Script 2"
31+
script = "echo foobar 2"
32+
33+
run_on_start = true
34+
}
35+
36+
resource "coder_script" "script3" {
37+
agent_id = coder_agent.dev2.id
38+
display_name = "Foobar Script 3"
39+
script = "echo foobar 3"
40+
41+
run_on_start = true
42+
}
43+
44+
resource "null_resource" "dev1" {
45+
depends_on = [
46+
coder_agent.dev1
47+
]
48+
}
49+
50+
resource "null_resource" "dev2" {
51+
depends_on = [
52+
coder_agent.dev2
53+
]
54+
}

provisioner/terraform/testdata/multiple-agents-multiple-scripts/multiple-agents-multiple-scripts.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)