Commit graph

61 commits

Author SHA1 Message Date
Mutahhir Hayat
5b2f19abad Add failing test for deferred actions 2026-03-06 15:54:23 +01:00
Mutahhir Hayat
876b671470 Refactor action trigger event conversion 2026-03-06 14:00:31 +01:00
Mutahhir Hayat
fb0cc11e48 Update to use new protobuf renames 2026-03-06 14:00:31 +01:00
Mutahhir Hayat
49feb6e86f Update naming to ResourceActionTrigger 2026-03-06 14:00:31 +01:00
Mutahhir Hayat
946918220c Read Action invocations from planfile 2026-03-06 14:00:31 +01:00
Radek Simko
0fe906fa8c make copyrightfix 2026-02-17 13:56:34 +00:00
Daniel Schmidt
d813ad14f7 add deprecation marks 2026-02-03 13:32:06 +01:00
James Bardin
807e084130 final renaming for function results 2025-05-08 11:42:05 -04:00
James Bardin
a6ec17cb77 rename function results table
Remove "provider" from the function results fields since it's not going
to be exclusively used for providers any longer.
2025-05-07 16:03:43 -04:00
James Bardin
d016070564 move function results hashing to lang
We need to abstract the function results verification to use internally
too, so start by moving it out of the providers code.
2025-05-07 13:02:46 -04:00
Daniel Banck
b2b42c0fb4
Store resource identities in state (TF-23255) (#36464)
* Persist resource identity in Terraform state

* make syncdeps

* Move identity schema merging closer to the protocol

* mock GetResourceIdentitySchemas

* Fix identity refresh tests

* Add more tests

* Change grcpwrap upgrade identity

* Review feedback

* Remove unnecessary version conversion

* Check if GetResourceIdentitySchemas RPC call is implemented

* Update function signature docs

* Adapt protocol changes

* Check unimplemented error for identities in GetSchema
2025-03-11 20:58:44 +01:00
Liam Cervante
bfa320c7b0
stacks: represent ephemeral inputs and outputs as null (#35824)
* stacks: represent ephemeral inputs and outputs as null

* quick fix: remove unnecessary check
2024-10-08 16:46:31 +02:00
James Bardin
384f2d4fab update collections to use for-range method 2024-10-04 11:22:44 -04:00
Liam Cervante
b38fd17cf9
stacks: emit removal notices for empty components (#35738)
* stacks: emit removal notices for empty components

* fix tests and checks
2024-09-18 10:41:36 +02:00
Liam Cervante
e78294d42b
stacks: stop encoding values into msgpack twice (#35734) 2024-09-18 10:18:01 +02:00
Liam Cervante
598648b66f
stacks: handle input and output state during delete plans (#35726) 2024-09-16 12:00:48 +02:00
Liam Cervante
d142486a40
stacks: expand plan and apply outputs for inputs (#35724) 2024-09-16 11:45:19 +02:00
Liam Cervante
73e3f8096b
stacks: complete stack output implementation for plan and apply (#35723) 2024-09-16 11:36:36 +02:00
Liam Cervante
50233d7a78
stacks: support sensitive input values in planned changes (#35640)
* stacks: support sensitive input values in planned changes

* stacks: Fix panic when applying sensitive inputs

The stacks-specific check that a given plan's input variable values
remain unchanged at apply time would previously panic when given a
marked value. Marks are not important for this check, so we simply
remove them to ensure that it passes. This seems in line with how
AssertObjectCompatible works, which I'm taking as precedent.

The new test added in this commit panics without the corresponding code
change.

---------

Co-authored-by: Alisdair McDiarmid <alisdair@users.noreply.github.com>
2024-08-27 16:13:59 +02:00
Liam Cervante
f1ae07b1af
stacks: add support for provider functions in .tfstack.hcl files (#35610)
* stacks: fix bug preventing cross-provider move refactorings

* also make provider functions work

* stacks: add support for provider functions in .tfstack.hcl files
2024-08-22 09:28:39 +02:00
Liam Cervante
915b174da3
stacks: split the terraform1 RPC package into per-service packages (#35513)
* stacks: split the terraform1 RPC package into per-service packages

* pull latest changes
2024-08-07 17:33:51 +02:00
Liam Cervante
471bddf3ba
json plan: update resource index and import ids to support unknown values (#35518) 2024-08-07 08:28:03 +02:00
Daniel Schmidt
4faf0f25dd
guard against nil resource key 2024-07-30 12:00:24 +02:00
Daniel Schmidt
c693c39677
use resource_name instead of name
Co-authored-by: Liam Cervante <liam.cervante@hashicorp.com>
2024-07-30 12:00:23 +02:00
Daniel Schmidt
df85a22343
stacks: add fields required to display plan 2024-07-30 08:39:08 +02:00
Liam Cervante
87bbc47737
stacks: include plan mode in stacks plan format (#35405)
* stacks: include plan mode in stacks plan format

* fix tests

* fix missed files
2024-07-23 17:45:07 +02:00
Martin Atkins
ec2510fc3d stacks: Track raw stack as separate messages in raw plan
Previously we had the entire raw prior state serialized as part of the
"plan header" message in the raw plan, which meant that the maximum state
size was constrained by the maximum allowed gRPC message size.

Instead now we'll use a separate raw plan element for each raw prior state
element, so that we're limited only in the size of individual items rather
than size of the state as a whole.

This deals with the last remaining (non-deprecated) case where our RPC
protocol tries to pack an entire raw state or plan into a single protobuf
message, and so we're now standardized on using a streaming approach in
all cases.
2024-07-17 11:08:16 -07:00
Liam Cervante
46a6d3f637
stacks: include moved and imported metadata in change descriptions (#35439) 2024-07-11 11:46:06 +02:00
Daniel Schmidt
b62a67394b
stacks: save plantimestamp to plan 2024-06-25 10:59:56 +02:00
Martin Atkins
e74896bd24 stackruntime: Handle apply-time-specified input variables
When the topmost stack configuration declares an ephemeral input variable,
its values must be provided separately for each of the plan and apply
phases.

Therefore here we extend the API to allow specifying input variable values
during the apply phase, and add rules to check whether all of the
apply-time-required input variables have been specified and whether any
non-ephemeral variables are either unspecified or re-specified with equal
values during the apply phase.

This also extends the FindStackConfigurationComponents response to include
more metadata about the input variables and output values so that a caller
can know which ones are ephemeral. The name of that RPC function had
already become a little too specific with the inclusion of embedded stack
information and is even moreso now; we might choose to rename it to
something more generic like "AnalyzeStackConfiguration" in future, but
that'd be a breaking change and therefore requires more coordination.
2024-06-17 08:34:46 -07:00
Liam Cervante
9b95898f63
stacks: emit events for deferred actions (#35325)
* stacks: emit events for deferred actions

* deferral allowed is always on

* Update internal/rpcapi/stacks.go

Co-authored-by: Daniel Schmidt <danielmschmidt92@gmail.com>

---------

Co-authored-by: Daniel Schmidt <danielmschmidt92@gmail.com>
2024-06-12 13:51:44 +02:00
Daniel Schmidt
59ead5356f
stacks: update RPC APIs with deferral information (#35125)
* stacks: add deferred resource instance planned change to protobuf

* stacks: add deferred resource instance to stack plan sequence

* stacks: add planned change for deferred actions

* stacks: refactor planned change resource instance planned

moving the components out of the main function definition so that we can reuse the implementation for deferred resource instances which wraps the message used for PlannedChangeResourceInstancePlanned

* stacks: track deferred changes in stackplan

* add simple tests

* fix tests

* address comments

---------

Co-authored-by: Liam Cervante <liam.cervante@hashicorp.com>
2024-06-04 15:14:00 +02:00
Martin Atkins
30e2fd6525 Handle marks a little more consistently
In the very first implementation of "sensitive values" we were
unfortunately not disciplined about separating the idea of "marked value"
from the idea of "sensitive value" (where the latter is a subset of the
former). The first implementation just assumed that any marking whatsoever
meant "sensitive".

We later improved that by adding the marks package and the marks.Sensitive
value to standardize on the representation of "sensitive value" as being
a value marked with _that specific mark_.

However, we did not perform a thorough review of all of the mark-handling
codepaths to make sure they all agreed on that definition. In particular,
the state and plan models were both designed as if they supported arbitrary
marks but then in practice marks other than marks.Sensitive would be
handled in various inconsistent ways: dropped entirely, or interpreted as
if marks.Sensitive, and possibly do so inconsistently when a value is
used only in memory vs. round-tripped through a wire/file format.

The goal of this commit is to resolve those oddities so that there are now
two possible situations:
 - General mark handling: some codepaths genuinely handle marks
   generically, by transporting them from input value to output value in
   a way consistent with how cty itself deals with marks. This is the
   ideal case because it means we can add new marks in future and assume
   these codepaths will handle them correctly without any further
   modifications.
 - Sensitive-only mark preservation: the codepaths that interact with our
   wire protocols and file formats typically have only specialized support
   for sensitive values in particular, and lack support for any other
   marks. Those codepaths are now subject to a new rule where they must
   return an error if asked to deal with any other mark, so that if we
   introduce new marks in future we'll be forced either to define how we'll
   avoid those markings reaching the file/wire formats or extend the
   file/wire formats to support the new marks.

Some new helper functions in package marks are intended to standardize how
we deal with the "sensitive values only" situations, in the hope that
this will make it easier to keep things consistent as the codebase evolves
in future.

In practice the modules runtime only ever uses marks.Sensitive as a mark
today, so all of these checks are effectively covering "should never
happen" cases. The only other mark Terraform uses is an implementation
detail of "terraform console" and does not interact with any of the
codepaths that only support sensitive values in particular.
2024-04-18 07:32:52 -07:00
Daniel Schmidt
949a0e5585
Merge pull request #34755 from hashicorp/TF-10993
stacks: expose replace paths in grpc api
2024-03-05 11:45:08 +01:00
Daniel Schmidt
2fa4cc7b53
stacks: use existing conversion for attribute paths 2024-03-05 11:39:54 +01:00
CJ Horton
5a750561e6 round-trip check results through stack plans
Components expect that check results will be round-tripped
through the plan in order to update unknown check results
during the apply. We hadn't wired this up for stack plans,
resulting in panics when the apply tries to update a check
status that doesn't exist.
2024-03-01 17:22:44 -08:00
Daniel Schmidt
57dd94fcde
stacks: expose replace paths in grpc api
Co-authored-by: Katy Moe <katy@katy.moe>
2024-03-01 14:30:49 +01:00
Martin Atkins
a45d4467f1 stackeval: Don't fail when data resource is removed
Due to an oversight in our handling of resource instance objects that are
neither in configuration nor plan -- which is true for data resources that
have since been removed from the configuration -- we were generating plan
change objects that were lacking a provider configuration address, which
made them syntactically invalid and thus not reloadable using the
raw plan parser.

This is a bit of a strange situation since we don't technically _need_ a
provider configuration address for these; all we're going to do is just
unceremoniously delete them from the state during apply anyway. However,
we always have the provider configuration address available anyway, so
adding this in here is overall simpler than changing the parser, the
models it populates, and all of the downstream users of those models to
treat this field as optional.

This commit is more test case than it is fix, since the fix was relatively
straightforward once I had a test case to reproduce the problem it's
fixing.
2024-02-26 08:14:16 -08:00
Martin Atkins
884e1fb2a4 terraform: Plans can be "complete" and "applyable"
These ideas are both already implied by some logic elsewhere in the system,
but until now we didn't have the decision logic centralized in a single
place that could therefore evolve over time without necessarily always
updating every caller together.

We'll now have the modules runtime produce its own boolean ruling about
each characteristic, which callers can rely on for the mechanical
decision-making of whether to offer the user an "approve" prompt, and
whether to remind the user after apply that it was an incomplete plan
that will probably therefore need at least one more plan/apply round to
converge.

The "Applyable" flag directly replaces the previous method Plan.CanApply,
with equivalent logic. Making this a field instead of a method means that
we can freeze it as part of a saved plan, rather than recalculating it
when we reload the plan, and we can export the field value in our export
formats like JSON while ensuring it'll always be consistent with what
Terraform is using internally.

Callers can (and should) still use other context in the plan to return
more tailored messages for specific situations they already know about
that might be useful to users, but with these flags as a baseline callers
can now just fall back to a generic presentation when encountering a
situation they don't yet understand, rather than making the wrong decision
and causing something strange to happen. That is: a lack of awareness of
a new rule will now cause just a generic message in the UI, rather than
incorrect behavior.

This commit mostly just deals with populating the flags, and then all of
the direct consequences of that on our various tests. Further changes to
actually make use of these flags elsewhere in the system will follow in
later commits, both in this repository and in other repositories.
2024-02-09 09:24:27 -08:00
Alisdair McDiarmid
1d3f863f2b stackruntime: Support sensitive component inputs
Components can emit sensitive values as outputs, which can be consumed
as inputs to other components. This commit ensures that such values are
correctly processed in order to pass their sensitivity to the modules
runtime.
2024-01-08 15:27:06 -05:00
Martin Atkins
a4d61733f6 stackplan: Include extra info in raw component instance plan
We'll now track the planned action, the component addresses we depend on,
and the planned output values.
2024-01-08 10:52:01 -08:00
Martin Atkins
25a514f846 stackeval: Populate planned component instance more thoroughly
We'll now track a more realistic Action, the components that the component
instance depends on, and the planned output values.
2024-01-08 10:52:01 -08:00
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
Matej Risek
8ac8f18636
Feature/add additional fields to resource proto (#34364)
Add additional fields to the AppliedChange#ResourceInstance

We're adding Resource Mode, Resource Type and Provider Address to the AppliedChange's ResourceInstance
2023-12-08 10:05:55 +01:00
Martin Atkins
0952457778 stackplan: Remove stale TODO about output value changes
This recorded that we needed to encode the type information for the
output values. In the end we didn't need to do anything special for that
because we're borrowing the pre-serialized data originally designed for
the traditional Terraform CLI saved plan format, and that encodes the
type information as part of the MessagePack encoding in-band.
2023-11-15 12:38:56 -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
3d8e95d153 rpcapi(Stacks): Support multiple descriptions in a "PlannedChange"
Previously we had an asymmetry between PlannedChange and AppliedChange,
where the latter supported any number of "description" objects whereas
the former only supported zero or one.

This change then is primarily motivated by making these two APIs
consistent, but also has some other benefits:

 - The generated RPC stub packages will now have a specific type to use
   to represent _just_ a change description for a plan, so callers can
   pass around and preserve just those objects in isolation, rather than
   always having to use the entire PlannedChange message for that purpose.

 - This gives us a little more flexibility if later we find we need to
   return more than one description associated with a single logical
   change in future. For example, if we end up needing to make a breaking
   change to how we describe a particular kind of change, we might send
   an object containing both the old form and the new form together,
   and instruct clients that support the new form to treat it as taking
   priority over the old form when both are present.

   We don't yet know of any specific reason to do this, but this protocol
   is likely to be with us for a long time and so we need to prioritize
   leaving room for future additions we haven't thought of yet.

This is a breaking change to the API from a client's perspective, but
that's acceptable at the current stage of development where nothing has
been committed in a stable release yet.
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
5372d5eb98 stacks+rpcapi(stacks): Model deposed objects for resource instances
Previously we incorrectly assumed that resource instances only have one
"current" object each. However, resource instances can also have deposed
objects which we must also keep track of.

This is a breaking change to the rpcapi since we're now using a new
message type for a resource instance _object_ address in several places.
That breakage is intentional here because at the time of writing this
commit the rpcapi is not yet in any stable release and we want to force
updating our existing internal client to properly handle deposed objects
too.
2023-11-15 12:38:56 -08:00