From 09ace542e887fb559d72be4bdc77c93580b4e35e Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Fri, 10 Jun 2022 17:04:36 -0500 Subject: [PATCH 1/2] fix: ensure `agentResource` is non-nil --- provisioner/terraform/resources.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/provisioner/terraform/resources.go b/provisioner/terraform/resources.go index 044ad9837445a..f78a086c134c6 100644 --- a/provisioner/terraform/resources.go +++ b/provisioner/terraform/resources.go @@ -127,12 +127,14 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res } } - agents, exists := resourceAgents[agentResource.Label] - if !exists { - agents = make([]*proto.Agent, 0) + if agentResource != nil { + agents, exists := resourceAgents[agentResource.Label] + if !exists { + agents = make([]*proto.Agent, 0) + } + agents = append(agents, agent) + resourceAgents[agentResource.Label] = agents } - agents = append(agents, agent) - resourceAgents[agentResource.Label] = agents } // Manually associate agents with instance IDs. From 00a3677c376275359d033d20ae227c25160fe7c6 Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Fri, 10 Jun 2022 17:09:46 -0500 Subject: [PATCH 2/2] continue on loop --- provisioner/terraform/resources.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/provisioner/terraform/resources.go b/provisioner/terraform/resources.go index f78a086c134c6..639ed8876fba3 100644 --- a/provisioner/terraform/resources.go +++ b/provisioner/terraform/resources.go @@ -127,14 +127,16 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res } } - if agentResource != nil { - agents, exists := resourceAgents[agentResource.Label] - if !exists { - agents = make([]*proto.Agent, 0) - } - agents = append(agents, agent) - resourceAgents[agentResource.Label] = agents + if agentResource == nil { + continue + } + + agents, exists := resourceAgents[agentResource.Label] + if !exists { + agents = make([]*proto.Agent, 0) } + agents = append(agents, agent) + resourceAgents[agentResource.Label] = agents } // Manually associate agents with instance IDs.