fix: Use Terraform address to index resource + agent association (#1577)

This fixes resources created from Terraform modules not
properly being associated with an agent.

By not using the address, and resource identifiers prefixed
with `module.<name>` would be missed!
This commit is contained in:
Kyle Carberry
2022-05-18 16:26:08 -05:00
committed by GitHub
parent 0706c60445
commit f3fe2a08ce
+2 -4
View File
@@ -357,11 +357,10 @@ func parseTerraformPlan(ctx context.Context, terraform *tfexec.Terraform, planfi
if resource.Type == "coder_agent" || resource.Type == "coder_agent_instance" {
continue
}
resourceKey := strings.Join([]string{resource.Type, resource.Name}, ".")
resources = append(resources, &proto.Resource{
Name: resource.Name,
Type: resource.Type,
Agents: findAgents(resourceDependencies, agents, resourceKey),
Agents: findAgents(resourceDependencies, agents, resource.Address),
})
}
@@ -498,8 +497,7 @@ func parseTerraformApply(ctx context.Context, terraform *tfexec.Terraform, state
if resource.Type == "coder_agent" || resource.Type == "coder_agent_instance" {
continue
}
resourceKey := strings.Join([]string{resource.Type, resource.Name}, ".")
resourceAgents := findAgents(resourceDependencies, agents, resourceKey)
resourceAgents := findAgents(resourceDependencies, agents, resource.Address)
for _, agent := range resourceAgents {
// Didn't use instance identity.
if agent.GetToken() != "" {