Commit Graph

1099 Commits

Author SHA1 Message Date
James Bardin 3f7197622a Merge pull request #6833 from hashicorp/jbardin/fix-interpolation
Interpolate variable during Input and Validate
2016-05-24 10:19:19 -04:00
James Nugent bf91434576 Merge branch 'b-missing-data-diff' 2016-05-23 16:11:48 -05:00
Paul Hinze b205ac2123
core: Another validate test for computed module var refs
I wanted to make sure this case was handled, and it is!

So here's an extra test for us.
2016-05-23 15:54:14 -05:00
Martin Atkins ed9b8f91cf core: test that data sources are read during refresh
Data sources with non-computed configurations should be read during the
refresh walk. This test ensures that this remains true.
2016-05-23 15:21:00 -05:00
Martin Atkins b832fb305b core: context test for destroying data resources
Earlier we had a bug where data resources would not yet removed from the
state during a destroy. This was fixed in cd0c452, and this test will
hopefully make sure it stays fixed.
2016-05-23 15:21:00 -05:00
James Bardin ed042ab067 Interpolation also skipped during Validate phase
Adding walkValidate to the EvalTree operations, and removing the
walkValidate guard from the Interpolater.valueModuleVar allows the
values to be interpolated for Validate.
2016-05-23 13:44:13 -04:00
James Bardin fc4ac52014 Module variables not being interpolated
Variables weren't being interpolated during the Input phase, causing a
syntax error on the interpolation string. Adding `walkInput` to the
EvalTree operations prevents skipping the interpolation step.
2016-05-23 13:44:09 -04:00
Martin Atkins b255c389e2 core: restore data resource creation diffs
cd0c452 contained a bug where the creation diff for a data resource was
put into a new local variable within the else block rather than into the
diff variable in the parent scope, causing a null diff to always be
produced.

This restores the expected behavior: a computed data resource appears in
the diff, so it can then be fetched during the apply walk.
2016-05-21 13:23:28 -07:00
Martin Atkins d9c137555f core: test to prove that data diffs are broken
Apparently there's been a regression in the creation of data resource
diffs: they aren't showing up in the plan at all.

As a first step to fixing this, this is an intentionally-failing test
that proves it's broken.
2016-05-21 13:00:46 -07:00
Martin Atkins cd0c4522ee core: honor "destroy" diffs for data resources
Previously the "planDestroy" pass would correctly produce a destroy diff,
but the "apply" pass would just ignore it and make a fresh diff, turning
it back into a "create" because data resources are always eager to
refresh.

Now we consider the previous diff when re-diffing during apply and so
we can preserve the plan to destroy and then ultimately actually "destroy"
the data resource (remove from the state) when we get to ReadDataApply.

This ensures that the state is left empty after "terraform destroy";
previously we would leave behind data resource states.
2016-05-20 15:07:23 -05:00
James Nugent 2abe8b6612 Merge pull request #6753 from hashicorp/b-output-destroy-fix
: core: Fix destroy w/module vars used in counts
2016-05-19 11:21:50 -05:00
Chris Marchesi 2a679edd25 core: Fix destroy on nested module vars for count
Building on b10564a, adding tweaks that allow the module var count
search to act recursively, ensuring that a sitaution where something
like var.top gets passed to module middle, as var.middle, and then to
module bottom, as var.bottom, which is then used in a resource count.
2016-05-18 13:32:56 -05:00
Paul Hinze f33ef43195 core: Fix destroy when modules vars are used in resource counts
A new problem was introduced by the prior fixes for destroy
interpolation messages when resources depend on module variables with
a _count_ attribute, this makes the variable crucial for properly
building the graph - even in destroys. So removing all module variables
from the graph as noops was overzealous.

By borrowing the logic in `DestroyEdgeInclude` we are able to determine
if we need to keep a given module variable relatively easily.

I'd like to overhaul the `Destroy: true` implementation so that it does
not depend on config at all, but I want to continue for now with the
targeted fixes that we can backport into the 0.6 series.
2016-05-18 13:32:49 -05:00
James Nugent 3ea3c657b5 core: Use OutputState in JSON instead of map
This commit forward ports the changes made for 0.6.17, in order to store
the type and sensitive flag against outputs.

It also refactors the logic of the import for V0 to V1 state, and
fixes up the call sites of the new format for outputs in V2 state.

Finally we fix up tests which did not previously set a state version
where one is required.
2016-05-18 13:25:20 -05:00
Martin Atkins 453fc505f4 core: Tolerate missing resource variables during input walk
Provider nodes interpolate their config during the input walk, but this
is very early and so it's pretty likely that any resources referenced are
entirely absent from the state.

As a special case then, we tolerate the normally-fatal case of having
an entirely missing resource variable so that the input walk can complete,
albeit skipping the providers that have such interpolations.

If these interpolations end up still being unresolved during refresh
(e.g. because the config references a resource that hasn't been created
yet) then we will catch that error on the refresh pass, or indeed on the
plan pass if -refresh=false is used.
2016-05-14 09:25:03 -07:00
Martin Atkins 61ab8bf39a core: ResourceAddress supports data resources
The ResourceAddress struct grows a new "Mode" field to match with
Resource, and its parser learns to recognize the "data." prefix so it
can set that field.

Allows -target to be applied to data sources, although that is arguably
not a very useful thing to do. Other future uses of resource addressing,
like the state plumbing commands, may be better uses of this.
2016-05-14 08:26:36 -07:00
Martin Atkins afc7ec5ac0 core: Destroy data resources with "terraform destroy"
Previously they would get left behind in the state because we had no
support for planning their destruction. Now we'll create a "destroy" plan
and act on it by just producing an empty state on apply, thus ensuring
that the data resources don't get left behind in the state after
everything else is gone.
2016-05-14 08:26:36 -07:00
Martin Atkins 4d50f22a23 core: separate lifecycle for data resource "orphans"
The handling of data "orphans" is simpler than for managed resources
because the only thing we need to deal with is our own state, and the
validation pass guarantees that by the time we get to refresh or apply
the instance state is no longer needed by any other resources and so
we can safely drop it with no fanfare.
2016-05-14 08:26:36 -07:00
Martin Atkins 36054470e4 core: lifecycle for data resources
This implements the main behavior of data resources, including both the
early read in cases where the configuration is non-computed and the split
plan/apply read for cases where full configuration can't be known until
apply time.
2016-05-14 08:26:36 -07:00
Martin Atkins 1da560b653 core: Separate resource lifecycle for data vs. managed resources
The key difference between data and managed resources is in their
respective lifecycles. Now the expanded resource EvalTree switches on
the resource mode, generating a different lifecycle for each mode.

For this initial change only managed resources are implemented, using the
same implementation as before; data resources are no-ops. The data
resource implementation will follow in a subsequent change.
2016-05-14 08:26:36 -07:00
Martin Atkins c1315b3f09 core: EvalValidate calls appropriate validator for resource mode
data resources are a separate namespace of resources than managed
resources, so we need to call a different provider method depending on
what mode of resource we're visiting.

Managed resources use ValidateResource, while data resources use
ValidateDataSource, since at the provider level of abstraction each
provider has separate sets of resources and data sources respectively.
2016-05-14 08:26:36 -07:00
Martin Atkins 844e1abdd3 core: ResourceStateKey understands resource modes
Once a data resource gets into the state, the state system needs to be
able to parse its id to match it with resources in the configuration.
Since data resources live in a separate namespace than managed resources,
the extra "mode" discriminator is required to specify which namespace
we're talking about, just like we do in the resource configuration.
2016-05-14 08:26:36 -07:00
Martin Atkins 0e0e3d73af core: New ResourceProvider methods for data resources
This is a breaking change to the ResourceProvider interface that adds the
new operations relating to data sources.

DataSources, ValidateDataSource, ReadDataDiff and ReadDataApply are the
data source equivalents of Resources, Validate, Diff and Apply (respectively)
for managed resources.

The diff/apply model seems at first glance a rather strange workflow for
read-only resources, but implementing data resources in this way allows them
to fit cleanly into the standard plan/apply lifecycle in cases where the
configuration contains computed arguments and thus the read must be deferred
until apply time.

Along with breaking the interface, we also fix up the plugin client/server
and helper/schema implementations of it, which are all of the callers
used when provider plugins use helper/schema. This would be a breaking
change for any provider plugin that directly implements the provider
interface, but no known plugins do this and it is not recommended.

At the helper/schema layer the implementer sees ReadDataApply as a "Read",
as opposed to "Create" or "Update" as in the managed resource Apply
implementation. The planning mechanics are handled entirely within
helper/schema, so that complexity is hidden from the provider implementation
itself.
2016-05-14 08:26:36 -07:00
Mitchell Hashimoto 59a9bcf3dc
terraform: fix compilation with new func call 2016-05-11 13:07:33 -07:00
Mitchell Hashimoto 27452f0043
terraform: Module option to Import to add module to graph 2016-05-11 13:02:37 -07:00
Mitchell Hashimoto ec02c8c0e2
helper/resource: testing of almost all aspects of ImportState tests 2016-05-11 13:02:37 -07:00
Mitchell Hashimoto 0d1debc0ae
terraform: import verifies the refresh results in non-nil state
/cc @jen20
2016-05-11 13:02:36 -07:00
Mitchell Hashimoto 6bdab07174
providers/aws: security group import imports rules 2016-05-11 13:02:36 -07:00
Mitchell Hashimoto b728f8c018
terraform: import state ID should be sent to hook 2016-05-11 13:02:35 -07:00
Mitchell Hashimoto d1a81379d0
terraform: use InstanceInfo more appropriately, pass ID to ImportState 2016-05-11 13:02:35 -07:00
Mitchell Hashimoto 126eb23864
terraform: call pre/post import hooks 2016-05-11 13:02:35 -07:00
Mitchell Hashimoto 95b87f5012
terraform: hook methods for pre/post import state 2016-05-11 13:02:34 -07:00
Mitchell Hashimoto 8f201b14f2
terraform: providers should input/config on import 2016-05-11 13:02:34 -07:00
Mitchell Hashimoto 33bbf09ff6
terraform: error if import with collision 2016-05-11 13:02:33 -07:00
Mitchell Hashimoto c814d36333
terraform: handle multiple same named states 2016-05-11 13:02:33 -07:00
Mitchell Hashimoto cfa58a25a6
terraform: test multiple return values 2016-05-11 13:02:33 -07:00
Mitchell Hashimoto 2ed23778b4
terraform: test importing into a new module with other modules 2016-05-11 13:02:33 -07:00
Mitchell Hashimoto 2738fa7df5
terraform: test importing into an existing module 2016-05-11 13:02:33 -07:00
Mitchell Hashimoto 7fe8b21969
terraform: verify import with missing type doesn't add to state 2016-05-11 13:02:32 -07:00
Mitchell Hashimoto 58fe557a9f
terraform: test that missing type results in error on import 2016-05-11 13:02:32 -07:00
Mitchell Hashimoto 0701c70eae
terraform: test import with module depth of two 2016-05-11 13:02:32 -07:00
Mitchell Hashimoto 492bda5186
terraform: more provider transform tests 2016-05-11 13:02:32 -07:00
Mitchell Hashimoto 0a7f48ab8e
terraform: import module works! 2016-05-11 13:02:32 -07:00
Mitchell Hashimoto 3b85544016
terraform: getting providers to connect the way we want for modules 2016-05-11 13:02:32 -07:00
Mitchell Hashimoto 6f607d0c59
terraform: MissingProviderTransformer now injects missing modules 2016-05-11 13:02:32 -07:00
Mitchell Hashimoto 1d3f11f0ba
terraform: working on fixes for imports in modules 2016-05-11 13:02:32 -07:00
Mitchell Hashimoto 0ab0ccf5b3
terraform: verify refresh is called on import 2016-05-11 13:02:31 -07:00
Mitchell Hashimoto 59e498dba8
terraform: basic test passing 2016-05-11 13:02:31 -07:00
Mitchell Hashimoto 8bb8637f24
terraform: some initial graphs (not tested, failing tests) 2016-05-11 13:02:31 -07:00
Mitchell Hashimoto aca26fd784
terraform: ImportTransformer, EvalImportState 2016-05-11 13:02:31 -07:00