Skip to content

Commit 8a1f50f

Browse files
committed
WIP
1 parent 41f2de0 commit 8a1f50f

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

provisioner/terraform/resources.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,11 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
427427
for _, agents := range resourceAgents {
428428
for _, agent := range agents {
429429
// Find agents with the matching ID and associate them!
430-
if agent.Id != attrs.AgentID {
430+
431+
if !dependsOnAgent(graph, agent, attrs.AgentID, resource) {
431432
continue
432433
}
434+
433435
agent.Apps = append(agent.Apps, &proto.App{
434436
Slug: attrs.Slug,
435437
DisplayName: attrs.DisplayName,
@@ -748,6 +750,30 @@ func convertAddressToLabel(address string) string {
748750
return cut
749751
}
750752

753+
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.
755+
if agent.Id == "" && appAgentID == "" {
756+
appNodeSuffix := fmt.Sprintf(`] coder_app.%s (expand)"`, resource.Name)
757+
agentNodeSuffix := fmt.Sprintf(`] coder_agent.%s (expand)"`, agent.Name)
758+
759+
// Traverse the graph to check if the coder_app depends on coder_agent.
760+
for _, dst := range graph.Edges.SrcToDsts {
761+
for _, edges := range dst {
762+
for _, edge := range edges {
763+
if strings.HasSuffix(edge.Src, appNodeSuffix) &&
764+
strings.HasSuffix(edge.Dst, agentNodeSuffix) {
765+
return true
766+
}
767+
}
768+
}
769+
}
770+
return false
771+
}
772+
773+
// Provision: agent ID and app ID are present
774+
return agent.Id == appAgentID
775+
}
776+
751777
type graphResource struct {
752778
Label string
753779
Depth uint
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.8.4
1+
1.8.5

0 commit comments

Comments
 (0)