Commit Graph

2898 Commits

Author SHA1 Message Date
James Bardin
4637be4377 add a way to force depends_on behavior of data
Resources that are not yet created will not be in the graph during
refresh, and therefore cannot be attached to the data source nodes. In
this case we still need to indicate if there are depends_on entries
inherited from the module call, which we can do with the forceDependsOn
field.
2020-06-04 18:03:32 -04:00
James Bardin
e74ebe1787 get more depends_on info for data source
Since data sources may be read during refresh or early in plan, they
need to know if there are any inherited dependencies from containing
modules too.
2020-06-04 18:03:14 -04:00
James Bardin
a03c86f612 add DependsOn method to moduleExpandModule
We'll need this again for getting the transitive depends_on references
from parent module calls. This is needed to inform us how to handle data
sources during refresh and plan.
2020-06-04 18:03:03 -04:00
James Bardin
535267e986 add dependsOn to evalDataRead
this is also needed during refresh, so move it into the base struct type
2020-06-04 18:03:03 -04:00
James Bardin
58babccc7a improve depends_on test to check ordering 2020-06-04 18:03:03 -04:00
Kristin Laemmert
daa57ba9f6
terraform: fix panic with the combination of non extant resource and dynamics (#25097) 2020-06-02 09:01:12 -04:00
James Bardin
1bbb59fc1b remove extra whitespace 2020-05-29 10:31:10 -04:00
James Bardin
acd3dca567 remove unused closer field 2020-05-29 10:29:27 -04:00
James Bardin
3dbd6ea3a9 remove stale comment 2020-05-29 10:18:33 -04:00
James Bardin
74ae34865d re-add test lost in merge 2020-05-28 21:41:15 -04:00
James Bardin
b860b40127 re-enable depend_on test 2020-05-28 21:35:05 -04:00
James Bardin
10e8529471 add node pruning log line 2020-05-28 21:34:01 -04:00
James Bardin
75ec201e6a temporarily disable module depends_on test 2020-05-28 21:33:56 -04:00
James Bardin
d97a210ad3 don't connect destroyers to module expanders
Resource destroy nodes can only depend on other resources. Connecting
them to their module expander can introduce cycles when the module
expander depends on resources in the destroyer's subgraph.
2020-05-28 21:33:08 -04:00
James Bardin
a9e0f46f23 expanded module depends_on test 2020-05-28 21:33:05 -04:00
James Bardin
70ac00595b fix apply tests
sSme apply tests had outputs in empty modules, which won't be saved to
state.
2020-05-28 21:30:44 -04:00
James Bardin
48757bcbe0 get rid of the NodeOutputOrphan
We don't need another node type for orphaned outptus, they are just
outputs being removed for a different reason than destroy. Use the
NodeDestroyableOutput implementation.

Destroy outputs also don't need to be referencers, since they are being
removed.

Rename DestroyOutputTransformer to destroyRootOutputTransformer, and add
an explanation as to why it is the only transformer that requires an
exception to know when it's involved from the destroy command.
2020-05-28 21:30:44 -04:00
James Bardin
dc1b133831 remove requiresInstanceExpansion
simplification allows us to settle on a single interface,
graphNodeExpandsInstances for all types if instance expanders. The only
other specific class of resource we need to detect during pruning is the
nodeExpandApplyableResource node, which is already classified under the
GraphNodeResourceInstance interface.
2020-05-28 21:30:44 -04:00
James Bardin
082f91cd85 fix ModulePath for nodeExpandModule
ModulePath was incorrectly returning the parent module, because it did
not implement ReferenceOutside. With ReferenceOutside working correctly,
we can have ModulePath return the real path and remove the special case
for this during pruning.
2020-05-28 21:30:44 -04:00
James Bardin
c638252210 pruneUnusedNodesTransformer
Create a single transformer to remove all unused nodes from the apply
graph. This is similar to the combination of the resource pruning done
in the destroy edge transformer, and the unused values transformer. In
addition to resources, variables, locals, and outputs, we now need to
remove unused module expansion nodes as well. Since these can all be
interdependent, we need to process them as whole in a single
transformation.
2020-05-28 21:30:42 -04:00
James Bardin
7122b271f9 restore the ordering of nested modules
In order for depends_on to work, modules need to implicitly depend on
their child modules. This will have little effect on terraform's
concurrency, as configuration trees are always much wider than they are
deep.
2020-05-28 21:30:12 -04:00
James Bardin
63b54f2b72 remove unused transformer 2020-05-28 21:30:12 -04:00
James Bardin
5c401bead9 nodeCloseModule needs GraphNodeReferenceOutside
The ModulePath method was incorrect, and standing in for
GraphNodeReferenceOutside. Add ReferenceOutside so we can fix
ModulePath.
2020-05-28 21:30:12 -04:00
James Bardin
009a136fa2 requiresInstanceExpansion and instanceExpander
create interfaces that nodes can implement to declare whether they
expand into instances of some sort, using the instances.Expander, and/or
whether use the instances.Expander to find instances.

included is a rough transformer implementation to remove these nodes
from the apply graph.
2020-05-28 21:30:12 -04:00
James Bardin
741aab31d1 delete unused code
this search for orphans was never used
2020-05-28 21:30:12 -04:00
James Bardin
8ba63110ec
Merge pull request #25005 from hashicorp/jbardin/module-depends-on
Module depends_on
2020-05-28 21:29:04 -04:00
Martin Atkins
d1bc412220 configs: Custom variable validation is no longer experimental
All of the feedback from the experiment described enhancements that can
potentially be added later without breaking changes, so this change simply
removes the experiment gate from the feature as originally implemented
with no changes to its functionality.

Further enhancements may follow in later releases, but the goal of this
change is just to ship the feature exactly as it was under the experiment.

Most of the changes here are cleaning up the experiment opt-ins from our
test cases. The most important parts are in configs/experiments.go and in
experiments/experiment.go .
2020-05-28 16:07:59 -07:00
James Bardin
d2466fab3d add module self-reference test 2020-05-27 15:09:52 -04:00
James Bardin
14ef51bfcd module depends_on test
verify a chain of depends_on references through modules execute in the
correct order
2020-05-20 14:46:30 -04:00
James Bardin
e1f607c9eb add depends_on references for modules to graph
Connect references from depends_on in modules calls. This will "just
work" for a lot of cases, but data sources will be read too early in the
case where they require the dependencies to be created. While
data sources will be properly ordered behind the module head node, there
is nothing preventing them from being being evaluated during refresh.
2020-05-20 13:46:13 -04:00
James Bardin
e690fa1363
Merge pull request #24904 from hashicorp/jbardin/plan-data-sources
Evaluate data sources in plan when necessary
2020-05-20 10:00:32 -04:00
James Bardin
a8e0914d7f attach dependency type name changes 2020-05-18 21:35:37 -04:00
Kristin Laemmert
a4c3c1d389
vendor: upgrade go-cty dependency to 1.4.1 (#24983)
* vendor: upgrade go-cty dependency to 1.4.1

This upgrade fixes a panic with inconsistent object element types.
2020-05-18 14:10:19 -04:00
James Bardin
78d8af18c2
Merge pull request #24956 from hashicorp/jbardin/cbd-state
CreateBeforeDestroy inheritence and state serializaton
2020-05-18 11:46:29 -04:00
James Bardin
c052463f62 test for inherited create_before_destroy in state 2020-05-14 15:46:08 -04:00
James Bardin
7731441beb Make sure CBD is correct during apply, and saved
The resource apply nodes need to be GraphNodeDestroyerCBD in order to
correctly inherit create_before_destroy. While the plan will have
recorded this to create the correct deposed nodes, the edges still need
to be transformed correctly.

We also need create_before_destroy to be saved to state for nodes that
inherited it, so that if they are removed from state the destroy will
happen in the correct order.
2020-05-14 15:46:08 -04:00
James Bardin
cf9b6de03e force cbd during apply too
We need to run the force CBD transformer during apply too, both to
ensure we can rely on the `CreateBeforeDestroy()` status for dependants
during apply, but also to ensure that the correct status is stored into
state.
2020-05-14 15:46:08 -04:00
James Bardin
23f5fc3e5a thread create_before_destroy to the state file 2020-05-14 15:46:08 -04:00
Kristin Laemmert
041f4dd8ca
configs: require normalized provider local names (#24945)
* addrs: replace NewLegacyProvider with NewDefaultProvider in ParseProviderSourceString

ParseProviderSourceString was still defaulting to NewLegacyProvider when
encountering single-part strings. This has been fixed.

This commit also adds a new function, IsProviderPartNormalized, which
returns a bool indicating if the string given is the same as a
normalized version (as normalized by ParseProviderPart) or an error.
This is intended for use by the configs package when decoding provider
configurations.

* terraform: fix provider local names in tests

* configs: validate that all provider names are normalized

The addrs package normalizes all source strings, but not the local
names. This caused very odd behavior if for e.g. a provider local name
was capitalized in one place and not another. We considered enabling
case-sensitivity for provider local names, but decided that since this
was not something that worked in previous versions of terraform (and we
have yet to encounter any use cases for this feature) we could generate
an error if the provider local name is not normalized. This error also
provides instructions on how to fix it.

* configs: refactor decodeProviderRequirements to consistently not set an FQN when there are errors
2020-05-14 09:00:58 -04:00
James Bardin
291110fe78 Don't use plans.Update for data sources
The new data source planning logic no longer needs a separate action,
and the apply status can be determined from whether the After value is
complete or not.
2020-05-13 13:58:11 -04:00
James Bardin
8850d787f4 add evalWriteEmptyState for data source removal 2020-05-13 13:58:11 -04:00
James Bardin
7b8f13862c un-export new data eval nodes 2020-05-13 13:58:11 -04:00
James Bardin
8e3728af54 rename methods for ConfigResource changes 2020-05-13 13:58:11 -04:00
James Bardin
c6c851eb3f add test for using a data source with depends_on
Ensure that a data source with depends_on not only plans to update
during refresh, but evaluates correctly in the plan ensuring
dependencies are planned accordingly.
2020-05-13 13:58:11 -04:00
James Bardin
44919641ef set state in deferred data read
The state was not being set, so the change was not evaluated correctly
for dependant resources.

Remove use of cty.NilVal in readDataSource, only one place was using it,
so the code could just be moved out.

Fix a bunch of places where warnings would be lost.
2020-05-13 13:58:11 -04:00
James Bardin
05575a863c check for data source changed during plan
Rather than re-read the data source during every plan cycle, apply the
config to the prior state, and skip reading if there is no change.

Remove the TODOs, as we're going to accept that data-only changes will
still not be plan-able for the time being.

Fix the null data source test resource, as it had no computed fields at
all, even the id.
2020-05-13 13:58:11 -04:00
James Bardin
6ca252faab refactor EvalReadData
The logic for refresh, plan and apply are all subtly different, so
rather than trying to manage that complex flow through a giant 300 line
method, break it up somewhat into 3 different types that can share the
types and a few helpers.
2020-05-13 13:58:11 -04:00
James Bardin
96be76effb cleanup refresh test 2020-05-13 13:58:11 -04:00
James Bardin
4a92b7888f start to refactor EvalReadData
Remove extra fields, remove the depends_on logic from
NodePlannableResourceInstnace, and start breaking up the massive Eval
method.
2020-05-13 13:58:11 -04:00
James Bardin
be20a7941d remove EvalReadDataApply
EvalReadDataApply was all dead code, as it was only using during delete
and simply set the state to nil.
2020-05-13 13:58:11 -04:00