terraform/internal/backend/local
Martin Atkins f0034beb33 core: refactoring.ImpliedMoveStatements replaces NodeCountBoundary
Going back a long time we've had a special magic behavior which tries to
recognize a situation where a module author either added or removed the
"count" argument from a resource that already has instances, and to
silently rename the zeroth or no-key instance so that we don't plan to
destroy and recreate the associated object.

Now we have a more general idea of "move statements", and specifically
the idea of "implied" move statements which replicates the same heuristic
we used to use for this behavior, we can treat this magic renaming rule as
just another "move statement", special only in that Terraform generates it
automatically rather than it being written out explicitly in the
configuration.

In return for wiring that in, we can now remove altogether the
NodeCountBoundary graph node type and its associated graph transformer,
CountBoundaryTransformer. We handle moves as a preprocessing step before
building the plan graph, so we no longer need to include any special nodes
in the graph to deal with that situation.

The test updates here are mainly for the graph builders themselves, to
acknowledge that indeed we're no longer inserting the NodeCountBoundary
vertices. The vertices that NodeCountBoundary previously depended on now
become dependencies of the special "root" vertex, although in many cases
here we don't see that explicitly because of the transitive reduction
algorithm, which notices when there's already an equivalent indirect
dependency chain and removes the redundant edge.

We already have plenty of test coverage for these "count boundary" cases
in the context tests whose names start with TestContext2Plan_count and
TestContext2Apply_resourceCount, all of which continued to pass here
without any modification and so are not visible in the diff. The test
functions particularly relevant to this situation are:
 - TestContext2Plan_countIncreaseFromNotSet
 - TestContext2Plan_countDecreaseToOne
 - TestContext2Plan_countOneIndex
 - TestContext2Apply_countDecreaseToOneCorrupted

The last of those in particular deals with the situation where we have
both a no-key instance _and_ a zero-key instance in the prior state, which
is interesting here because to exercises an intentional interaction
between refactoring.ImpliedMoveStatements and refactoring.ApplyMoves,
where we intentionally generate an implied move statement that produces
a collision and then expect ApplyMoves to deal with it in the same way as
it would deal with all other collisions, and thus ensure we handle both
the explicit and implied collisions in the same way.

This does affect some UI-level tests, because a nice side-effect of this
new treatment of this old feature is that we can now report explicitly
in the UI that we're assigning new addresses to these objects, whereas
before we just said nothing and hoped the user would just guess what had
happened and why they therefore weren't seeing a diff.

The backend/local plan tests actually had a pre-existing bug where they
were using a state with a different instance key than the config called
for but getting away with it because we'd previously silently fix it up.
That's still fixed up, but now done with an explicit mention in the UI
and so I made the state consistent with the configuration here so that the
tests would be able to recognize _real_ differences where present, as
opposed to the errant difference caused by that inconsistency.
2021-09-20 09:06:22 -07:00
..
testdata core: Functional-style API for terraform.Context 2021-08-30 13:59:14 -07:00
backend.go core: Functional-style API for terraform.Context 2021-08-30 13:59:14 -07:00
backend_apply.go core: Functional-style API for terraform.Context 2021-08-30 13:59:14 -07:00
backend_apply_test.go save apply diagnostics on backend failure 2021-05-17 17:22:04 -04:00
backend_local.go core: Functional-style API for terraform.Context 2021-08-30 13:59:14 -07:00
backend_local_test.go fix temp directory handling in some tests 2021-09-13 13:45:04 -04:00
backend_plan.go core: Functional-style API for terraform.Context 2021-08-30 13:59:14 -07:00
backend_plan_test.go core: refactoring.ImpliedMoveStatements replaces NodeCountBoundary 2021-09-20 09:06:22 -07:00
backend_refresh.go core: Functional-style API for terraform.Context 2021-08-30 13:59:14 -07:00
backend_refresh_test.go Move terraform/ to internal/terraform/ 2021-05-17 14:09:07 -07:00
backend_test.go core: Functional-style API for terraform.Context 2021-08-30 13:59:14 -07:00
cli.go Move backend/ to internal/backend/ 2021-05-17 14:09:07 -07:00
hook_state.go Move terraform/ to internal/terraform/ 2021-05-17 14:09:07 -07:00
hook_state_test.go Move terraform/ to internal/terraform/ 2021-05-17 14:09:07 -07:00
local_test.go Move backend/ to internal/backend/ 2021-05-17 14:09:07 -07:00
testing.go fix temp directory handling in some tests 2021-09-13 13:45:04 -04:00