Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of relax import for_each validation into v1.10 #36136

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading