From d5dbb0e2fcff10f072a74f9105669f1eebc6daf2 Mon Sep 17 00:00:00 2001 From: kylecarbs Date: Wed, 18 May 2022 20:44:21 +0000 Subject: [PATCH] fix: Use Terraform address to index resource + agent association 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.` would be missed! --- provisioner/terraform/provision.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/provisioner/terraform/provision.go b/provisioner/terraform/provision.go index ecc493b991c56..56da18c732815 100644 --- a/provisioner/terraform/provision.go +++ b/provisioner/terraform/provision.go @@ -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() != "" {