Commit graph

85 commits

Author SHA1 Message Date
Daniel Schmidt
8fa922f912
stacks: implement PlanTimestamp method on ExpressionScope
This allows us to set the plantimestamp methods value in
the stacks language
2024-06-24 17:19:18 +02:00
Liam Cervante
c0499647fa
stacks: include moved and removed in API (#35360)
* stacks: include moved and removed in API

* fix race test
2024-06-20 11:04:22 +02:00
Liam Cervante
b646dff26a
stacks: apply nested default values to inputs (#35349)
* stacks: apply nested default values to inputs

* group similar tests
2024-06-18 12:03:43 +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
fc390038f3
stacks: add tests for and refactor steps when a provider can't be configured (#35294) 2024-06-06 13:36:57 +02:00
Liam Cervante
dc06717f69
stacks: add support for unknown for_each expressions in providers (#35267)
* stacks: add support for unknown for_each expressions in providers

* return more precise values for the unknown provider
2024-06-04 16:26:23 +02:00
Liam Cervante
1e9a186059
stacks: return dynamic types when referencing partial components (#35254) 2024-06-04 15:32:50 +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
Liam Cervante
7a8ffff66e
stacks: Fix unknown provider values crashing validation phase (#35155)
* test to reproduce

* stacks: Fix unknown provider values crashing validation phase

* remove extra type information

---------

Co-authored-by: CJ Horton <cjhorton@hashicorp.com>
2024-05-16 13:06:13 +02:00
Daniel Schmidt
3267718d3d
stacks: support unknown for_each on embedded stacks 2024-05-06 16:50:48 +02:00
kmoe
b74715e5fb
stacks: fix invalid filename (#35111) 2024-05-03 08:12:27 +01:00
Daniel Schmidt
aeb5b47723
stacks: remove unused test case 2024-04-30 17:16:49 +02:00
Daniel Schmidt
3cbfd39721
stacks: validate unknown component for_each type 2024-04-29 16:31:20 +02:00
Daniel Schmidt
3a7150b27e
stacks: handle unknown values in component for_each 2024-04-29 16:31:20 +02:00
Alisdair McDiarmid
f409639934
Merge pull request #34765 from hashicorp/alisdair/stack-root-input-variable-defaults
stackruntime: Apply defaults to root variables
2024-03-08 11:09:21 -05:00
Alisdair McDiarmid
f3ec86b17b stackruntime: Treat unset and null equally
When handling root input variable values, we now consider unset and null
values to be equivalent to each other. This is consistent with how we
handle variables in embedded stacks, and very similar to how we handle
variable in the modules runtime with `nullable = false`.

One difference from the modules runtime case is that we do not prevent
a null default value for stack variables.
2024-03-07 15:49:39 -05:00
Alisdair McDiarmid
0fe26468cd stackruntime: Apply defaults to root variables
When evaluating a stack's root input variables, supplied by the caller,
we must apply any default values specified in the variable
configuration for variables with no specified value. This commit adds
this default fallback case, using NilVal as a marker indicating the lack
of a specified value.

If no default value exists for a variable, it is therefore required to
be supplied by the caller. This commit also reports a diagnostic error
in this case.
2024-03-04 16:20:17 -05: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
Liam Cervante
cec4b7b74c
stacks: validate providers based on types instead of local names (#34735)
* stacks: validate providers based on types instead of local names

* fix tests
2024-02-28 08:24:53 +01:00
Liam Cervante
31a7fa88d5
stacks: validate provider configurations during static analysis (#34730) 2024-02-27 08:43:58 +01:00
Liam Cervante
b2cc7dbadf
stacks: validate the types of input variables during validation (#34722) 2024-02-26 11:36:19 +01:00
Liam Cervante
b3abff5750
stacks: check providers blocks in components during validatation (#34707) 2024-02-21 11:07:51 +01:00
Liam Cervante
bced645a4d
stacks: call terraform.Validate on stack component configs (#34705) 2024-02-21 10:58:44 +01:00
Liam Cervante
64b311d53a
stacks: apply sensitive marks to outputs from components (#34684)
* stacks: apply sensitive marks to outputs from components

* gen headers

* ensure consistent test ordering
2024-02-16 10:46:50 +01:00
Liam Cervante
07f6621091
stacks: include resources in state when calculating required providers (#34645)
* stacks: include resources in state when calculating required providers

* also support apply time

* add copywrite headers
2024-02-15 10:45:47 +01:00
Liam Cervante
3475d22741
Fix nil pointer exception when planning stacks with undeclared variables (#34638)
* fix nil pointer exception when planning with undeclared variables

* another function does the same
2024-02-12 17:24:15 +01: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
Alisdair McDiarmid
e4b319401e stacksruntime: Add sensitive outputs tests 2024-01-08 15:27:06 -05:00
Martin Atkins
afd2282aa6 stacks/stackruntime: fix TestPlanWithSingleResource
We've now upgraded the go-slug dependency to a newer version that fixed
the bug that this FIXME comment was referring to, so we can now write the
source address correctly and remove the note.
2023-11-15 12:38:54 -08:00
Martin Atkins
c1e7abafc3 stackruntime: Configure and assign provider instances
Instead of the temporary hack of hard-coding the built-in "terraform"
provider, it's now possible to declare configurations for arbitrary
providers and assign them to the provider configuration slots of the root
module of each component.
2023-11-15 12:38:54 -08:00
Martin Atkins
3dc3781904 stackruntime: Starting up and configuring provider plugins
Each declared provider configuration is now started up and configured
during planning. We don't actually do anything with them yet other than
shut them down again once the plan is complete, but we'll improve on that
in subsequent commits.
2023-11-15 12:38:54 -08:00
Martin Atkins
ea3b70abf0 stackeval: Component calls are now referenceable
This means it's valid to write references like "component.foo" in
expressions in a stack configuration, where the result is built from the
planned output values of the root module of each component instance.

For embedded stacks we intentionally designed the language to require
explicit types on all output values so that we'd still be able to do type
checking even when we can't calculate the output values yet. Unfortunately
we can't do the same trick for components because the main Terraform
module language treats output values as dynamically-typed and so an
output value we can't evaluate yet could have literally any type.

Therefore we concede and just return cty.DynamicVal in most failure cases
here; perhaps a future edition of the main Terraform language can improve
this by requiring explicitly-typed output values there too.
2023-11-15 12:38:53 -08:00
Martin Atkins
4a179ed969 stackeval: Very very basic component planning
This is the absolute bare-minimum integration with the main Terraform
language runtime to plan changes for a component. It's intentionally not
yet very robust and limited only to the built-in Terraform provider
because we're just trying to get the bones in place for seeing stack
planning working, rather than trying to build something complete enough
to ship.

This currently only deals with the resource instance changes that get
planned and doesn't expose the root module's output values for use
elsewhere in the stack configuration. Output value handling will follow
in subsequent commits.
2023-11-15 12:38:52 -08:00
Martin Atkins
791a5fb8a6 stackruntime: Top-level "Validate" function
This is the public entry point for the overall validation of an entire
stack configuration. So far it supports validation only of input variables,
embedded stack calls, and output values. We'll grow this to support other
language constructs in later commits.

This is a relatively large commit due to introducing various supporting
infrastructure to help make evaluation possible at all. Subsequent commits
will hopefully be more focused due to being able to depend on the
foundations introduced here.
2023-11-15 12:38:51 -08:00
Martin Atkins
4754889950 stackruntime: Beginnings of Validate function
This stubs out the basic structure of stackeval's equivalent of a graph
walk, which is really just a recursive tree walk starting async tasks that
might depend on each other via the abstractions in package "promising".

This initial work is sufficient to validate the inputs to an embedded
stack call when referring to input variables in the calling stack, showing
that the expression evaluation model seems to be working and the use of
promises to deal with dependency ordering seems viable.
2023-11-15 12:38:51 -08:00