Commit Graph

22032 Commits

Author SHA1 Message Date
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
Martin Atkins e1e4762b03 core: Update TestNodeApplyableModuleVariablePath for new address type 2018-10-16 18:48:28 -07:00
Martin Atkins feff252700 core: fix tests for checkInputVariables
The contract for this function has changed as part of the 0.12
reorganization so that, while before it would accept a partial variables
map if all missing variables were optional, it now expects that the caller
has already collected values for all variables and is just checking them
for type-correctness here.
2018-10-16 18:48:28 -07:00
Martin Atkins ce41553d56 core: Fix test for NodeDestroyResource.DynamicExpand
Provider addresses are now required for ResourceState, and the string
formatting is now different in the naming of destroy-deposed graph nodes.
2018-10-16 18:48:28 -07:00
Martin Atkins 26e820d829 addrs: Don't return zero-length slice in Reference.Remaining.
Although this rarely matters, making it always be nil when empty makes
deep assertions simpler in tests.

This also includes a minor update to the test in the core package that
first encountered this problem, to improve the quality of its output
on failure.
2018-10-16 18:48:28 -07:00
Martin Atkins e1bc27ef6c core: ApplyGraphBuilder tests to use the "test" mock provider
These tests now need schema available to run properly, so rather than
crafting a separate schema for each of these we'll just use the one
created by simpleMockProvider, which contains a resource type called
test_object that we'll now use as the basis for all of the tests here.
2018-10-16 18:48:28 -07:00
Martin Atkins f475b3b931 core: Fix DiffTransformer node addresses
In this codepath we're still using the old "internal" ResourceAddress
parser to parse resource addresses from the diff, but the string being
parsed does not include a module path and so the result is interpreted
as a resource in the root module.

We need to rewrite this to be in the correct module path as part of
converting to the new address representation, in order to get a correct
absolute address.
2018-10-16 18:48:28 -07:00
Martin Atkins 4472cffb35 core: NodeApplyableResourceInstance.References returns its result
A trivial mistake in the rework of this function meant that it was just
discarding its result rather than returning it. It will now return its
result as expected, allowing reference analysis to work for this node
type.
2018-10-16 18:48:28 -07:00
Martin Atkins 5863c581ee core: Fix misleading log message in ProviderTransformer
The final "<resource> provided by <provider>" message was showing the
original selection made by the resource itself rather than the provider
address finally resolved after inheritance, which caused the log to
misrepresent what was actually being created in the graph.
2018-10-16 18:48:28 -07:00
Martin Atkins f7b8e3b8be core: Fix tests for TestPlanGraphBuilder
Previously this was just stubbing out provider types, but we now need to
include schema for each of the providers and resource types the tests
use in order for the references to be properly detected.

The test fixtures are adjusted slightly here so we can use the
simpleTestSchema as the schema for all of the different blocks in these
tests. The relationships between the resources are still preserved, but
the attributes are renamed to comply with this schema.
2018-10-16 18:48:28 -07:00
Martin Atkins 168354c2e8 core: Tests for scale in and out need to mock EvalExpression
Since expression evaluation is now done via an EvalContext method, and
since these tests use the MockEvalContext, we need to provide a value for
the mock call to return. Previously expression evaluation happened at a
different layer that was not mocked here.
2018-10-16 18:48:28 -07:00
Martin Atkins bec0f56808 core: Pass components through to the destroy transformers
These transformers both construct temporary graphs using many of the same
transformers used in the apply graph, and properly doing this now requires
access to the providers and provisioners in order to obtain their schemas.

Along with this, we also update the tests here to use the
simpleMockComponentFactory helper to get a mock provider with a schema
already configured, which means we also need to update the test fixtures
and assertions to use the resource type and attributes defined in that
mock factory.
2018-10-16 18:48:28 -07:00
Martin Atkins 1a9ee72ecb core: Additional trace logging in attach resource config transformer 2018-10-16 18:48:28 -07:00
Martin Atkins 71d7a9e480 core: AttachSchemaTransformer fail gracefully with no schema
Having a missing schema is a programming error, but at the time of this
commit we're in the midst of introducing schema all over Terraform and so
there are inevitably some places -- particularly in older unit tests --
where schema isn't yet being provided.

This error allows us to catch those cases and fail gracefully, rather
than panicking further down here when we access t.Components methods.

Also includes some additional logging to aid debugging of this
transformer.
2018-10-16 18:48:28 -07:00
Martin Atkins b73e4ede5d core: use correct fallback provider address for abstract resource instance
Previously we were attempting to construct a default manually here, and
actually getting it wrong by using the resource type name as a whole
rather than the expected inferrence by prefix.

Now we use the method provided in the addrs package for this purpose,
which implements the standard behavior of shaving off the first
underscore-separated word from the resource type name.
2018-10-16 18:48:28 -07:00
Martin Atkins f82c192c49 core: mock provider factory functions for testing
Now that any configuration processing requires schema, we need either a
standalone schema or a provider/provisioner configured with one a lot more
often in tests.

To avoid adding loads of extra boilerplate to the tests, these new helper
functions produce objects pre-configured with a schema that should be
useful for a number of different cases, and can be customized further for
more interesting situations.

A lot of our tests can then just use these pre-defined object and
attribute names in their fixtures in situations where the canned schemas
here are good enough.
2018-10-16 18:48:28 -07:00
Martin Atkins 4833d2aa79 addrs: helper wrappers for parsing addresses in strings
Our "Parse..." functions all take hcl.Traversal objects rather than strings,
assuming that in most cases we've already parsed a traversal out of some
larger construct (usually a config file) before interpreting it as an
address.

However, there are some situations -- particularly tests -- where being
able to easily parse a string directly is helpful. These new "Parse...Str"
functions all wrap the function of the same name with no "Str" suffix and
first parse the string with the HCL native syntax traversal parser.

As noted in the function doc comments, this should not be used in "real"
code except in exceptional circumstances, since it creates addresses and
diagnostics that do not have useful source location information for
reporting diagnostics.
2018-10-16 18:48:28 -07:00
Martin Atkins 8fabcc0c08 core: Correct test TestOrphanResourceCountTransformer_zeroAndNone
The logic under test has intentionally changed here so that setting count
to any value -- even 1 -- causes Terraform to prefer to keep indexed
instances if both non-indexed and indexed are present.

Previously Terraform treated count = 1 as equivalent to count not set at
all, but we now recognize these as two different situations and treat
count = 1 as the same as any other non-zero count, to ensure that if
count is set conditionally it'll always produce indexed instances, even
if the dynamic expression ends up evaluating to 1.
2018-10-16 18:48:28 -07:00
Martin Atkins ad6bb4a1d5 core: NodeProvisioner.Name update for new address types
This function was previously checking for a path length greater than one
because the older path format included an always present "root" element
at the start.

We now need to check for a totally-empty list, because otherwise we fail
to add the expected prefix to the front of a path with only one element.

This also includes some adjustments to the related tests and transforms
that do not change behavior but do make the test results easier to
understand and debug.
2018-10-16 18:48:28 -07:00
Martin Atkins e40e3b9ad8 core: fix inheritence checks in ConfigTreeDependencies
Due to some disagreement about what representation of provider addresses
we were using, the inherited providers map wasn't matching. Now we'll
consistenly use the "compact" form (just the provider name and optional
alias).

Also includes some other tweaks to make this test better-behaved.
2018-10-16 18:48:28 -07:00
Martin Atkins 880d971328 core: TestStateAddModule old-style output
Although the AddModule method now takes a new-style
module address as an argument, internally we're still
shimming it to a []string.

Therefore this test needs to still expect [][]string as
a result, rather tan []addrs.ModuleInstance.
2018-10-16 18:48:28 -07:00
Martin Atkins 3ed396ad5c core: Update ProviderTransformer tests for new ImportTarget interface
Prior to the refactoring to move provider address parsing/selection up
into the frontend, there was some logic here to just-in-time default a
provider config based on the given resource type.

This is now expected to happen at a higher layer, with ImportTarget
expecting an already-valid provider configuration address.

The normal import codepath was already updated with this in mind, but some
of the provider transform tests are using ImportStateTransformer as a
shortcut for getting some resource nodes added to the graph, and so those
tests now need to include a valid provider address in their ImportTarget
values.

Also includes some adjustments to test output to make the tests easier
to debug.
2018-10-16 18:48:28 -07:00
Martin Atkins f107a4bc33 addrs: Generate special string for invalid ProviderConfig
The zero value of ProviderConfig is not a valid provider config address,
so we'll generate a special string for that in order to make that clear
in case one sneaks in somewhere. This can happen, for example, in the
core flow of resolving provider inheritance during the ProviderTransformer
if a caller attempts to access the resolved provider before that
transformer has run.
2018-10-16 18:48:28 -07:00
Martin Atkins b0b1486c46 core: Clarify the MissingProviderTransformer logic
The prior implementation of this function (before the rewrite to use
addrs.AbsProviderConfig values) was relying on some implicit behavior of
our provider address normalization to generate an address in the root
module. Since that wasn't explicit, I introduced a bug here when
introducing the new address type, where I generated an address in the
node's own module, rather than in the root as expected.

This new implementation is functionally equivalent to the prior, but is
written to make the intent more obvious: take _just_ the type from the
node's provider address and create an implicit configuration for it
_in the root module_.

Along with the change in approach, this new implementation also has an
updated documentation comment that better describes its current intent
(previously it was outdated) and hopefully clearer trace logging to
better communicate what it's doing.
2018-10-16 18:48:28 -07:00
Martin Atkins fc7871c5ee command/import: default provider config in same module
Previously we were defaulting the provider configuration selection to a
provider in the root module inferred from the resource type name.

This is close, but not quite right: we need to _start_ with a provider
configuration in the same module as we're importing into, and then our
provider resolution steps during import graph construction will use that
as a starting point for a walk up the tree to find the nearest matching
configuration (which might eventually still be in the root, but not
necessarily).
2018-10-16 18:48:28 -07:00
Martin Atkins e4e972db67 core: Fix MissingProviderTransformer matching existing providers
In the change to using addrs types rather than string keys directly here
I incorrectly made this use the _relative_ provider config instead of
the absolute one, causing MissingProviderTransformer to only match
providers defined in the root module (due to ambiguity in the string
representations of these address types).

The rest of this change is improved logging and test output that helped
with debugging this issue.
2018-10-16 18:48:28 -07:00
Martin Atkins 604c347128 core: Update test fixtures for ProviderTransformer tests
Some of these tests were using an outdated form to reference a local
directory as a module. While here, I also updated the provider references
to the new unquoted form, which is preferred from v0.12 onwards.
2018-10-16 18:48:28 -07:00
Martin Atkins 37dfda93ce core: Fix ReferenceTransformer tests
The changes to our GraphNodeReferencable and GraphNodeReferencer
interfaces were not also reflected in our testing structs here, and so
these tests were no longer working.

This updates these implementations to the new required signatures,
adapting the simplified model used in the structs to generate local
variable references, since the reference model no longer uses the
arbitrary strings that this test originally depended on.

We also remove some of the tests here since the functionality they were
testing no longer applies: inter-module dependencies are now handled by
the graph nodes producing extra ReferencableAddrs, and the "backup" form
is no longer used because our new address model is able to distinguish
resources from resource instances without the need for the magical
backup reference forms we previously used.
2018-10-16 18:48:28 -07:00
Martin Atkins a6ca01f49d core: Fix TargetsTransformer tests
Resolution of dependencies automatically from expressions now requires
a schema to be available. To avoid the need to provide mock schemas for
all of these different resource types, we instead use the depends_on
argument here to mark the dependencies explicitly.
2018-10-16 18:48:28 -07:00
Martin Atkins 17d8ec6b6f core: NodeAbstractResource correct default result from ProvidedBy
Previously we had a bug where we'd use the resource type name instead of
the provider name. Now we use the DefaultProviderConfig helper function
to extract the provider name from the resource type name.
2018-10-16 18:48:28 -07:00
Martin Atkins c8f186b303 core: TestTransitiveReductionTransformer needs a schema
The ReferenceTransformer can't do its work here unless our resources have
schema attached, since otherwise it doesn't know which attributes to
search to find references.
2018-10-16 18:48:28 -07:00
Martin Atkins 7188cabdaf core: Testing helpers for building provider schemas
Now that a schema is required to decode resource configuration, a lot more
tests than before need access to mock providers in order to get a schema.
These new helpers allow a mock provider with a schema to be constructed
concisely.
2018-10-16 18:48:28 -07:00
Martin Atkins c58bdc6390 core: fix the tests in variables_test.go
This test required some adaptation for the new variable handling model in
the HCL2-oriented codepaths, where more of the handling is now done in the
"command" package.

The initial reorganization of this test was not correct, so this is a
further revision to adapt the original assertions to the new model as much
as possible, removing a few tests that no longer make sense in the new
world.
2018-10-16 18:48:28 -07:00
Martin Atkins 60ad24229f website: Link from Configuration index to Resource page
Since the index page is long, by the time the reader reaches the end of
it the relevant portion if the navigation is unlikely to be visible. To
compensate for this, we'll link to the first sub-section and thus give
the user an opportunity to notice the navigation structure for the rest
of the pages.
2018-10-16 18:48:28 -07:00
Martin Atkins b2e8987f7e website: Fix references to the now-defunct "Interpolation" page
This has been replaced with an "Expressions" page.

Also includes a number of changes to Markdown style to conform to our
usual conventions, applied automatically by my editor while making these
changes.
2018-10-16 18:48:28 -07:00