Commit Graph

14 Commits

Author SHA1 Message Date
James Bardin ea9096fb21 data source depends_on
A data source referencing another data source through depends_on should
not be forced to defer until apply. Data sources have no side effects,
so nothing should need to be applied. If the dependency has a
planned change due to a managed resource, the original data source will
also encounter that further down the list of dependencies.

This prevents a data source being read during plan for any reason from
causing other data sources to be deferred until apply. It does not
change the behavior noticeably in 0.14, but because 0.13 still had
separate refresh and plan phases which could read the data source, the
deferral could cause many things downstream to become unexpectedly
unknown until apply.
2020-09-25 13:46:47 -04:00
James Bardin 6039622111 Simplify data lifecycle for the no-refresh world
Now that we don't have to handle data sources that may or may not have
been updated during a refresh phase, and the plan phase can save the
data source to the refreshed state, we can remove a lot of the logic
involved in detecting whether the data source needs to be planned or
not.

When there is no separate refresh phase, we always must attempt to read
the data source during planning, and the only conditions are based on
having a known configuration, and not having any dependencies on which
we're waiting. If the data source is read during plan, we can now save
that directly to the refreshed state, and don't need to smuggle the
value as a change to be saved during apply.
2020-09-22 09:55:19 -04:00
James Bardin 669da06515 saved read data in the refresh state during plan
This only changes the refreshed state stored in the plan file. Since the
change is stored in the plan, the applied result would be the same, but
we should still store the refreshed data in the plan file for tools that
consume the plan file.

This will also be needed in order to implement a new refresh command
based on the plan itself.
2020-09-17 17:12:10 -04:00
Alisdair McDiarmid 5be772d85a terraform: Fix createEmptyBlocks NestingSingle bug
When calling createEmptyBlocks, we only intend to process legacy SDK
blocks (NestingList or NestingSet), but the function also needs to pass
through NestingSingle block types untouched. To do so we must only look
up the container's element type after we've established that the block
is backed by a container.
2020-08-27 20:29:36 -04:00
James Bardin 93246bd978 allow plan data state comparison with legacy SDK
In order to determine if we need to re-read a data source during plan,
we need to compare the newly evaluated configuration with the stored
state. To do that we create a ProposedNewVal, which if there are no
changes, should match the existing state exactly.

A problem arises if the remote data source contains any blocks, and they
are not set in the configuration. Terraform always decodes configuration
blocks as empty containers, however the legacy SDK cannot correctly
handle empty blocks and may return a null block which is saved to the
state. In order to correctly make the comparison for planning, we need
to reify those null blocks as empty containers in the cty value.

The createEmptyBlocks helper converts any null NestingList or NestingSet
blocks to empty list or set cty values. We only need to be concerned
with List and Set, because those are the only types that can be defined
with the legacy SDK. In hindsight these could have been normalized in
the legacy SDK shims had this problem been uncovered earlier, but for the
sake of compatibility we will now normalize these in core.
2020-08-14 13:36:52 -04:00
James Bardin 7d3cd5bc43 store planned data source state when deferring
This copies the behavior of resources, so that there is a placeholder
state available for planning.
2020-07-23 17:15:13 -04:00
James Bardin f433228906 hide empty plans for misbehaving data resource
If a data source is storing a value that doesn't comply precisely with
the schema, it will now show up as a perpetual diff during plan.

Since we can easily detect if there is no resulting change from the
stored value, rather than presenting a planned read each time, we can
change the plan to a NoOp and log the incongruity as a warning.
2020-06-18 19:21:19 -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 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 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 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