Skip to content

Commit

Permalink
Merge pull request #36136 from hashicorp/backport/jbardin/import-expa…
Browse files Browse the repository at this point in the history
…nsion-validation/hardly-glowing-titmouse

Backport of relax import for_each validation into v1.10
  • Loading branch information
jbardin authored Nov 29, 2024
2 parents a08e034 + 14394d7 commit 571db67
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 571db67

Please sign in to comment.