Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitac1a8da

Browse files
committed
fix provisioner, add resource test
1 parentb5c1ae0 commitac1a8da

File tree

7 files changed

+536
-9
lines changed

7 files changed

+536
-9
lines changed

‎provisioner/terraform/resources.go

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package terraform
33
import (
44
"context"
55
"fmt"
6+
"slices"
67
"strings"
78

89
"github.com/awalterschulze/gographviz"
@@ -57,10 +58,10 @@ type agentAttributes struct {
5758
DisplayApps []agentDisplayAppsAttributes`mapstructure:"display_apps"`
5859
Orderint64`mapstructure:"order"`
5960
ResourcesMonitoring []agentResourcesMonitoring`mapstructure:"resources_monitoring"`
60-
Devcontainers []agentDevcontainer`mapstructure:"devcontainers"`
6161
}
6262

63-
typeagentDevcontainerstruct {
63+
typeagentDevcontainerAttributesstruct {
64+
AgentIDstring`mapstructure:"agent_id"`
6465
WorkspaceFolderstring`mapstructure:"workspace_folder"`
6566
ConfigPathstring`mapstructure:"config_path"`
6667
}
@@ -353,13 +354,6 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
353354
agent.Auth=&proto.Agent_InstanceId{}
354355
}
355356

356-
for_,devcontainer:=rangeattrs.Devcontainers {
357-
agent.Devcontainers=append(agent.Devcontainers,&proto.Devcontainer{
358-
WorkspaceFolder:devcontainer.WorkspaceFolder,
359-
ConfigPath:devcontainer.ConfigPath,
360-
})
361-
}
362-
363357
// The label is used to find the graph node!
364358
agentLabel:=convertAddressToLabel(tfResource.Address)
365359

@@ -603,6 +597,43 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
603597
}
604598
}
605599

600+
// Associate Dev Containers with agents.
601+
for_,resources:=rangetfResourcesByLabel {
602+
for_,resource:=rangeresources {
603+
ifresource.Type!="coder_devcontainer" {
604+
continue
605+
}
606+
varattrsagentDevcontainerAttributes
607+
err=mapstructure.Decode(resource.AttributeValues,&attrs)
608+
iferr!=nil {
609+
returnnil,xerrors.Errorf("decode script attributes: %w",err)
610+
}
611+
for_,agents:=rangeresourceAgents {
612+
for_,agent:=rangeagents {
613+
// Find agents with the matching ID and associate them!
614+
if!dependsOnAgent(graph,agent,attrs.AgentID,resource) {
615+
continue
616+
}
617+
agent.Devcontainers=append(agent.Devcontainers,&proto.Devcontainer{
618+
WorkspaceFolder:attrs.WorkspaceFolder,
619+
ConfigPath:attrs.ConfigPath,
620+
})
621+
}
622+
}
623+
}
624+
}
625+
// Stable order.
626+
for_,agents:=rangeresourceAgents {
627+
for_,agent:=rangeagents {
628+
slices.SortStableFunc(agent.Devcontainers,func(a,b*proto.Devcontainer)int {
629+
ifn:=strings.Compare(a.WorkspaceFolder,b.WorkspaceFolder);n!=0 {
630+
returnn
631+
}
632+
returnstrings.Compare(a.ConfigPath,b.ConfigPath)
633+
})
634+
}
635+
}
636+
606637
// Associate metadata blocks with resources.
607638
resourceMetadata:=map[string][]*proto.Resource_Metadata{}
608639
resourceHidden:=map[string]bool{}

‎provisioner/terraform/resources_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,34 @@ func TestConvertResources(t *testing.T) {
830830
}},
831831
}},
832832
},
833+
"devcontainer": {
834+
resources: []*proto.Resource{
835+
{
836+
Name:"dev",
837+
Type:"null_resource",
838+
Agents: []*proto.Agent{{
839+
Name:"main",
840+
OperatingSystem:"linux",
841+
Architecture:"amd64",
842+
Auth:&proto.Agent_Token{},
843+
ConnectionTimeoutSeconds:120,
844+
DisplayApps:&displayApps,
845+
ResourcesMonitoring:&proto.ResourcesMonitoring{},
846+
Devcontainers: []*proto.Devcontainer{
847+
{
848+
WorkspaceFolder:"/workspace1",
849+
},
850+
{
851+
WorkspaceFolder:"/workspace2",
852+
ConfigPath:"/workspace2/.devcontainer/devcontainer.json",
853+
},
854+
},
855+
}},
856+
},
857+
{Name:"dev1",Type:"coder_devcontainer"},
858+
{Name:"dev2",Type:"coder_devcontainer"},
859+
},
860+
},
833861
} {
834862
folderName:=folderName
835863
expected:=expected
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
terraform {
2+
required_providers {
3+
coder={
4+
source="coder/coder"
5+
version=">=2.0.0"
6+
}
7+
}
8+
}
9+
10+
resource"coder_agent""main" {
11+
os="linux"
12+
arch="amd64"
13+
}
14+
15+
resource"coder_devcontainer""dev1" {
16+
agent_id=coder_agent.main.id
17+
workspace_folder="/workspace1"
18+
}
19+
20+
resource"coder_devcontainer""dev2" {
21+
agent_id=coder_agent.main.id
22+
workspace_folder="/workspace2"
23+
config_path="/workspace2/.devcontainer/devcontainer.json"
24+
}
25+
26+
resource"null_resource""dev" {
27+
depends_on=[
28+
coder_agent.main
29+
]
30+
}

‎provisioner/terraform/testdata/devcontainer/devcontainer.tfplan.dot

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp