Commit Graph

2539 Commits

Author SHA1 Message Date
Martin Atkins 2fd016738a core: NodePlanDeposedResourceInstanceObject populate EvalReadStateDeposed
The Provider field is required and will cause a panic if not populated.
2018-11-30 11:22:39 -08:00
Martin Atkins 444cb96b48 core: Reject provider schemas with version < 0
There's no reason for a negative version, so by blocking it now we'll
ensure that none creep in.

The more practical short-term motivation for this is that we're still
using uint64 for these internally in some cases and so this restriction
ensures that we won't run into rough edges when converting from int64 to
uint64 at those boundaries until we later fix everything to use int64
consistently.
2018-11-30 11:22:39 -08:00
Martin Atkins 30b7040e95 core: Validate module references
Previously we were making an invalid assumption in evaluating module call
references (like module.foo) that the module must exist, which is
incorrect for that particular case because it's a reference to a child
module, not to an object within the current module.

However, now that we have the mechanism for static validation of
references, we'll deal with this one there so it can be caught sooner.
That then makes the original assumption valid, though for a different
reason.

This is verified by two new context tests for validation:
  - TestContext2Validate_invalidModuleRef
  - TestContext2Validate_invalidModuleOutputRef
2018-11-28 13:19:57 -08:00
Martin Atkins 168d84b3c4 core: Make resource type schema versions visible to callers
Previously we were fetching these from the provider but then immediately
discarding the version numbers because the schema API had nowhere to put
them.

To avoid a late-breaking change to the internal structure of
terraform.ProviderSchema (which is constructed directly all over the
tests) we're retaining the resource type schemas in a new map alongside
the existing one with the same keys, rather than just switching to
using the providers.Schema struct directly there.

The methods that return resource type schemas now return two arguments,
intentionally creating a little API friction here so each new caller can
be reminded to think about whether they need to do something with the
schema version, though it can be ignored by many callers.

Since this was a breaking change to the Schemas API anyway, this also
fixes another API wart where there was a separate method for fetching
managed vs. data resource types and thus every caller ended up having a
switch statement on "mode". Now we just accept mode as an argument and
do the switch statement within the single SchemaForResourceType method.
2018-11-27 15:53:54 -08:00
Martin Atkins 3b49028b77 core: Static-validate resource references against schemas
In the initial move to HCL2 we started relying only on full expression
evaluation to catch attribute errors, but that's not sufficient for
resource attributes in practice because during validation we can't know
yet whether a resource reference evaluates to a single object or to a
list of objects (if count is set).

To address this, here we reinstate some static validation of resource
references by analyzing directly the reference objects, disregarding any
instance index if present, and produce errors if the remaining subsequent
traversal steps do not correspond to items within the resource type
schema.

This also allows us to produce some more specialized error messages for
certain situations. In particular, we can recognize a reference like
aws_instance.foo.count, which in 0.11 and prior was a weird special case
for determining the count value of a resource block, and offer a helpful
error showing the new length(aws_instance.foo) usage pattern.

This eventually delegates to the static traversal validation logic that
was added to the configschema package in a previous commit, which also
includes some specialized error messages that distinguish between
attributes and block types in the schema so that the errors relate more
directly to constructs the user can see in the configuration.

In future we could potentially move more of the checks from the dynamic
schema construction step to the static validation step, but resources
are the reference type that most needs this immediately due to the
ambiguity caused by the instance indexing syntax. We can safely refactor
other reference types to be statically validated in later releases.

This is verified by two pre-existing context validate tests which we
temporarily disabled during earlier work (now re-enabled) and also by a
new validate test aimed specifically at the special case for the "count"
attribute.
2018-11-26 08:25:03 -08:00
Martin Atkins 1226e77999 core: Remove GraphSemanticChecker, etc
These overly-general interfaces are no longer used anywhere, and their
presence in the important-sounding semantics.go file was a distracting
red herring.

We'd previously replaced the one checker in here with a simple helper
function for checking input variables, and that's arguably more at home
with all of the other InputValue functionality in variables.go, and that
allows us to remove semantics.go (and its associated test file) altogether
and make room for some forthcoming new files for static validation.
2018-11-26 08:25:03 -08:00
James Bardin f375691819 add missing key-value from test 2018-11-19 18:58:29 -05:00
James Bardin 0b7be2d0e3 fixes for the remaining tests
It's possible that a computed collection could be handled by the
attribute name, rather than the index count value.

Use a new testDiffFn for some tests, which don't work with the old
function that can't determine `computed` without the schema.
2018-11-19 18:56:50 -05:00
James Bardin e4270993be remove unused value 2018-11-16 15:28:30 -05:00
James Bardin db968733da re-count the flatmapped containers
When applying a legacy diff, recount the flatmapped containers. We can't
trust helper/schema to return the correct value, if it even exists.
2018-11-16 15:26:16 -05:00
James Bardin 3716db3865
Merge pull request #19384 from hashicorp/jbardin/nested-sets
New Attribute and Diff handling in shims
2018-11-16 11:55:41 -05:00
James Bardin 89b2c6f21e comment fixes 2018-11-16 11:24:14 -05:00
James Bardin 16f28f7348 new mechanism for applying a diff to a value
This attempts to apply the diff in order to get consistent output from
the shimmed values.
2018-11-16 09:59:03 -05:00
James Bardin b872491baa incremental progress towards applying diffs 2018-11-16 09:58:42 -05:00
Sander van Harmelen 634430ebb2 Fix wildcard dependencies when upgrading states
Fixes #19347
2018-11-15 13:17:15 +01:00
Martin Atkins fcf3f643ce command: Fix TestPlan_shutdown
Comments here indicate that this was erroneously returning an error but
we accepted it anyway to get the tests passing again after other work.
The tests over in the "terraform" package agree that cancelling should be
a successful outcome rather than an error.

I think that cancelling _should_ actually be an error, since Terraform did
not complete the operation it set out to complete, but that's a change
we'd need to make cautiously since automation wrapper scripts may be
depending on the success-on-cancel behavior.

Therefore this just fixes the command package test to agree with the
Terraform package tests and adds some FIXME notes to capture the potential
that we might want to update this later.
2018-11-08 08:57:11 -08:00
Martin Atkins 421462cb64
Merge #19237: Handle unknown values properly in module outputs
Since the state models can't preserve unknown values, we need to rely on the plan to persist these until the effective configuration can be fully resolved during the apply phase.
2018-11-05 16:30:39 -08:00
Martin Atkins ab62b330c1 core: Allow planned output changes to be updated during apply
If plan and apply are both run against the same context then we still have
the planned output values in memory while we're doing the apply walk, so
we need to make sure to update them along with the state as we learn the
final known values of each output.

There were actually two different bugs here:

- We weren't removing any existing planned change for an output when
  setting a new one. In retrospect a map would've been a better data
  structure for the output changes, rather than a slice to mimic what we
  do for resource instance objects, but for now we'll leave the structures
  alone and clean up as needed. (The set of outputs should be small for
  any reasonable configuration, so the main impact of this is some ugly
  code in RemoveOutputChange.)

- RemoveOutputChange itself had a bug where it was iterating over the
  resource changes rather than the output changes. This didn't matter
  before because we weren't actually using that function, but now we are.

This fix is confirmed by restoring various existing context apply tests
back to passing again.
2018-11-05 16:02:45 -08:00
Sander van Harmelen b62a22ab62 Add a VariableSourceType for names .tfvars files
This new source type should be used for variables loaded from .tfvars files that were explicitly passed as command line arguments (e.g. -var-file=foo.tfvars)
2018-11-05 19:29:34 +01:00
Martin Atkins 21577a5f15 core: Whole-module evaluation must consider planned output values
Just as when we resolve single output values we must check to see if there
is a planned new value for an output before using the value in state,
because the planned new value might contain unknowns that can't be
represented directly in the state (and would thus be incorrectly returned
as null).
2018-11-01 17:41:35 -07:00
Martin Atkins d73b2d778f core: TestContext2Plan_requiredModuleOutput to use t.Run
This allows us to see the results of the tests for all resources even if
one of them fails.
2018-11-01 17:32:30 -07:00
James Bardin 7e4f09c787 don't apply unchanged attributes from legacy diffs
If a legacy diff has equal old and new values, don't apply the diff.
These would show up in sets, because of the overall change in set key.
2018-11-01 16:19:17 -04:00
James Bardin 21064771ea add failing test for required output value
The required value from an output is nil when it should be unknown
2018-10-31 16:41:36 -04:00
James Bardin c9e7346bfd create a new proposed value when replacing
When replacing an instance, calculate a new proposed value from the null
state and the config. This ensures that all unknown values are properly
set.
2018-10-31 13:49:04 -04:00
James Bardin 4635ebc61a create a new proposed value when replacing
When replacing an instance, calculate a new proposed value from the null
state and the config. This ensures that all unknown values are properly
set.
2018-10-31 13:48:13 -04:00
James Bardin 6dad121e70 insert resource timeouts into the config schema
Resource timeouts were a separate config block, but did not exist in the
resource schema. Insert any defined timeouts when generating the
configshema.Block so that the fields can be accepted and validated by
core.
2018-10-30 13:14:08 -04:00
Sander van Harmelen 292ec47e66
Merge pull request #19197 from hashicorp/f-state-mv
command/state: update and fix the state mv command
2018-10-27 15:03:42 +02:00
Sander van Harmelen 7ec3f96e3a command/state: update and fix the state mv command 2018-10-27 15:01:07 +02:00
James Bardin a1915964a2 some basic tests for NewResourceConfigShimmed
This is used in the helper package for the provider shims.
2018-10-26 15:01:30 -04:00
James Bardin 6732b6713b missed IsNull check in config shim 2018-10-26 14:02:09 -04:00
Sander van Harmelen af1a471a05 command/state: update and fix the state list command 2018-10-19 16:31:12 +02:00
James Bardin e08a388d3c check IsKnown on values that may panic 2018-10-18 19:21:32 -04:00
James Bardin 155f899249 update terraform with PrepareProviderConfig
Change the call sites and update the MockProvider. No core behavior is
changed yet.
2018-10-18 08:48:55 -04:00
Martin Atkins c06f24b323 core: Use hcl2shimConfigValueFromHCL2Block when shimming ResourceConfig
This ensures more HCL1/HIL-like behaviors when dealing with nested blocks
that are not set in the configuration, which is important for
compatibility with helper/schema's validation logic.
2018-10-16 19:14:54 -07:00
James Bardin 3b6deef296 reset plan changes every call to Plan.
Tests often call Plan multiple times on the same context to verify there
are no changes, so we need to make sure changes don't accumulate.
2018-10-16 19:14:11 -07:00
James Bardin b3fed27dbf export MustShimLegacyState for resource tests
We also need to convert legacy states for helper resource tests.
2018-10-16 19:14:11 -07:00
Martin Atkins c5940f2438 backend/local: Increase log verbosity for backend context construction
There are several steps here and a number of them can include reaching out
to remote servers or executing local processes, so it's helpful to have
some trace logs to better narrow down causes of errors and hangs during
this step.
2018-10-16 19:14:11 -07:00
James Bardin f54113ec08 remove unneeded legacy test
The legacy test wasn't really testing anything useful, just the plan
behavior with no diff in a module returned a module with no diff.
There's no reason to convert this to the new plans, since there's no
legacy behavior to match.
2018-10-16 19:14:11 -07:00
James Bardin 7e0fc55b80 return proper PlanResourceChange in mock 2018-10-16 19:14:11 -07:00
James Bardin 795161f615 update to start a new process for each plugin
Modify the plugin factories to create a new plugin process for each
individual plugin.
2018-10-16 19:14:11 -07:00
Martin Atkins dd8b3ab722 core: Reinstate state-based tracking of data resource dependencies
This was inadvertently lost in the consoliation of EvalReadDataDiff and
EvalReadDataApply into a single EvalReadData.
2018-10-16 19:14:11 -07:00
Martin Atkins 206a4b5de9 core: Fix TestContext2Plan_dataResourceBecomesComputed
Data resources get processed during refresh, so it doesn't make sense to
have a data resource test that doesn't run the refresh walk.
2018-10-16 19:14:11 -07:00
Martin Atkins f51d8a0a9f core: Fix TestContext2Apply_dataBasic
In the reorganization of the data source read code we missed the fact that
the plan phase must _always_ generate a read data diff, never directly
read, because the state generated during plan is throwaway.

This only matters in the -refresh=false case, since normally refresh has
already taken care of this, but that is still an important case, covered
by the TestContext2Apply_dataBasic test.
2018-10-16 19:14:11 -07:00
Martin Atkins 8ada1bd712 core: Don't panic in TestContext2Apply_dataDependsOn if data source fails 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
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 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 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 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 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 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
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 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
Martin Atkins 1885f107a5 core: Fix TestContext2Apply_destroyDeeplyNestedModule
The new state.String() has slightly different output for an empty state,
so we'll test that it's empty in a more direct way.
2018-10-16 19:14:11 -07:00
Martin Atkins d1f95ea6a7 core: Fix TestContext2Apply_Provisioner_compute
Due to a quirk in how testDiffFn constructs its diff, compute doesn't
actually get included in the final result anymore under the new shims.
This result is still correct, nonetheless.
2018-10-16 19:14:11 -07:00
Martin Atkins 1cfaf52406 core: Fix TestContext2Apply_outputOrphanModule
The new state.String is not quite identical to the old, so we'll assert
an empty state in a more direct way.
2018-10-16 19:14:11 -07:00
Martin Atkins b6e9a5e5a4 core: Fix TestContext2Apply_outputOrphanModule
This is caused just be a slight difference in the new implementation of
stringifying state.
2018-10-16 19:14:11 -07:00
Martin Atkins 90faaf9f80 core: Fix TestContext2Apply_countTainted
The prior behavior being asserted by this test was incorrect, since the
configuration calls for there to be two instances of the resource at the
end.

We also now assert on the generated plan since it's important to verify
that we are indeed planning to replace the zeroth instance but not the
first instance (which doesn't yet exist).
2018-10-16 19:14:11 -07:00
Martin Atkins ca6efc6ba9 core: Fix TestContext2Apply_countDecreaseToOneCorrupted
We now include attribute changes in destroy diffs, so the expected output
of this test includes these changes.

Also includes a fix to legacyDiffComparisonString to actually sort the
attribute changes by name in the rendered diff.
2018-10-16 19:14:11 -07:00
Martin Atkins 74ffebe8ea core: Fix TestContext2Apply_compute
The testDiffFn doesn't include "compute" in the diff it produces and so
it no longer appears in the shimmed output.

This is just a quirk of this weird mock implementation; real providers
always copy all of the values from thec config into the diff before adding
in any other changes.
2018-10-16 19:14:11 -07:00
Martin Atkins e6f8b51111 core: Fix TestContext2Apply_cancelProvisioner
This test now requires a provisioner schema for correct operation.
2018-10-16 19:14:11 -07:00
Martin Atkins 032f908f4a core: MockProvider and MockProvisioner can't lock in Stop
The only reasonable usage of these methods is for them to run concurrently
with other methods, so we mustn't hold a lock to do this work. For tests
that deal with stopping, it's the test's own responsibility to deal with
any concurrency issues that arise from their StopFns running concurrently
with other mock functions.
2018-10-16 19:14:11 -07:00
Martin Atkins 21071fb679 core: Additional logging for Context.Stop
Since stopping is a rather complex mechanism that relies on correct
handling of concurrency, it's handy to have these logs here to debug when
things don't happen in quite the right order.
2018-10-16 19:14:11 -07:00
James Bardin 847c8d6244 CBD transformer test update
Comment out an out of date CBD test. The test no longer works due to
the CBD status being checked during plan, but the test case may still
have some value which we can review later.

update the text in the CBD transformer to reflect the
s/ancestor/descendent/ change.
2018-10-16 19:14:11 -07:00
Kristin Laemmert fe67d9dbf8 terraform.Schemas: export struct fields
There does not appear to be any real reason that these Schemas fields are
not exported, and exporting them makes it possible to directly construct
Schemas for tests without pulling in an entire context.
2018-10-16 19:14:11 -07:00
James Bardin 844f157183 finish graph builder test updates 2018-10-16 19:14:11 -07:00
Martin Atkins 9dcc841f31 core: Fix TestContext2Apply_cancel
Now that we populate a resource-level state pre-emptively for a resource,
before we apply the instances of that resource, it is no longer true that
this produces only one resource state, but the test below (comparing the
string version of the state) already captures the expected behavior and
so this additional check was redundant anyway.
2018-10-16 19:14:11 -07:00
Martin Atkins 185d9cf7fe core: Fix TestContext2Apply_destroyCrossProviders
This test needed a schema that better reflects the expectations of its
configuration fixture.
2018-10-16 19:14:11 -07:00
Martin Atkins 6491c6d997 core: Fix TestContext2Apply_dataBasic
The mock provider must be configured to return an object of a type that
conforms to the schema for the test_data_source resource type.
2018-10-16 19:14:11 -07:00
Martin Atkins 058df3563f core: fix TestContext2Apply_createBeforeDestroy_hook
This test was incorrectly updated to the new hook API; it should've been
recording the individual resource state values passed to the hook, not
the original state as a whole (which is not yet updated at the point
when the hook is called).
2018-10-16 19:14:11 -07:00
James Bardin f1657bb3e3 update some graph builder tests
Reduce the graphs, as they are too ungainly to compare without
reduction. We also depend on reduction in all use cases, so we should be
testing the graph as we use it anyway.
2018-10-16 19:14:11 -07:00
James Bardin 1f374dc446 fix refresh test
provider schema must be defined before initializing the context
2018-10-16 19:14:11 -07:00
James Bardin e3f64af8ac Temporarily move 2 validate tests to plan
We can't catch invalid attributes in validate at the moment, because the
lack of count information causes the references to return unknown. Make
sure they fail in plan, and mark the validate tests to fix later.
2018-10-16 19:14:11 -07:00
Martin Atkins a43b7df282 core: Handle forced-create_before_destroy during the plan walk
Previously we used a single plan action "Replace" to represent both the
destroy-before-create and the create-before-destroy variants of replacing.
However, this forces the apply graph builder to jump through a lot of
hoops to figure out which nodes need it forced on and rebuild parts of
the graph to represent that.

If we instead decide between these two cases at plan time, the actual
determination of it is more straightforward because each resource is
represented by only one node in the plan graph, and then we can ensure
we put the right nodes in the graph during DiffTransformer and thus avoid
the logic for dealing with deposed instances being spread across various
different transformers and node types.

As a nice side-effect, this also allows us to show the difference between
destroy-then-create and create-then-destroy in the rendered diff in the
CLI, although this change doesn't fully implement that yet.
2018-10-16 19:14:11 -07:00
James Bardin ebe3754fe6 validate test updates
Remove a test that is no longer needed, since provider must be
explicitly defined for orphaned modules, and is covered in other context
tests.

Udpate a test fixture to better represent the origianl missing map
issue, since the ability to detect nil now made the old test invalid.
2018-10-16 19:14:11 -07:00