Commit Graph

22052 Commits

Author SHA1 Message Date
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
Martin Atkins 1ed56f9903 core: NewInstanceInfo should take ResourceInstance, not Resource
On the initial pass here I reached a faulty conclusion about what from
the new world should shim into a NewInstanceInfo, based on a poor read
of existing code.

It actually _should've_ been based on an absolute instance after all,
as evidenced by the expected result of TestContext2Refresh_targetedCount.
Therefore the signature is changed here, and all of the callers (which,
in retrospect, were all holding a full instance address anyway!) are
updated to that new signature.
2018-10-16 18:49:20 -07:00
James Bardin 8d062fc577 update apply test fixtures 2018-10-16 18:49:20 -07:00
James Bardin 6ed1a81831 connect references to the resource type
References can't be connected directly to the instances, because the
resources are expanded when ReferenceTransformer is run. Lookup
references by the resource type.
2018-10-16 18:49:20 -07:00
Kristin Laemmert b979053361 general cleanup - addressing code review 2018-10-16 18:49:20 -07:00
Kristin Laemmert 498ffbf77b adding some test cases and tweaking implementation to address them 2018-10-16 18:49:20 -07:00
Kristin Laemmert 0cbcd75ebb port distinct and chunklist functions 2018-10-16 18:49:20 -07:00
Kristin Laemmert 8aac7587f7 port index and contains functions 2018-10-16 18:49:20 -07:00
Kristin Laemmert e697e7d733 port compact function 2018-10-16 18:49:20 -07:00
Kristin Laemmert 1901d5d184 port coalescelist function 2018-10-16 18:49:20 -07:00
Kristin Laemmert 04ac87747c base64decode: check that the decoded (not encoded) string is valid UTF-8 2018-10-16 18:49:20 -07:00
Martin Atkins 153021dd08 core: NewResourceConfigShimmed not to crash without schema
Although there isn't really a good reason why there should be no schema
in practice, it's better for us not to crash right now while we're still
updating all of the callers (mostly tests) to make schema available.
2018-10-16 18:49:20 -07:00
James Bardin c6b2799ee9 add "unknown" computed attribute
Having a compute value of "unknown" will trigger the testDifFn to always
insert a computed value to cause an unknown value suring apply
2018-10-16 18:49:20 -07:00
James Bardin edacd9ff4d add Provider schema to the contextFixture 2018-10-16 18:49:20 -07:00
James Bardin 672221e38e it is valid to have no provider config 2018-10-16 18:49:20 -07:00
Martin Atkins fe105bfc3f core: Fix TestContext2Input_submoduleTriggersInvalidCount
This test now needs to provide a mock schema so its fixture can assign
to the "foo" argument in null_data_source.
2018-10-16 18:49:20 -07:00
Martin Atkins 93ff9f4233 core: Fix TestContext2Input_submoduleTriggersInvalidCount
Its fixture was using a module variable called "count", and that name is
now reserved.
2018-10-16 18:49:20 -07:00
Martin Atkins e7cfbb9737 core: Fix TestContext2Input_hcl
This test now needs to provide a mock schema for its resource type so that
the two test arguments can be assigned.
2018-10-16 18:49:20 -07:00
Martin Atkins b6fe705985 core: fix buggy test TestContext2Input_providerMulti
This was trying to test gathering input from a default and an alias
provider configuration, but it was incorrectly setting the provider ref
on the instance that was supposed to belong to the alias. This was working
before because Terraform would gather input from the aliased provider
anyway, but now the invalid "alias" argument in the resource is producing
a validation error.

This doesn't actually make the test work again yet, because we still have
provider input disabled at this time, pending a forthcoming change to
how provider input is handled.
2018-10-16 18:49:20 -07:00
Martin Atkins f65f51c023 core: fix syntax of input-bad-var-default test fixture
This was incorrectly using block syntax to assign a value to the "default"
attribute.
2018-10-16 18:49:20 -07:00
Martin Atkins 6cf4835714 core: Fix output from context input tests
The previous test output made it hard to understand what was going on when
a test failed. We'll now produce more verbose output.
2018-10-16 18:49:20 -07:00
Martin Atkins 74873838e0 core: Fix TestContext2Input
This test was previously not setting InputModeVarUnset, causing us to
overwrite the "amis" map that _is_ already set. This worked before because
we used to treat the empty result as an empty map and then merge it with
the given value, but since we no longer do that merging behavior we were
ending up with an empty map after input.

Since the intent of this test is to see that the "foo" variable gets
populated by input, here we add InputModeVarUnset which then matches how
the input walk is triggered by the "real" codepath in the local backend.

This also includes some updates to make the test fixture v0.12-idiomatic
(applied after it was seen to work with the old fixture) and to properly
handle the "diags" return value from the various context methods.
2018-10-16 18:49:20 -07:00
Martin Atkins 1b55f09891 core: remove redundant rule lines in BasicGraphBuilder logs
The "------" is useful when we produce the multi-line graph description,
but just adds noise when we're showing "(no changes)".
2018-10-16 18:49:20 -07:00
Martin Atkins 7673a0d850 core: Include "id" attribute in schema for cbd depends datasource test
This attribute is referenced in order to include a computed value into
another resource, and so it must be present in the schema so that it can
be properly resolved.
2018-10-16 18:49:20 -07:00
Martin Atkins 588f4930f2 core: Rename typoed fixture for TestContext2Plan "CBD" test
The intent here was for this to be "cbd" for "create_before_destroy", but
it was typoed.
2018-10-16 18:49:20 -07:00
Martin Atkins dd6b171f62 core: Make provisioner schemas available to plan resource instance nodes
This requires making the "components" object available to the resource
node so it can be used during DynamicExpand. It also involved splitting
the provisioner schema attachment into a separate interface from
GraphNodeProvisionerConsumer so that it can now be handled within
AttachSchemaTransformer, along with all of the other schema attachment
steps.
2018-10-16 18:49:20 -07:00