Commit Graph

22087 Commits

Author SHA1 Message Date
Kristin Laemmert 602b59cdc4 porting functions 2018-10-16 18:49:20 -07:00
Kristin Laemmert 4ad3676934 port ceil function 2018-10-16 18:49:20 -07:00
Kristin Laemmert c4f4dddff5 porting crypto functions 2018-10-16 18:49:20 -07:00
Kristin Laemmert eb1d8b7909 cleanup comments for nicer godocs 2018-10-16 18:49:20 -07:00
Kristin Laemmert 9aa9b18658 porting crypto functions 2018-10-16 18:49:20 -07:00
Kristin Laemmert 1a5299efcb porting encoding functions 2018-10-16 18:49:20 -07:00
Martin Atkins e850becf64 core: update context plan tests for new module address rendering
The diff stringer now uses the standard serialization of a module address,
so we need to update the golden representations to restore their
associated tests to passing.
2018-10-16 18:49:20 -07:00
Martin Atkins 1a547b5351 core: Rename "count" variables in context plan fixtures
This variable name is now reserved so we can support the count
meta-argument inside module blocks in a later release.
2018-10-16 18:49:20 -07:00
Martin Atkins dc7f793be9 command: terraform fmt to use new HCL formatter
This doesn't yet include test updates, since there are problems in core
currently blocking these tests from running. The tests will therefore be
updated in a subsequent commit.
2018-10-16 18:49:20 -07:00
Martin Atkins ebc6238bee backend/local: Update tests for changes in "terraform" package
This mainly consists of adding schema information to the mock providers.
2018-10-16 18:49:20 -07:00
Martin Atkins a270a18a4d command: Update tests for changes in "terraform" package
This is not exhaustive, but it gets the tests in this package compiling
again and gets most of them working.
2018-10-16 18:49:20 -07:00
James Bardin cdc8abdae0 add missing Operation to the Evaluator 2018-10-16 18:48:28 -07:00
James Bardin d55d623ef0 handle unset computed values in tests
The old testDiffFn used th raw config to dynamically set computed values
in the diff. Since the schema now defines what values should be there,
all test diffs end up with unkown computed values. Filter these out by
looking for a value set to "compute"
2018-10-16 18:48:28 -07:00
Martin Atkins 77bc36abce core: Make context_plan_test failure output more helpful
Lots of the tests were previously only producing the actual result, and
not what was expected. Now we'll show both, to make debugging easier.
2018-10-16 18:48:28 -07:00
Martin Atkins cc5b1d452f core: NewInstanceInfo now produces correct "id" for data resources
We need to mimic the old API here, and we weren't doing that quite right
since the "data" prefix was missing from data resources.
2018-10-16 18:48:28 -07:00
Martin Atkins 299fe25a04 hcl2shim: Handle unknown values when shimming to/from flatmap
Previously unknown values were round-tripping through flatmap and coming
out as known strings containing the UnknownVariableValue. (The classic bug
that, ironically, was one of the big reasons to write cty!)

Now we properly handle unknown values in both directions: going in to
flatmap we write UnknownVariableValue at the appropriate key (as the count
for sequences or maps) and then coming out of flatmap we turn
UnknownVariableValue back into a cty unknown value of the requested type.
2018-10-16 18:48:28 -07:00
Martin Atkins eb54715902 core: fix string rendering of modules in diffs
This was assuming our old practice of a slice starting with the string
"root". We'll normalize here and then stringify the result to ensure that
we get a string consistent with what's used elsewhere.

This is primarily aimed at fixing some of the context plan tests.
2018-10-16 18:48:28 -07:00
Martin Atkins 39dfc9f4e0 core: Fix schema-related issues in context plan tests
Most changes here just introduce some custom schema into the test mocks.
In some cases, a fixture is lightly updated to more modern assumptions.

The test for accessing count.index in a resource block without count set
is removed, because that is no longer valid under the new language
implementation.
2018-10-16 18:48:28 -07:00
Kristin Laemmert d4e703a5c1 base64decode 2018-10-16 18:48:28 -07:00
Kristin Laemmert e30cb1a7dc typo 2018-10-16 18:48:28 -07:00
Kristin Laemmert a187c92f0e implement datetime functions 2018-10-16 18:48:28 -07:00
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