Commit Graph

22227 Commits

Author SHA1 Message Date
Martin Atkins 3e55c4e72b Revert "destroy nodes can't be referenced directly"
This reverts commit e708d4ebe9b2f571183250ab79ac217ae9498fcc.
2018-10-16 18:49:20 -07:00
James Bardin 2f6787c9b2 core: update provisioner test fixtures
They need to conform to the test schema
2018-10-16 18:49:20 -07:00
James Bardin ec8df26a80 prefer the existing instance ID in tests
The old testApplyFn would overwrite ID with "foo" in all cases there
wasn't a diff, which made the test fixtures harder to reason about. If
there's an ID, keep it the same.
2018-10-16 18:49:20 -07:00
James Bardin 1350ed8e3a core: update fixture to match schema 2018-10-16 18:49:20 -07:00
James Bardin a5c3c454ab filter self references in NodeApplyableResourceIns
Don't save self-references in the state dependencies for a resource.
2018-10-16 18:49:20 -07:00
Martin Atkins ea73922780 core: DestroyEdgeTransformer must use instance rather than resource addrs
The initial destroyer map is constructed using DestroyAddr(), which
returns resource instance addresses, but we were then going on to _use_
that map with resource addresses, which means the keys can't match when
indexed instances are being destroyed.

Now we'll use resource instance addresses in all cases.

This also includes some additional logging that was helpful in debugging
this issue.
2018-10-16 18:49:20 -07:00
Martin Atkins aedbbc6207 core: Fix TestContext2Apply_outputOrphanModule
The adaptation of ModuleState.RemovedOutputs for the new config types
was incorrect because it took the absence of any output map as "nothing to
do", rather than "everything has been removed" as expected.

Now it treats a nil map like an empty map, detecting _all_ of the outputs
as having been removed if the output map is nil.
2018-10-16 18:49:20 -07:00
Martin Atkins 11bd07abb2 core: Have WritePlan be explicit that it's non-functional right now
This is temporarily broken until we implement the new plan file format,
since terraform.Plan is no longer serializable with gob. Rather than have
an error that seems like it needs immediate fixing, we'll be explicit
about it in the error message and focus our efforts on other test failures
for now, and return to implement the new file format later.
2018-10-16 18:49:20 -07:00
Martin Atkins 798adf3ce6 core: EvalSequence to handle EvalEarlyExitError
An earlier commit today reworked this to handle non-fatal errors, which
are returned "smuggled" as a special type of error to avoid changing the
EvalNode interface.

Unfortunately, that change then broke the _other_ special thing we smuggle
through the error return path: early exit.

Now we'll handle them both. This is not perfect because the early-exit
path causes us to discard any warnings we've already collected, but it's
more important that we bail early than retain warnings.
2018-10-16 18:49:20 -07:00
Martin Atkins b6d0abef1d core: Only treat instance ref as resource ref if instance nonexistent
We previously added a special case for dealing with references to
instances in the plan graph where there are only resource nodes. However,
this was too general a fix and so it upset the handling of graphs where
instances _are_ present.

Now we'll do that fallback behavior only if there is no instance node in
the graph already, so the exact matching behavior will be used in graphs
where the instances are present.
2018-10-16 18:49:20 -07:00
Martin Atkins 68c8d83620 core: In TransformDestroyEdge, insert variable nodes before providers
The provider transforms now depend on analyzing references in order to
properly create provider edges, and so we need to now insert all of the
nodes that can have references and attach schemas before we run
TransformProviders.

This was done for the main graph builders in a previous commit, but as
usual we missed this surprising hidden graph builder that lives inside
a graph transformer. 🙄
2018-10-16 18:49:20 -07:00
Martin Atkins bcadbb2ddb core: Update plan graph builder tests for new provider edges
Due to the need for schema in order to resolve references in expressions,
we now create additional provider dependency edges when a node refers to
an attribute from a resource.
2018-10-16 18:49:20 -07:00
James Bardin d9239e1f48 use provisioner attr defined in schema 2018-10-16 18:49:20 -07:00
James Bardin 41dde5fafc missing attribute now caught after apply 2018-10-16 18:49:20 -07:00
James Bardin 36aca84572 update ConnInfo test to work with new schema
We can't handle dynamic attributes in the tests any longer
2018-10-16 18:49:20 -07:00
James Bardin 903852b8e2 skip unset values in conection blocks
There's no valid, null value for the connection strings, so we can skip
over any unset values from the schema.
2018-10-16 18:49:20 -07:00
James Bardin 6a896c8748 fix the provisioner schema and update tests
The provisioenr schema needed to have `Optional: true` for all the
attributes. Also add the `type` attr and update the tests to match.
2018-10-16 18:49:20 -07:00
James Bardin e0e177374f don't hanlde "type" when parsing connection blocks
There's no provisioner schema yet, and we need to handle the type
dynamically during evaluation.
2018-10-16 18:49:20 -07:00
Martin Atkins 30d6a40329 core: Give import graph access to schema, variables, outputs, locals
During import we constrain provider configuration to allow only references
to variables, but since provider configurations in child modules might
refer to variables from the parent, we still need to include the module
variables, outputs and locals in the graph here and attach the provider
schemas.

In future a better check would be that the provider configuration doesn't
refer to anything that is currently unknown, but we'll save that for
another day.
2018-10-16 18:49:20 -07:00
Martin Atkins fc8030d2ae core: use testProvider for TestContextImport_moduleProvider
This test depends on the Refresh callback that comes built in to a
provider returned from testProvider.
2018-10-16 18:49:20 -07:00
Martin Atkins 9c0335e22e core: More TRACE logging for the "terraform import" walk 2018-10-16 18:49:20 -07:00
Martin Atkins 7f3d7313d8 core: Update error message for non-existing "terraform import"
The previous wording of this message was a little awkward, and a little
confusing due to the mention of it being a non-existing "resource", when
elsewhere in our output we use that noun to refer to the configuration
construct rather than the remote object.

Here we rework it as a diagnostic message, and while here also include an
extra note about a common problem of using an id from a different region
than the provider is configured for, to help the user realize what is
wrong in that case.
2018-10-16 18:49:20 -07:00
Martin Atkins 3de6a3db82 core: Fix TestContextImport_collision
The previous commit rewrote this incorrectly because the fatal message
made it seem like it was failing when an error occurs, but an error is
actually expected here.

Also includes a more detailed error message for this case, consistent with
our new diagnostics style.
2018-10-16 18:49:20 -07:00
Martin Atkins 6bc702f09d core: Update context import tests for diagnostics, rather than errors
ctx.Import now returns tfdiags.Diagnostics rather than "error", so these
tests need to now expect that API for proper behavior.

Several of these tests are still failing for other reasons. That will be
addressed in subsequent commits.
2018-10-16 18:49:20 -07:00
Kristin Laemmert 605e23db6b various code review fixes 2018-10-16 18:49:20 -07:00
Kristin Laemmert 6463dd90e9 functions: TransposeFunc, SliceFunc 2018-10-16 18:49:20 -07:00
Kristin Laemmert 30671d85ad functions: MergeFunc 2018-10-16 18:49:20 -07:00
Kristin Laemmert aecd7b2e62 functions: LookupFunc 2018-10-16 18:49:20 -07:00
Kristin Laemmert 4d8c398f8e functions: KeysFunc 2018-10-16 18:49:20 -07:00
Kristin Laemmert 21daabe680 functions: MapFunc 2018-10-16 18:49:20 -07:00
Kristin Laemmert da02e0da4d functions: ListFunc 2018-10-16 18:49:20 -07:00
Kristin Laemmert 529c2c3cc9 functions: FlattenFunc 2018-10-16 18:49:20 -07:00
Kristin Laemmert 4dd3ffc127 porting matchkeys 2018-10-16 18:49:20 -07:00
Martin Atkins 3ac6e575f1 core: EvalSequence must continue when only warnings are returned
To avoid a massively-disruptive change to how EvalNode works, we're now
"smuggling" warnings through the error return value for these, but this
depends on all of the Eval machinery correctly handling this special case
and continuing evaluation when only warnings are returned.

Previous changes missed EvalSequence as a place where execution halts on
error. Now it will accumulate diagnostics itself, aborting if any of
them are error diagnostics, and then wrap its own result up in an error
to be returned by the main Eval function, which already treats non-fatal
errors as a special case, though now produces an explicit log message
about that situation to make it easier to spot in trace logs.

This also includes a more detailed warning message for the warning about
provider input being disabled. While this warning should be removed before
we release anyway, having this additional detail is helpful in debugging
tests where it's being returned.
2018-10-16 18:49:20 -07:00
James Bardin 02a6657a71 don't check for targeted downstream from providers
Since outputs now rely on providers in order to ensure that a schema is
available for evaluation, we need to exclude providers from checking
TargetDownstream.
2018-10-16 18:49:20 -07:00
James Bardin fd4b427162 index provider schemas by type
A provider's schema is the same regardless of its address in the
config. Key them by type so that an evaluation referencing a provider
from an address not included in the graph can still find the schema.
2018-10-16 18:49:20 -07:00
Martin Atkins c8dfc944fe core: ProviderTransformer debug log to use abs addr always
This one address in the log output was relative, making the result
misleading.
2018-10-16 18:49:20 -07:00
Martin Atkins 05bf08b2ec core: Remove context apply test for map variable merging
We no longer have this merge behavior, because it is inconsistent with how
variables behave in all other contexts and similar behavior can now be
achieved by merging the user's input with a predefined map in a local
value expression.
2018-10-16 18:49:20 -07:00
Martin Atkins 7dc3c51a86 core: Only create stub provider if real provider is not present
Previously we'd create the stub provider in any case where we didn't need
a configured provider, but we also need to skip creating it if there's
already a provider node present, or else we can end up with multiple
stub nodes in the graph.
2018-10-16 18:49:20 -07:00
Martin Atkins b144497041 core: Attach schemas before dealing with provider edges
Since ProviderTransformer now needs the schema in order to infer indirect
references to providers, we must run AttachSchemaTransformer before the
provider transformers in order to calculate the correct ordering of
operations.
2018-10-16 18:49:20 -07:00
Martin Atkins a2728759cd core: Apply inheritance logic to both direct and referenced providers
The provider schema cache is keyed by provider configuration address
rather than provider type, so we need to do the same inheritance logic
to resolve providers needed because of reference as we do for providers
needed for direct use.

This allows resources that override "provider" or resources in child
modules that have their own provider configurations to be associated
with the provider config they will eventually get schema from, rather
than (as before) always the default configuration for the provider in
the root module.

Eventually it'd probably be better to switch to using a provider cache
that is keyed by provider _type_ rather than provider config, but since
it's currently fetched by visiting the individual provider graph nodes
we currently visit each provider configuration separately and fetch a
schema for each.
2018-10-16 18:49:20 -07:00
James Bardin 4d2da4d733 connect non-resources to providers they reference
Any non-resource (outputs, variables, locals) that references a resource
type must also be connected to that resources provider. This is required
during apply, because the graph built from the diff may not include the
referenced resources because they are being evaluated from the state.

If the provider isn't present already, add a NodeEvalableProvider to
fetch the provider schema.

The provider transformers now need to happen after the outputs, locals,
and variables are transformed.
2018-10-16 18:49:20 -07:00
Martin Atkins 1f859ba8d4 configs: Handle object constructor keys when shimming traversals
This is important in particular for shimming the "providers" map in module
blocks:

    providers = {
        "aws" = "aws.foo"
    }

We call this shim for both the key and the value here, and the value would
previously have worked. However, the key is wrapped up by the parser in
an ObjectConsKeyExpr container, which deals with the fact that in normal
use an object constructor key that is just a bare identifier is actually
interpreted as a string. We don't care about that interpretation for our
shimming purposes, and so we can just unwrap it here.
2018-10-16 18:49:20 -07:00
Martin Atkins 687830a5d5 core: Mock schema for TestContext2Apply_multiProviderDestroy
This test seems to have been buggy before our current work, with the test
fixture containing a reference to a resource that doesn't exist.

This both fixes the fixture and adds a mock schema for it, though this
just revealed another error which isn't fixed here, where the a_ids value
seems to come through as unknown after apply. That will be fixed in a
subsequent commit.
2018-10-16 18:49:20 -07:00
Martin Atkins cdb32390b9 core: Add schema mocks to more of the context apply tests 2018-10-16 18:49:20 -07:00
Martin Atkins 5cf06e86c6 core: Remove TestContext2Apply_provisionerMultiSelfRefSingle
We no longer support using "self.count" in a provisioner to access the
resolved count meta-argument value of the associated resource.

This was only possible before because of a special exception in how
Terraform resolved variables, and in new HCL that exception isn't possible
because resource instances are real values in the scope and we don't want
to add this implied "count" attribute to all of them.

"count" is a property of the resource config rather than of the resource
instances, and since "self" is a resource _instance_ it doesn't make sense
to expose it there.

There is no replacement for this feature. In the rare case where it is
needed, the user must factor the count out into a named local value and
refer to that both in the count meta-argument and in the provisioner.
2018-10-16 18:49:20 -07:00
Martin Atkins 1caffba0e6 core: update various context apply tests for schema/fixtures
Most of these changes are just adding schema to describe the expectations
of the existing test fixtures. However, some of them require the fixtures
themselves to be changed due to changing assumptions in the language.
2018-10-16 18:49:20 -07:00
Martin Atkins 8774c857f6 core: "computed ref type mismatch" test is now a plan test
This was previously an apply-time failure due to our inability to
type-check unknowns in 0.11, but we now retain type information for
unknown values and so this check now fails during plan instead.
2018-10-16 18:49:20 -07:00
Martin Atkins 02932b5a50 core: Schema for TestContext2Apply_outputDiffVars
The fixtures for this test assume some atypical arguments to the resources
and also need a provisioner schema.

This doesn't actually fix the test, but by fixing the schema/fixture this
exposes a problem that seems to exist in the main code, which will be
fixed in a subsequent commit.
2018-10-16 18:49:20 -07:00
Martin Atkins 4314c9e985 core: Update context refresh test output to be more useful 2018-10-16 18:49:20 -07:00