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

Commita8324ca

Browse files
committed
fix provisioner, add resource test
1 parent1139e44 commita8324ca

File tree

7 files changed

+527
-9
lines changed

7 files changed

+527
-9
lines changed

‎provisioner/terraform/resources.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ type agentAttributes struct {
5757
DisplayApps []agentDisplayAppsAttributes`mapstructure:"display_apps"`
5858
Orderint64`mapstructure:"order"`
5959
ResourcesMonitoring []agentResourcesMonitoring`mapstructure:"resources_monitoring"`
60-
Devcontainers []agentDevcontainer`mapstructure:"devcontainers"`
6160
}
6261

63-
typeagentDevcontainerstruct {
62+
typeagentDevcontainerAttributesstruct {
63+
AgentIDstring`mapstructure:"agent_id"`
6464
WorkspaceFolderstring`mapstructure:"workspace_folder"`
6565
ConfigPathstring`mapstructure:"config_path"`
6666
}
@@ -353,13 +353,6 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
353353
agent.Auth=&proto.Agent_InstanceId{}
354354
}
355355

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

@@ -603,6 +596,32 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
603596
}
604597
}
605598

599+
// Associate Dev Containers with agents.
600+
for_,resources:=rangetfResourcesByLabel {
601+
for_,resource:=rangeresources {
602+
ifresource.Type!="coder_devcontainer" {
603+
continue
604+
}
605+
varattrsagentDevcontainerAttributes
606+
err=mapstructure.Decode(resource.AttributeValues,&attrs)
607+
iferr!=nil {
608+
returnnil,xerrors.Errorf("decode script attributes: %w",err)
609+
}
610+
for_,agents:=rangeresourceAgents {
611+
for_,agent:=rangeagents {
612+
// Find agents with the matching ID and associate them!
613+
if!dependsOnAgent(graph,agent,attrs.AgentID,resource) {
614+
continue
615+
}
616+
agent.Devcontainers=append(agent.Devcontainers,&proto.Devcontainer{
617+
WorkspaceFolder:attrs.WorkspaceFolder,
618+
ConfigPath:attrs.ConfigPath,
619+
})
620+
}
621+
}
622+
}
623+
}
624+
606625
// Associate metadata blocks with resources.
607626
resourceMetadata:=map[string][]*proto.Resource_Metadata{}
608627
resourceHidden:=map[string]bool{}

‎provisioner/terraform/resources_test.go

Lines changed: 31 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
@@ -1375,6 +1403,9 @@ func sortResources(resources []*proto.Resource) {
13751403
sort.Slice(agent.Scripts,func(i,jint)bool {
13761404
returnagent.Scripts[i].DisplayName<agent.Scripts[j].DisplayName
13771405
})
1406+
sort.Slice(agent.Devcontainers,func(i,jint)bool {
1407+
returnagent.Devcontainers[i].WorkspaceFolder<agent.Devcontainers[j].WorkspaceFolder
1408+
})
13781409
}
13791410
sort.Slice(resource.Agents,func(i,jint)bool {
13801411
returnresource.Agents[i].Name<resource.Agents[j].Name
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