Commit Graph

22266 Commits

Author SHA1 Message Date
Kristin Laemmert 755b1e2497 implement pathexpand 2018-10-16 18:48:28 -07:00
Kristin Laemmert 2a2ffb6ef4 implement dirname function 2018-10-16 18:48:28 -07:00
Martin Atkins fa11fb70f6 govendor fetch github.com/hashicorp/hcl2/...
This includes fixes to hcldec that should make our configschema.Block
implementation behave better with Optional+Computed attributes.
2018-10-16 18:48:28 -07:00
Kristin Laemmert 8c1f0842b0 implement basename function 2018-10-16 18:48:28 -07:00
Martin Atkins 2b3b6c2407 core: TestContext2Plan_countComputedModule expectedErr
The phrasing of this message changed as part of updating it to use HCL
diagnostics rather than just a string.
2018-10-16 18:48:28 -07:00
James Bardin e6478599c6 strip unknown values from the resource config
Computed values are now all added to the config value as unknowns. Strip
these out to match the legacy expatiations.
2018-10-16 18:48:28 -07:00
Martin Atkins d6d655f21d core: Context plan tests expect a new error message for prevent_destroy
This error message has been revised as part of changing it to use
diagnostics instead of an error string directly.
2018-10-16 18:48:28 -07:00
Martin Atkins 5a77045a61 core: Move invalid output context tests to "validate"
This problem should now be caught at validate time rather than plan time,
because we can use the schema to detect the problem before the resource
has been resolved.
2018-10-16 18:48:28 -07:00
Martin Atkins 824986b698 core: use correct provider config address when eval pending resources
The evaluate data source was using a guessed provider configuration
address from configuration in this case, but that isn't necessarily
correct since the resource might actually be associated with a config
inherited from a parent module.

We still need to retain that fallback to config because we are sometimes
asked to evaluate when state is incomplete (like in "terraform console"),
but if possible we'll take the stored provider address from the state
and use that, even if the resource is otherwise "pending".
2018-10-16 18:48:28 -07:00
James Bardin cae5c2feaa update apply tests 2018-10-16 18:48:28 -07:00
James Bardin 492a3b09fa deposed nodes need the resolved provider too
The provider is looked up by the ResolvedProvider
2018-10-16 18:48:28 -07:00
James Bardin f8b77030db destroy nodes can't be referenced directly
Destroy nodes were being referenced by their regular paths, which was
causing cycles in the graphs. Destroy nodes can't be referenced directly
in any way, so override the inherited method for a referenceable address.
2018-10-16 18:48:28 -07:00
James Bardin 7137d85522 ignore id when creating diffs
The id field is always computed, and never directly related to a diff.
Since that field is being converted to a regular schema attribute, we
need to handle the behavior in the mocks too.
2018-10-16 18:48:28 -07:00
Martin Atkins 129f5fe74d lang/funcs: port some of Terraform's built-in functions
These implementations are adaptations of the existing implementations in
config/interpolate_funcs.go, updated to work with the cty API.

The set of functions chosen here was motivated mainly by what Terraform's
existing context tests depend on, so we can get the contexts tests back
into good shape before fleshing out the rest of these functions.
2018-10-16 18:48:28 -07:00
Martin Atkins e528fe50e9 core: Misc. updates to the "plan" context tests
Mostly this is about updating ctx.Plan callers to expect diags instead of
err, but also includes a few light updates to test fixtures, and a fix to
testModuleInline.
2018-10-16 18:48:28 -07:00
James Bardin 6bf70427dd lock the provisioner mutex in ProvisionerSchema 2018-10-16 18:48:28 -07:00
James Bardin cdaeed4f26 a provisioner may not always have a connection 2018-10-16 18:48:28 -07:00
James Bardin 07042a95fa fixing context apply tests 2018-10-16 18:48:28 -07:00
James Bardin 3bd2293152 compare module by normalized path
The onld logic for locating comparing module paths no longer worked, and
we can simplify the comparison by using the addrs.ModuleInstance string.
2018-10-16 18:48:28 -07:00
Martin Atkins ea727d9918 core: Add mock schemas to the refresh context tests
There are still some other issues with some of these tests right now, but
all the ones that need to have schema should now have it.

It seems that there is a bug with the evaluation of child module input
variables where they can't find their schema even when a mock is provided.
Will attack this in a subsequent commit.
2018-10-16 18:48:28 -07:00
Martin Atkins 8b6ef7c8d3 core: EvalWriteOutput handle dynamic pseudo-type
This should actually have been caught by !val.IsWhollyKnown, since
DynamicVal is always unknown, but something isn't working quite right here
and so for now we'll redundantly check also if it's of the dynamic
pseudo-type, and then revisit cty later to see if there's a real bug
hiding down there.
2018-10-16 18:48:28 -07:00
Martin Atkins 5281afcc07 core: Actually read provider schema for data resources
We were passing the pointer into EvalReadDataDiff here, but because it was
not also passed to EvalGetProvider it was just always nil.
2018-10-16 18:48:28 -07:00
Martin Atkins 01a19e18ea core: Add ProviderAddr to all import context tests
The recent changes for v0.12 have moved the responsibilities around here
so that it's the caller's responsibility to specify the provider address
in all cases, with the real UI (in the "command" package) providing a
suitable default if nothing is specified.

Therefore the tests at _this_ level must all include an explicit provider
address, since these tests are acting as if they _are_ the UI code.
2018-10-16 18:48:28 -07:00
Martin Atkins 2c1ef35965 core: skip resource validation when count is unknown
The approach here is a little hacky, since this edge case applies only to
validate and all of the other evaluateResourceCountExpression callers
don't care about it: we overload the "count" return value as a flag to
allow NodeValidatableResource to allow it to detect this situation and
silently ignore errors in this case.
2018-10-16 18:48:28 -07:00
Martin Atkins b54342460c core: Check that resource exists in config before evaluating it
We were previously doing this for all of the reference types except this
one. Now we do it for resources and resource instances too, which both
allows us to produce a proper error message when one is missing (rather
than returning an unknown value) and allows us to properly handle the
case where there are no instances yet present in the state (e.g. because
we're in the validate walk) but "count" isn't set, and so a single
unknown value is expected rather than an empty tuple.
2018-10-16 18:48:28 -07:00
Martin Atkins 0c4c7c5a5f core: Context.InitProvider must cache providers using absolute addresses
Previously InitProvider was incorrectly using only the relative address,
which (due to the ambiguity in the string representation of absolute vs.
relative addresses) caused it to always initialize providers in the root
module.

Now we use the absolute address as the key, which then agrees with the
Provider method and ensures that each module gets its own separate
instance of each provider if explicit configuration is present.
2018-10-16 18:48:28 -07:00
Martin Atkins b8c3b8d45d core: Tolerate missing provider config schema in EvalValidateProvider
This should never happen in real code, but it comes up a lot in test code
where incomplete mock schemas are being used to test with very simple
configurations.
2018-10-16 18:48:28 -07:00
Martin Atkins e4e3876332 core: EvalValidateProvider must always call provider.Validate
Previously we were skipping all of the validation steps if a provider was
being configured implicitly, and thus had no block in configuration.

This is incorrect, since a provider must still get an opportunity to
configure itself with an empty configuration and possibly reject that
empty configuration with errors.
2018-10-16 18:48:28 -07:00
Martin Atkins b031e18332 core: Pass ProviderSchema to EvalValidateSelfRef
EvalValidateSelfRef needs schema in order to extract references. It was
previously expecting a *configschema.Block directly, but we weren't
actually passing that in from anywhere except the tests because it's not
available directly in that form during the evaltree for
node_resource_validate.

Instead, we now pass in the whole *ProviderSchema for the associated
provider and have this EvalNode find the schema itself based on the
address. This breaks some of the generality of this node (now only really
works for resource addresses) but that's okay since we have no other
use-case right now anyway.
2018-10-16 18:48:28 -07:00
Martin Atkins 54464e3f93 core: EvalWriteOutput must convert values to string
Our old state format requires all primitive values to be strings. We were
trying to enforce that before, but this didn't work properly because
gocty does not perform automatic type conversions.

Instead, we now convert to string first and then convert the result into
a native Go string afterwards.
2018-10-16 18:48:28 -07:00
Martin Atkins 6a859f1fe3 core: don't use functions in the input-interpolate-var fixture
Using functions here causes this to test more than it needs to, and
requires additional setup in the corresponding tests.
2018-10-16 18:48:28 -07:00
Martin Atkins 0b4ac6d9e3 core: Allow unknown values as variable outputs in EvalWriteOutput
At the moment this must be handled as a special case because we're still
using the old representation of output state, but we do still need to
handle this so that unknown values can properly pass between modules
during validate and plan.
2018-10-16 18:48:28 -07:00
Martin Atkins d5fda47751 core: Add schema to all of the "Context2Validate" tests
Some of them are still failing for other reasons, but they at least all
now have schema representing their configurations.
2018-10-16 18:48:28 -07:00
Martin Atkins 509c6557dd core: Don't crash EvalValidateProvisioner if no connection block present 2018-10-16 18:48:28 -07:00
Martin Atkins 5b1b564663 core: fix formatting of unexpected diagnostics in context tests 2018-10-16 18:48:28 -07:00
Martin Atkins 7efa010f24 core: Add schema to TestTestContext2Validate_interpolateMap 2018-10-16 18:48:28 -07:00
Martin Atkins fc7453c073 core: Update tests that use the apply-vars fixture
These now need to include a suitable schema in order to properly process
the configuration.
2018-10-16 18:48:28 -07:00
Martin Atkins a9a9cdaa15 core: Fix ProcessIgnoreChanges tests
Since our ignoring is now implemented in terms of cty objects and HCL
traversals, rather than flatmap keys, it no longer makes sense to test
for the flatmap detail of keeping the map count in a separate key.

It _does_ make sense to ignore an entire block or map, but that's already
covered by another existing tests for just []string{"resource"} above.
2018-10-16 18:48:28 -07:00
Martin Atkins 39a83b2fd1 core: fix test for buildProviderConfig
This was incorrectly comparing a cty.Value to an hcl.Body. Now we decode
the body first so we can compare two of cty.Value.

Also includes a fix to a stale comment in buildProviderConfig that was no
longer accurate.
2018-10-16 18:48:28 -07:00
Martin Atkins 0a59da418a core: Fix tests for EvalConfigProvider
The interface of this eval node has changed for v0.12, now requiring both
a provider address and the actual provider object.

We also need to give it a working ctx.EvalBlock implementation on the
mock EvalContext, so we just use installSimpleEval here to get our simple
implementation that just knows how to evaluate constant expressions.
2018-10-16 18:48:28 -07:00
Martin Atkins 9833d9991d core: Fix EvalWriteState tests
EvalWriteState now requires a provider address so that it can record the
last-used provider configuration in the state.
2018-10-16 18:48:28 -07:00
Martin Atkins dc7455887e core: fix tests for debug.go
The plan debug test now needs to provide a schema for the resource types
it uses.
2018-10-16 18:48:28 -07:00
Martin Atkins 0da8fe2087 core: Fix EvalValidateSelfRef tests
We must provide a schema for the synthetic body we use for testing so that
the references can be found within it.
2018-10-16 18:48:28 -07:00
Martin Atkins 4a002bf10b core: EvalValidateSelfRef must catch instances referencing their resources
An instance like aws_instance.foo[0] is not permitted to refer to
aws_instance.foo, since that result contains the individual instance along
with all other instances.
2018-10-16 18:48:28 -07:00
Martin Atkins fc5a3c5cec core: Fix tests for types in eval_validate.go
A schema is now required for any validation, so these tests now use the
simpleMockProvider function to produce a provider with a simple schema
already configured, and test against that schema.
2018-10-16 18:48:28 -07:00
Martin Atkins e6049d79b7 core: EvalContextMock code-based mocking of evaluation
EvaluateBlock and EvaluateExpr are often called multiple times in a single
operation, and our usual approach of mocking with static values is a poor
fit for those cases.

To accommodate more complex tests, we allow the test to optionally provide
a callback function to use instead of the static return values.

Since a pretty common need is to just evaluate the given block or
expression in a simple way, we also now have a helper method
installSimpleEval that installs reasonable implementations of these
two methods that can (assuming no other customization) just evaluate
constant expressions, which is sufficient for many tests.
2018-10-16 18:48:28 -07:00
Martin Atkins abf0284ca5 tfdiags: Unwrap NonFatalError on append
This is a variant of diagnosticsAsError that we use to signal to informed
callers that there might just be warnings inside, but we should also do
the right thing if a caller just appends it to an existing diagnostics
without checking first.
2018-10-16 18:48:28 -07:00
Martin Atkins 8d0bec5728 core: Don't include "type" in connection block schema
The config loader already extracts this during its initial pass and saves
it as a separate field in a configs.Connection value, so requiring it
again here causes confusing errors about this attribute being provided but
not set.
2018-10-16 18:48:28 -07:00
Martin Atkins f148b26287 core: Fix RefreshGraphBuilder tests
A correct outcome from this test now requires resource type schema to be
available to the graph builder.
2018-10-16 18:48:28 -07:00
Martin Atkins 5e8938de98 core: Remove GraphWalkerPanicwrap, etc
These are some remnants of the shadow graph functionality that was added
to support the graph builder changes in v0.8, but that has since been
removed and so there are no remaining callers for these types and
functions.
2018-10-16 18:48:28 -07:00