Commit Graph

22521 Commits

Author SHA1 Message Date
Martin Atkins 78f1d1d1c0 state/remote: Don't hang in PersistState
We were calling from PersistState into RefreshState, but RefreshState is
protected by the same lock as PersistState and so the call would deadlock.

Instead, we introduce a new entry point refreshState which can be used
when already holding the lock.
2018-10-16 19:14:11 -07:00
Martin Atkins 331cb07a05 states/statefile: Tolerate nil state in statefile.New
For historical reasons sometimes we have nil state in situations where
we'd still like to persist state snapshots to a store. To make life easier
for those callers, we'll substitute an empty state if we are given a nil
one, thus allowing us to still generate a valid serialization that will
load back in as an empty state.
2018-10-16 19:14:11 -07:00
Radek Simko d93b462e9c helper/plugin: don't panic in ReadDataSource State 2018-10-16 19:14:11 -07:00
Martin Atkins 67a8757b69 core: Properly handle deferral (or non-deferral) of data resources
(this is a WIP prototype)
2018-10-16 19:14:11 -07:00
Radek Simko 84d4e78481 core: Add test to show that data resource reads are not functioning properly 2018-10-16 19:14:11 -07:00
James Bardin 6f49a5d124 update go-plugin and hclog 2018-10-16 19:14:11 -07:00
Martin Atkins 9f1098ac5f builtin/providers/terraform: Fix tests
Various things drifted since these tests were originally written. This
catches them up to the latest implementations of state decoding,
upgrading, etc.
2018-10-16 19:14:11 -07:00
Martin Atkins 8c67fd52b0 builtin/providers: Don't panic if requested remote state isn't present 2018-10-16 19:14:11 -07:00
Martin Atkins 88551181d5 plugin: Fix tests
An earlier change made the tests not compile here. We now need to use the
legacyPluginMap function, since pluginMap has now been replaced with
helpers to produce new-style plugin _sets_.
2018-10-16 19:14:11 -07:00
Martin Atkins 1908aff476 helper/resource: Fix duplicated function testConfig
An earlier change introduced a new function testConfig to the main code
for this package, which conflicted with a function of the same name in
the test code.

Here we rename the function from the test code, allowing for the more
generally-named testConfig to be the one in the main code.
2018-10-16 19:14:11 -07:00
Martin Atkins d11dd20bf3 builtin/providers/test: use new API for root module address
terraform.RootModulePath is no longer present, but
addrs.RootModuleInstance is equivalent to it.
2018-10-16 19:14:11 -07:00
Martin Atkins 961056c08d configs/configupgrade: Use mock provider instead of test provider
The test provider comes with a lot of baggage since it's designed to be
used as a plugin, so instead we'll just use the mock provider
implementation directly, and so we can (in a later commit) configure it
appropriately for what our tests need here.
2018-10-16 19:14:11 -07:00
Martin Atkins 477ea0d360 state/remote: Make tests compile and run to completion
One of the tests was hanging, so for now it's stubbed out until we can
get to the bottom of the hang on a subsequent pass.
2018-10-16 19:14:11 -07:00
Martin Atkins 4bdaffb586 state: Remove tests for obsolete components
Most of the functionality in this package has been obsoleted by equivalent
symbols in states/statemgr. We're keeping this package around for the
moment mainly just to house the type aliases in state.go.

The tests in here no longer work because they are written against the old
APIs. We will eventually remove the components these are testing too, but
we're keeping them around for the moment so that we don't break the build
for some leftover callers that are still depending on these.
2018-10-16 19:14:11 -07:00
Martin Atkins aaf405b662 backend/remote-state: Get all the backend tests building again
The state manager refactoring in an earlier commit was reflected in the
implementations of these backends, but not in their tests. This gets us
back to a state where the backend tests will compile, and gets _most_ of
them passing again, with a few exceptions that will be addressed in a
subsequent commit.
2018-10-16 19:14:11 -07:00
Martin Atkins 058a1d81b0 command/format: Remove tests for plan.go
plan.go as a whole will be removed before too long, so there's no point
in us updating all of these tests to use the new plan types.
2018-10-16 19:14:11 -07:00
Martin Atkins 3b8d46418f command/format: print correctly nested blocks with labels 2018-10-16 19:14:11 -07:00
Martin Atkins b0016e9cf6 command: Allow tests to run to completion without panics or hangs
There are still 160 test failures as of this commit, but at least the test
program can run to completion and list out all the failures.
2018-10-16 19:14:11 -07:00
Martin Atkins d446d32d96 command: Fix TestApply for new mock provider interface
It must now provide a basic implementation of plan and apply for its
mock provider, which in this case can just pass through the proposed value
generated by core because there are no computed attributes in this schema.
2018-10-16 19:14:11 -07:00
Martin Atkins 5021e0e098 command: Fix TestApply_destroyTargeted for new provider and state types 2018-10-16 19:14:11 -07:00
Martin Atkins ec2e6cb06f terraform: Prune resource husks at the end of "terraform destroy"
When we're being asked to destroy everything, we ideally want to end up
with a totally empty state. Normally we will conservatively keep around
the "husks" of resources (what's left after all of the instances have been
destroyed) unless they are configured without count or for_each, but in
this special case we'll prune those out.

The implication of this is that in "weird" expression contexts that happen
before the next "terraform plan", such as evaluation in
"terraform console" or expressions in data resources and provider blocks
that get evaluated during the refresh walk, we will see these results
as unknown rather than as empty lists of objects. We accept that weirdness
for now because in a future release we are likely to remove "refresh" as
a separate walk anyway, doing all of that work during the plan walk where
we can ensure that these values are properly re-populated before trying
to use them.
2018-10-16 19:14:11 -07:00
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