From 29c879ca3a6eeed37080de8005c72136bc502b8f Mon Sep 17 00:00:00 2001 From: Liam Cervante Date: Mon, 22 Apr 2024 16:16:18 +0200 Subject: [PATCH] add nil check --- internal/terraform/node_resource_plan.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/terraform/node_resource_plan.go b/internal/terraform/node_resource_plan.go index 208722444d2e..5bbe21077066 100644 --- a/internal/terraform/node_resource_plan.go +++ b/internal/terraform/node_resource_plan.go @@ -98,11 +98,15 @@ func (n *nodeExpandPlannableResource) ModifyCreateBeforeDestroy(v bool) error { func (n *nodeExpandPlannableResource) DynamicExpand(ctx EvalContext) (*Graph, tfdiags.Diagnostics) { var diags tfdiags.Diagnostics - // First, make sure the count and the foreach don't refer to the same resource - diags = diags.Append(validateSelfRefInExpr(n.Addr.Resource, n.Config.Count)) - diags = diags.Append(validateSelfRefInExpr(n.Addr.Resource, n.Config.ForEach)) - if diags.HasErrors() { - return nil, diags + // First, make sure the count and the foreach don't refer to the same + // resource. The config maybe nil if we are generating configuration, or + // deleting a resource. + if n.Config != nil { + diags = diags.Append(validateSelfRefInExpr(n.Addr.Resource, n.Config.Count)) + diags = diags.Append(validateSelfRefInExpr(n.Addr.Resource, n.Config.ForEach)) + if diags.HasErrors() { + return nil, diags + } } // Expand the current module.