From 14394d71ac917432a148e2da21cc7018341d2fa4 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 27 Nov 2024 15:34:27 +0000 Subject: [PATCH] backport of commit 926b688c5aa2c92f69efa7983f8ab7fbe6d99e97 --- internal/terraform/context_apply_deferred_test.go | 2 +- internal/terraform/node_resource_validate.go | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/internal/terraform/context_apply_deferred_test.go b/internal/terraform/context_apply_deferred_test.go index 13bca0170dfc..1b66c4d67ae2 100644 --- a/internal/terraform/context_apply_deferred_test.go +++ b/internal/terraform/context_apply_deferred_test.go @@ -2915,7 +2915,7 @@ import { wantDeferred: make(map[string]ExpectedDeferred), wantDiagnostic: func(diags tfdiags.Diagnostics) bool { for _, diag := range diags { - if diag.Description().Summary == "Use of import for_each in an invalid context" { + if diag.Description().Summary == "Resource has no configuration" { return true } } diff --git a/internal/terraform/node_resource_validate.go b/internal/terraform/node_resource_validate.go index 9725f3437999..7d4a0c00c2e7 100644 --- a/internal/terraform/node_resource_validate.go +++ b/internal/terraform/node_resource_validate.go @@ -572,20 +572,7 @@ func (n *NodeValidatableResource) validateImportTargets(ctx EvalContext) tfdiags return diags } - // Resource config might be nil here since we are also validating config generation. - expanded := n.Config != nil && (n.Config.ForEach != nil || n.Config.Count != nil) - if imp.Config.ForEach != nil { - if !expanded { - diags = diags.Append(&hcl.Diagnostic{ - Severity: hcl.DiagError, - Summary: "Use of import for_each in an invalid context", - Detail: "Use of for_each in import requires a resource using count or for_each.", - // FIXME: minor issue, but this points to the for_each expression rather than for_each itself. - Subject: imp.Config.ForEach.Range().Ptr(), - }) - } - forEachData, _, forEachDiags := newForEachEvaluator(imp.Config.ForEach, ctx, true).ImportValues() diags = diags.Append(forEachDiags) if forEachDiags.HasErrors() {