Skip to content

Commit

Permalink
core: Don't return other errors if move statements are invalid
Browse files Browse the repository at this point in the history
Because our validation rules depend on some dynamic results produced by
actually running the plan, we deal with moves in a "backwards" order where
we try to apply them first -- ignoring anything strange we might find --
and then validate the original statements only after planning.

An unfortunate consequence of that approach is that when the move
statements are invalid it's likely that move execution will not fully
complete, and so the generated plan is likely to be incorrect and might
well include errors resulting from the unresolved moves.

To mitigate that, here we let any move validation errors supersede all
other diagnostics that the plan phase might've generated, in the hope that
it'll help the user focus on fixing the incorrect move statements without
creating confusing by reporting errors that only appeared as a quick of
how Terraform worked around the invalid move statements earlier.
  • Loading branch information
apparentlymart committed Sep 23, 2021
1 parent b417aa8 commit f371f46
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/terraform/context_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,18 @@ func (c *Context) planWalk(config *configs.Config, prevRunState *states.State, r
})
diags = diags.Append(walker.NonFatalDiagnostics)
diags = diags.Append(walkDiags)
diags = diags.Append(c.postPlanValidateMoves(config, moveStmts, walker.InstanceExpander.AllInstances()))
moveValidateDiags := c.postPlanValidateMoves(config, moveStmts, walker.InstanceExpander.AllInstances())
if moveValidateDiags.HasErrors() {
// If any of the move statements are invalid then those errors take
// precedence over any other errors because an incomplete move graph
// is quite likely to be the _cause_ of various errors. This oddity
// comes from the fact that we need to apply the moves before we
// actually validate them, because validation depends on the result
// of first trying to plan.
return nil, moveValidateDiags
}
diags = diags.Append(moveValidateDiags) // might just contain warnings

if len(moveResults.Blocked) > 0 && !diags.HasErrors() {
// If we had blocked moves and we're not going to be returning errors
// then we'll report the blockers as a warning. We do this only in the
Expand Down

0 comments on commit f371f46

Please sign in to comment.