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

Commit9963149

Browse files
committed
fix: Use Terraform address to index resource + agent association
Closes#1705.There was an issue in the implementation brought by#1577 by not trimmingthe array value when resources use counts. This should fix it, and addsa test to be sure!
1 parent99c79c7 commit9963149

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

‎provisioner/terraform/provision.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func parseTerraformPlan(ctx context.Context, terraform *tfexec.Terraform, planfi
390390
}
391391
}
392392

393-
agents[resource.Address]=agent
393+
agents[convertAddressToLabel(resource.Address)]=agent
394394
}
395395

396396
for_,resource:=rangetfResources {
@@ -400,11 +400,10 @@ func parseTerraformPlan(ctx context.Context, terraform *tfexec.Terraform, planfi
400400
ifresource.Type=="coder_agent"||resource.Type=="coder_agent_instance" {
401401
continue
402402
}
403-
resourceKey:=strings.Join([]string{resource.Type,resource.Name},".")
404403
resources=append(resources,&proto.Resource{
405404
Name:resource.Name,
406405
Type:resource.Type,
407-
Agents:findAgents(resourceDependencies,agents,resourceKey),
406+
Agents:findAgents(resourceDependencies,agents,convertAddressToLabel(resource.Address)),
408407
})
409408
}
410409

@@ -485,8 +484,7 @@ func parseTerraformApply(ctx context.Context, terraform *tfexec.Terraform, state
485484
default:
486485
agent.Auth=&proto.Agent_InstanceId{}
487486
}
488-
resourceKey:=strings.Join([]string{resource.Type,resource.Name},".")
489-
agents[resourceKey]=agent
487+
agents[convertAddressToLabel(resource.Address)]=agent
490488
}
491489

492490
// Manually associate agents with instance IDs.
@@ -529,8 +527,7 @@ func parseTerraformApply(ctx context.Context, terraform *tfexec.Terraform, state
529527
ifresource.Type=="coder_agent"||resource.Type=="coder_agent_instance" {
530528
continue
531529
}
532-
resourceKey:=strings.Join([]string{resource.Type,resource.Name},".")
533-
resourceAgents:=findAgents(resourceDependencies,agents,resourceKey)
530+
resourceAgents:=findAgents(resourceDependencies,agents,convertAddressToLabel(resource.Address))
534531
for_,agent:=rangeresourceAgents {
535532
// Didn't use instance identity.
536533
ifagent.GetToken()!="" {
@@ -696,8 +693,8 @@ func findDependenciesWithLabels(graph *gographviz.Graph, nodeName string) []stri
696693
// findAgents recursively searches through resource dependencies
697694
// to find associated agents. Nested is required for indirect
698695
// dependency matching.
699-
funcfindAgents(resourceDependenciesmap[string][]string,agentsmap[string]*proto.Agent,resourceKeystring) []*proto.Agent {
700-
resourceNode,exists:=resourceDependencies[resourceKey]
696+
funcfindAgents(resourceDependenciesmap[string][]string,agentsmap[string]*proto.Agent,resourceLabelstring) []*proto.Agent {
697+
resourceNode,exists:=resourceDependencies[resourceLabel]
701698
if!exists {
702699
return []*proto.Agent{}
703700
}
@@ -714,3 +711,9 @@ func findAgents(resourceDependencies map[string][]string, agents map[string]*pro
714711
}
715712
returnresourceAgents
716713
}
714+
715+
// convertAddressToLabel returns the Terraform address without the count
716+
// specifier. eg. "module.ec2_dev.ec2_instance.dev[0]" becomes "module.ec2_dev.ec2_instance.dev"
717+
funcconvertAddressToLabel(addressstring)string {
718+
returnstrings.Split(address,"[")[0]
719+
}

‎provisioner/terraform/provision_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ provider "coder" {
206206
Name:"dryrun-resource-associated-with-agent",
207207
Files:map[string]string{
208208
"main.tf":provider+`
209+
data "coder_workspace" "me" {}
209210
resource "coder_agent" "A" {
210211
count = 1
211212
os = "linux"
@@ -216,7 +217,10 @@ provider "coder" {
216217
startup_script = "code-server"
217218
}
218219
resource "null_resource" "A" {
219-
count = length(coder_agent.A)
220+
depends_on = [
221+
coder_agent.A[0]
222+
]
223+
count = data.coder_workspace.me.start_count
220224
}`,
221225
},
222226
Request:&proto.Provision_Request{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp