Skip to content

Commit

Permalink
backport of commit 926b688
Browse files Browse the repository at this point in the history
  • Loading branch information
jbardin committed Nov 27, 2024
1 parent a08e034 commit 14394d7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
2 changes: 1 addition & 1 deletion internal/terraform/context_apply_deferred_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
13 changes: 0 additions & 13 deletions internal/terraform/node_resource_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 14394d7

Please sign in to comment.