Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
mtojek committed Jul 2, 2024
commit 157d13ba9b31cd6f04753c04d078cfef4994932e
2 changes: 1 addition & 1 deletion provisioner/terraform/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
for _, agents := range resourceAgents {
for _, agent := range agents {
// Find agents with the matching ID and associate them!
if agent.Id != attrs.AgentID {
if !dependsOnAgent(graph, agent, attrs.AgentID, resource) {
continue
}
agent.Scripts = append(agent.Scripts, &proto.Script{
Expand Down
43 changes: 42 additions & 1 deletion provisioner/terraform/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,47 @@ func TestConvertResources(t *testing.T) {
Type: "coder_env",
}},
},
"multiple-agents-multiple-scripts": {
resources: []*proto.Resource{{
Name: "dev1",
Type: "null_resource",
Agents: []*proto.Agent{{
Name: "dev1",
OperatingSystem: "linux",
Architecture: "amd64",
Scripts: []*proto.Script{
{
DisplayName: "Foobar Script 1",
Script: "echo foobar 1",
},
{
DisplayName: "Foobar Script 2",
Script: "echo foobar 2",
},
},
Auth: &proto.Agent_Token{},
ConnectionTimeoutSeconds: 120,
DisplayApps: &displayApps,
}},
}, {
Name: "dev2",
Type: "null_resource",
Agents: []*proto.Agent{{
Name: "dev2",
OperatingSystem: "linux",
Architecture: "amd64",
Scripts: []*proto.Script{
{
DisplayName: "Foobar Script 3",
Script: "echo foobar 3",
},
},
Auth: &proto.Agent_Token{},
ConnectionTimeoutSeconds: 120,
DisplayApps: &displayApps,
}},
}},
},
// Tests fetching metadata about workspace resources.
"resource-metadata": {
resources: []*proto.Resource{{
Expand Down Expand Up @@ -636,7 +677,7 @@ func TestConvertResources(t *testing.T) {
}},
},
} {
if folderName != "multiple-agents-multiple-apps" {
if folderName != "multiple-agents-multiple-scripts" {
continue
}
folderName := folderName
Expand Down
2 changes: 1 addition & 1 deletion provisioner/terraform/testdata/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.22.0"
}
}
}

resource "coder_agent" "dev1" {
os = "linux"
arch = "amd64"
}

resource "coder_agent" "dev2" {
os = "linux"
arch = "amd64"
}

resource "coder_script" "script1" {
agent_id = coder_agent.dev1.id
display_name = "Foobar Script 1"
script = "echo foobar 1"

run_on_start = true
}

resource "coder_script" "script2" {
agent_id = coder_agent.dev1.id
display_name = "Foobar Script 2"
script = "echo foobar 2"

run_on_start = true
}

resource "coder_script" "script3" {
agent_id = coder_agent.dev2.id
display_name = "Foobar Script 3"
script = "echo foobar 3"

run_on_start = true
}

resource "null_resource" "dev1" {
depends_on = [
coder_agent.dev1
]
}

resource "null_resource" "dev2" {
depends_on = [
coder_agent.dev2
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading