terraform/internal
Martin Atkins 37b1413ab3 core: Handle root and child module input variables consistently
Previously we had a significant discrepancy between these two situations:
we wrote the raw root module variables directly into the EvalContext and
then applied type conversions only at expression evaluation time, while
for child modules we converted and validated the values while visiting
the variable graph node and wrote only the _final_ value into the
EvalContext.

This confusion seems to have been the root cause for #29899, where
validation rules for root module variables were being applied at the wrong
point in the process, prior to type conversion.

To fix that bug and also make similar mistakes less likely in the future,
I've made the root module variable handling more like the child module
variable handling in the following ways:
 - The "raw value" (exactly as given by the user) lives only in the graph
   node representing the variable, which mirrors how the _expression_
   for a child module variable lives in its graph node. This means that
   the flow for the two is the same except that there's no expression
   evaluation step for root module variables, because they arrive as
   constant values from the caller.
 - The set of variable values in the EvalContext is always only "final"
   values, after type conversion is complete. That in turn means we no
   longer need to do "just in time" conversion in
   evaluationStateData.GetInputVariable, and can just return the value
   exactly as stored, which is consistent with how we handle all other
   references between objects.

This diff is noisier than I'd like because of how much it takes to wire
a new argument (the raw variable values) through to the plan graph builder,
but those changes are pretty mechanical and the interesting logic lives
inside the plan graph builder itself, in NodeRootVariable, and
the shared helper functions in eval_variable.go.

While here I also took the opportunity to fix a historical API wart in
EvalContext, where SetModuleCallArguments was built to take a set of
variable values all at once but our current caller always calls with only
one at a time. That is now just SetModuleCallArgument singular, to match
with the new SetRootModuleArgument to deal with root module variables.
2022-01-10 12:26:54 -08:00
..
addrs check for nested module index changes 2022-01-04 09:20:47 -05:00
backend command/show: Disable plan state lineage checks 2021-12-17 17:46:42 -05:00
builtin return diagnostics from provisioners 2021-05-19 11:24:54 -04:00
cloud Refactor cloud table test runs 2021-12-20 16:36:06 -06:00
command build: Build and run e2etest as part of the release build pipeline 2022-01-05 14:31:04 -08:00
communicator de-linting 2021-09-01 11:36:21 -04:00
configs skip provider resolution when there are errors 2021-12-06 14:28:34 -05:00
copy deprecate helper/copy 2020-10-08 08:42:16 -04:00
dag do not use pointer addr strings as map keys in set 2022-01-05 11:28:47 +00:00
depsfile providercache: Discard lock entries for unused providers 2021-12-17 15:30:21 -08:00
didyoumean didyoumean: move from "helper" to "internal" 2020-10-02 13:35:07 -07:00
e2e Move states/ to internal/states/ 2021-05-17 14:09:07 -07:00
earlyconfig addrs: Expose the registry address parser's error messages 2021-11-30 15:46:16 -08:00
experiments experiments: config_driven_move has concluded 2021-11-01 08:46:15 -07:00
getmodules getmodules: Use go-getter v1.5.10 and return to upstream GitGetter 2022-01-03 11:44:16 -08:00
getproviders Fix failing lint check for deprecated x/crypto/openpgp library 2021-11-18 14:59:29 -06:00
grpcwrap Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
helper/slowmessage remove wrapped streams and readline 2021-10-28 11:51:39 -04:00
httpclient Move httpclient/ to internal/httpclient/ 2021-05-17 14:09:07 -07:00
initwd addrs: Expose the registry address parser's error messages 2021-11-30 15:46:16 -08:00
instances InstancesForModule should not panic 2021-12-17 13:31:41 -05:00
ipaddr lang/funcs: Preserve IP address leading zero behavior from Go 1.16 2021-08-17 15:20:05 -07:00
lang lang: Redact sensitive values from function errors 2021-12-03 09:46:57 -05:00
legacy Move states/ to internal/states/ 2021-05-17 14:09:07 -07:00
logging cleanup panic output 2021-12-17 11:57:52 -05:00
modsdir Refactoring of module source addresses and module installation 2021-06-03 08:50:34 -07:00
moduledeps Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
moduletest Move configs/ to internal/configs/ 2021-05-17 14:09:07 -07:00
plans go.mod: go get google.golang.org/protobuf@v1.27.1 2021-10-11 16:37:39 -07:00
plugin internal/plugin[6]: Add generated mocks 2021-10-28 20:16:26 -05:00
plugin6 "Add cloud integration option" 2021-10-28 18:30:01 -07:00
provider-simple Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
provider-simple-v6 Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
provider-terraform/main Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
providercache providercache: Discard lock entries for unused providers 2021-12-17 15:30:21 -08:00
providers Move states/ to internal/states/ 2021-05-17 14:09:07 -07:00
provisioner-local-exec/main Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
provisioners Move configs/ to internal/configs/ 2021-05-17 14:09:07 -07:00
refactoring cleanup some move graph handling 2022-01-04 09:21:36 -05:00
registry command: make module installation interruptible 2021-11-11 12:28:10 +00:00
repl core: Functional-style API for terraform.Context 2021-08-30 13:59:14 -07:00
replacefile Upgrade to Go 1.17 2021-08-17 15:20:05 -07:00
states Relax test to focus on the behavior we care about (encoded == encoded) 2022-01-05 14:38:53 -08:00
terminal remove the use of panicwrap 2021-10-28 11:51:39 -04:00
terraform core: Handle root and child module input variables consistently 2022-01-10 12:26:54 -08:00
tfdiags Move tfdiags/ to internal/tfdiags/ 2021-05-17 14:09:07 -07:00
tfplugin5 go.mod: go get google.golang.org/protobuf@v1.27.1 2021-10-11 16:37:39 -07:00
tfplugin6 Merge pull request #29648 from hashicorp/jbardin/tfproto6.1 2021-10-28 16:00:02 -04:00
typeexpr internal/typeexpr: staticcheck 2020-12-02 13:59:19 -05:00