Commit Graph

22550 Commits

Author SHA1 Message Date
Martin Atkins db3ea65e8b command: Fix TestApply_destroy for new provider and state types 2018-10-16 19:14:11 -07:00
Martin Atkins 4ee15ec604 core: MockProvider.GetSchema shouldn't panic if unconfigured
Some mock objects will not have any mock behavior configured for the
GetSchema method, so we should just return a valid-but-empty schema in
that case, rather than panicking as we did before.
2018-10-16 19:14:11 -07:00
Martin Atkins be7bce493e command: Update plugins_test.go for new provider types
This only makes it compile. It does not yet ensure that the tests pass.
2018-10-16 19:14:11 -07:00
Martin Atkins dc0b5292a6 command: Update refresh_test.go for new provider types
This only makes it compile. It does not yet ensure that the tests pass.
2018-10-16 19:14:11 -07:00
Martin Atkins b195c712a3 command: Update plan_test.go for new provider types
This only makes it compile. It does not yet ensure that the tests pass.
2018-10-16 19:14:11 -07:00
Martin Atkins 54c1616d73 command: Update import_test.go for new provider types
This only makes it compile. It does not yet ensure that the tests pass.
2018-10-16 19:14:11 -07:00
Martin Atkins 65341b0973 command: Update apply_test.go for new provider types
This only makes it compile. It does not yet ensure that the tests pass.
2018-10-16 19:14:11 -07:00
Martin Atkins d9051be66d command: Use new provider and provisioner types in test helpers
This moves our build errors from the test helpers out into the tests
themselves. We'll update the tests in subsequent commits.
2018-10-16 19:14:11 -07:00
Martin Atkins a2a37ae40d provisioners: Add Factory type and FactoryFixed helper
These are similar to the symbols of the same name in package "providers".

terraform.ProvisionerFactory is now an alias for provisioners.Factory, so
we can defer updating all of the existing users of it.
2018-10-16 19:14:11 -07:00
Martin Atkins 5ff35c1a9a repl: Make tests compile and execute without panics
There are still some errors left, because our expression evaluator now
does more validation than before and so we'll need to (in a subsequent
commit) actually use a fixture configuration for these tests so that the
validations will allow the expressions to be validated.
2018-10-16 19:14:11 -07:00
Martin Atkins 85aa8769db configs/configupgrade: Partially fix TestUpgradeValid
This is still not compileable because the test provider needs to be
updated to the new provider interface, but all the rest of the types are
now correct so we can update the test provider in a later commit to make
this work again.
2018-10-16 19:14:11 -07:00
Martin Atkins 2b5d9506b1 states: Fix TestResourceInstanceDeposeCurrentObject
This was missed when changing the signature of deposeCurrentObject in an
earlier commit.
2018-10-16 19:14:11 -07:00
Kristin Laemmert 3da04ef9fc backend/local: adding some informative comments to commented-out tests 2018-10-16 19:14:11 -07:00
Kristin Laemmert c661157999 plans/objchange: further harden ProposedNewObject against ~weird~
incoming values

Addresses an odd state where the priorV of an object to be changed is
known but null.

While this situation should not happen, it seemed prudent to ensure that
core is resilient to providers sending incorrect values (which might
also occur with manually edited state).
2018-10-16 19:14:11 -07:00
Kristin Laemmert 2808df48ec backend/local WIP commit - fixing tests 2018-10-16 19:14:11 -07:00
Kristin Laemmert 2a8aa6a139 plans/objchange: if priorV is unknown, fall through to the recursive call to `ProposedNewObject` 2018-10-16 19:14:11 -07:00
Martin Atkins 32974549cd plans/objchange: Fix handling of unknown in AssertValueCompatible
We need to check for the known-ness of the prior value before we check for
the null-ness of actual, because it's valid for an unknown value to become
a null.
2018-10-16 19:14:11 -07:00
Martin Atkins 896b6bc897 core: Fix test build for ./plans/planfile
This was missed in the splitting of "Replace" into "DeleteThenCreate" and
"CreateThenDelete".
2018-10-16 19:14:11 -07:00
Martin Atkins 3919a9644c core: go fmt context_plan_test.go 2018-10-16 19:14:11 -07:00
Martin Atkins 55103985f7 core: Fix TestContext2Apply_moduleDestroyOrder
This test was occasionally failing due to a missing graph edge causing it
to be non-deterministic.

The graph edge was missing because our standard schema doesn't quite match
the config fixture and so the reference checker was not finding the "blah"
argument on aws_instance.a.

This change also includes an 100ms pause for the b node just to make this
potential race more likely to hit the "wrong" ordering when the graph is
not complete.
2018-10-16 19:14:11 -07:00
Martin Atkins cbac51a470 tools/loggraphdiff: a simple tool for graph change debugging 2018-10-16 19:14:11 -07:00
Martin Atkins 620f04af73 core: Fix TestContext2Plan_moduleVariableFromSplat
The weird special-case behaviors of testDiffFn were interfering with the
outcome of this test, but we don't actually need any of those special
behaviors here so we'll use a very simple PlanResourceChangeFn
implementation instead, just letting the built-in merge behavior in core
take care of it.
2018-10-16 19:14:11 -07:00
Martin Atkins b229264bd6 core: A "go fmt" catchup
Since we started using experimental Go Modules our editor tooling hasn't
been fully functional, apparently including format-on-save support. This
is a catchup to get everything back straight again.
2018-10-16 19:14:11 -07:00
Martin Atkins eddc29d6e4 core: Fix TestRefreshGraphBuilder_configOrphans
We now include explicit separate nodes in the graph for deposed instances,
whereas before we just dealt with them inside the main nodes.
2018-10-16 19:14:11 -07:00
Martin Atkins 3b2834b8fc core: Re-instate the ignore_changes processing tests 2018-10-16 19:14:11 -07:00
Martin Atkins 33d01a2ba2 core: Fix TestContext2Apply_moduleOrphanGrandchildProvider
One of the assumptions this test was checking no longer holds: we don't
retain outputs for non-root modules in persistent state, because we can
always re-populate these on a future run by evaluating the configuration.
2018-10-16 19:14:11 -07:00
Martin Atkins 95bdf98738 core: Fix TestContext2Apply_moduleOrphanProvider
We now always expect to find a provider configuration in state. If not,
we assume a module-local one, which is not what this test was trying to
test.
2018-10-16 19:14:11 -07:00
Martin Atkins 4dd4b721ac core: Fix TestContext2Apply_moduleOrphanInheritAlias
The old-fashioned formatting of "Provider" on the shimmed state here was
causing the state upgrade code to treat it like a module-relative address,
rather than an absolute address as we now expect.
2018-10-16 19:14:11 -07:00
Martin Atkins 76fca28faa core: Better error message for prematurely-removed provider config
This error message appears in a situation that is often confusing for
users, since the connection between resources and their providers in the
state is not something we draw attention to in the user experience of
Terraform.

This new error message tries to be a bit clearer about what the user must
do to resolve it. It's still not perfect since it doesn't cover the
variant of this problem where an entire module containing a provider block
and resources has been removed at the same time, but since there isn't
an easily-summarizable way to continue in that state this will need to
do for the moment, until we find a way to file off that rough edge in
the workflow.
2018-10-16 19:14:11 -07:00
Martin Atkins 4a62315d35 core: Don't show full provider configuration block in the logs
Configuration blocks can contain sensitive information, so better to just
talk about them by reference (in this case, source location) rather than
embedding them directly, to reduce the risk of accidental information
leakage through sharing logs for debug purposes.
2018-10-16 19:14:11 -07:00
Martin Atkins 5af82917b9 core: Fix TestEvalWriteStateDeposed
This was already updated for the new state types earlier, but since then
we adjusted how deposed instances are written out in the old string
representation of state, and so this regressed.
2018-10-16 19:14:11 -07:00
Martin Atkins 902e8e1f2a core: Fix two TestContext2Input_... tests
These both just were missing some computed attributes from their schema,
which was causing them to not appear in the rendered state output.
2018-10-16 19:14:11 -07:00
Martin Atkins fdf7057ff5 core: Fix various state-pruning-related test failures
These tests show that we're still not fully pruning modules from the state
in all cases, due to us not being able to fully prune out modules that
contain resources with count set after a destroy, but this is no worse
than before so we'll accept it for now and address this separately later.

A module heading without "<no state>" but also without any instances
listed is the rendering for a module containing a resource that has no
instances, since our old string rendering of state doesn't represent
resources themselves.
2018-10-16 19:14:11 -07:00
Martin Atkins 69bcbfb813 core: Fix TestContext2Apply_destroyModuleWithAttrsReferencingResource
Now that we're properly pruning orphaned resources and empty modules from
the state, our expected output is a little different.
2018-10-16 19:14:11 -07:00
Martin Atkins 2eea07750a core: Clean up resource states when they are orphaned
We previously had mechanisms to clean up only individual instance states,
leaving behind empty resource husks in the state after they were all
destroyed.

This takes care of it in the "orphan" case. It does not yet do it in the
"terraform destroy" or "terraform plan -destroy" cases because we don't
have anywhere to record in the plan that we're actually destroying and so
the resource configurations should be ignored and _everything_ should be
cleaned. We'll let the state be not-quite-empty in that case for now,
since it doesn't really hurt; cleaning up orphans is the main case because
the state will live on afterwards and so leftover cruft will accumulate
over the course of many changes.
2018-10-16 19:14:11 -07:00
Martin Atkins a806bb7d8c core: OrphanResourceTransformer -> OrphanResourceInstanceTransformer
This transformer creates resource _instance_ nodes rather than resource
nodes, so this name is a clearer descriptor for what it does.
2018-10-16 19:14:11 -07:00
Martin Atkins 311cdbdcab core: Remove unused EvalDiffDestroyModule
This is no longer needed because the state structure self-prunes when
a module becomes empty.
2018-10-16 19:14:11 -07:00
Martin Atkins 7d0be84300 configload: Don't fail if one module is a child directory of another
Given a module foo and a module foo/bar, the previous code might
incorrectly treat "bar" as a file within "foo" rather than as a module
directory in its own right.
2018-10-16 19:14:11 -07:00
Martin Atkins ab1dc08e5c core: Fix TestContext2Apply_dataDependsOn
The value returned from ReadDataSourceFn must conform to the schema for
the data source.
2018-10-16 19:14:11 -07:00
Kristin Laemmert fbe959ae6e backend/local: fix panic in tests
update the function names in testDelegateBackend to match what was being
called in TestLocal_multiStateBackend (matching the test behavior in
master)
2018-10-16 19:14:11 -07:00
Martin Atkins 804da4be57 core: Fix TestContext2Apply_multiDepose_createBeforeDestroy
Since this one has a situation where there are two deposed objects for
the same instance at once, we can't rely on comparing state strings: they
are not deterministic when multiple deposed objects are present.

Instead, we do more surgical comparisons directly on the state model
objects, which is not quite as robust but still gets us the main stuff we
care about here, to be followed up by another checkStateString further
down for the final state.
2018-10-16 19:14:11 -07:00
Martin Atkins bad0f7fafd core: Fix TestContext2Apply_targetedWithTaintedInState
Tainted objects now also remember which provider they belong to (via the
resource state they are attached to) and so the stringified state output
here is slightly different.
2018-10-16 19:14:11 -07:00
Martin Atkins b565018bf1 core: Fix TestContext2Apply_provisionerInterpCount
This was relying on a no-longer-valid mechanism for accessing the "count"
value from a resource block. The original issue this test was written to
cover is not really such a sharp edge anymore, since the length is taken
from the state during apply rather than from configuration, but it's still
a good case to cover.
2018-10-16 19:14:11 -07:00
Martin Atkins f88b4fd1f4 core: Fix TestContext2Apply_issue7824
This test was incorrectly amended on the first pass to create a
configuration snapshot from the step zero configuration, rather than the
step one configuration that the save plan is built from.

Along with that, it needed various other minor updates to match with
details that have shifted:
- "id" and "type" attributes must be explicitly declared in schema
- template_file.parent has count = 1, which now causes it to get an index
  and be a list where before it did not.
2018-10-16 19:14:11 -07:00
Martin Atkins 49fa2b3f35 core: Always set ProviderAddr on EvalDiffDestroy
If we don't set it, we end up creating an invalid plan where the destroy
changes don't have a provider address set, which then later fails
decoding when round-tripped through a planfile.

This also includes some extra safety checks in EvalDiff and
EvalDiffDestroy so that we can catch this bug sooner in future.

This change is verified by
TestContext2Apply_plannedDestroyInterpolatedCount, which is now passing.
2018-10-16 19:14:11 -07:00
Martin Atkins 48dd8ddec5 core: test helper contextOptsForPlanViaFile to set default backend
A plan file without a backend set is not valid, but at the level we're
testing in this package we don't really care about backends so we'll just
set a default one if the caller doesn't set something more specific, and
then we'll just ignore it completely when reading back.
2018-10-16 19:14:11 -07:00
Martin Atkins 9179cdcbc6 plans/planfile: allow resource instances with no instance key
This happens for resources that don't have either "count" or "for_each"
set.
2018-10-16 19:14:11 -07:00
Martin Atkins 9e0f7c10d9 core: Skip ignore_changes handling for create actions
It doesn't make sense to ignore_changes when the prior value is null,
since we have to create something before we can ignore changes to it.

This change is verified by TestContext2Apply_ignoreChangesWildcard.
2018-10-16 19:14:11 -07:00
Martin Atkins 5c4545dac2 core: Fix TestContext2Apply_destroyProvisionerWithMultipleLocals
This test was relying on the feature of the old provisioner API that gave
provisioners full access to the instance state of what they were
provisioning.

We no longer do this, and so instead the ApplyFn must distingish the
instances using a value from the provisioner's own configuration.
2018-10-16 19:14:11 -07:00
Martin Atkins 2bab5bf502 core: Allow planned Update change to become NoOp during apply
This can happen if unknown values in the plan actually end up being
identical to the prior values once resolved. In that case, we'll just make
no change at all.

This is verified by TestContext2Apply_ignoreChangesWithDep.
2018-10-16 19:14:11 -07:00