Commit graph

9 commits

Author SHA1 Message Date
Martin Atkins
bcccd67e32 tfstackdata1: A local DynamicValue message type
Previously we were directly using the planproto.DynamicValue message type,
but that's symmetrical with plans.DynamicValue in that it encodes only
the value itself and not associated metadata such as the paths that have
sensitive value marks.

This new tfstackdata1.DynamicValue therefore echoes
terraform1.DynamicValue by carrying both the value and the metadata
together.

This implies a slight change to one of the existing message types that
was encoding a map of planned input values for each component instance,
but in practice we're not currently making use of that data anyway -- it's
there to enable a hypothetical extra correctness check in the stacks
runtime so that we can detect inconsistency problems closer to their
source -- and so this change doesn't affect anything in practice. Before
we make use of it we'll probably want to change the internal API a little
so that we can preserve the sensitive value metadata on those values, but
that's beyond the scope of this PR.

The main point of adding this is to track the output values for a component
instance as part of the raw state, and so the new field for that is also
added here although nothing will read or write it yet. Actual use of that
new field will follow in future commits.
2023-12-08 10:20:20 -08:00
Martin Atkins
972f1c0678 stackplan: Track provider config for every resource instance change
Previously we were still partially relying on the record of this in the
embedded planproto object, but since we're now allowing "planned changes"
that don't actually include a change in that traditional sense we need to
track the provider configuration address separately as a top-level field.

As with some of the addresses before, this means we're now storing the
provider config address redundantly in two places when there _is_ a
planproto change. Hopefully we'll improve that someday, but we don't need
to sweat it too much right now because this only affects the internal
raw plan format that is not subject to any compatibility promises between
releases, so we can freely change it in any future version.
2023-11-15 12:38:56 -08:00
Martin Atkins
4e34e6ebfa stacks: Track prior state for all resource instance objects
Previously our raw plan data structure only included information about
resource instances that have planned actions, which meant we were missing
those which only get their state updated during refresh and don't actually
need any real work done.

Now we'll track everything, accepting that some "planned changes" for
resource instance objects will not actually include a planned change in
the typical sense, and instead only represent a state update.
2023-11-15 12:38:56 -08:00
Martin Atkins
8fd29e9439 stacks: Preserve prior state from plan to apply
We need to retain the prior state (in a form that Terraform Core's modules
runtime can accept) between the plan and apply phases because Terraform
uses it to verify that the provider's "final plan" is consistent with
the initial plan.

We previously tried to do this by reusing the "old" value from the planned
change, but that's not really possible in practice because of the
historical implementation detail that Terraform wants state information
in a JSON format and plan information in MessagePack.

This also contains the beginnings of handling the "discarding" of
unrecognized keys from the state data structures, although we'll probably
need to do more in that area later since this is just the bare minimum.
2023-11-15 12:38:56 -08:00
Martin Atkins
69aa51b9ff stackruntime: Fix some quirks of data sent from plan to apply
We previously took a few shortcuts just to more quickly produce a proof
of concept. This gets us considerably closer to a properly-working handoff
from plan to apply, at least for create, update, and replace actions.

Destroying stuff that's been removed from the configuration will take some
further work since currently everything we do is driven by objects in the
configuration. That will follow in later commits.
2023-11-15 12:38:55 -08:00
Martin Atkins
49511fe9a8 stackstate: Fuller round-tripping of resource instance object state
This gets us ever closer to being able to preserve resource instance
objects from one run to the next. In subsequent commits we'll make use of
the "LoadFromProto" option to load the prior state during the planning
phase and take it into account when we're deciding what actions to
propose.
2023-11-15 12:38:55 -08:00
Martin Atkins
54622c68a5 stackstate: Generate "raw state" objects for resource instance objects
Previously we just had a stub that only generated basic external
description objects. Now we'll also emit "raw state" objects for these,
and have some initial support for deposed objects too.
2023-11-15 12:38:55 -08:00
Martin Atkins
d99985720f stacks: Carry input variable values from plan to apply
We need to preserve the input variable values provided during the plan
phase so we can reuse them during the apply phase to recalculate derived
results based on new information learned during the apply process.

We also need to recalculate the input values for individual components
during the apply phase, so we can react to previously-unknown values that
come from other upstream components.
2023-11-15 12:38:55 -08:00
Martin Atkins
f9317731e9 tfstackdata1: Protobuf schema for stack plan and state serialization
This represents our _internal_ plan and state formats, which are private
to Terraform Core so that we can evolve them over time without needing to
coordinate with other systems.

The plan parts of this are the stack-specific container messages around
the existing "tfplan" proto schema that traditional Terraform uses for
saved plan files.

The state parts of this are really just stubs since we're not really
dealing with state just yet, but they're here to illustrate where we
intend to expand in future commits when we start implementing the apply
phase and the ability to plan based on a prior state.
2023-11-15 12:38:52 -08:00