From d574082caf4c7a39edf78bccbe31d1268dabc3ed Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 7 Feb 2024 16:33:14 -0800 Subject: [PATCH] terraform: nodeExpandModule must check experiments on moduleCtx Previously we were incorrectly checking for the experiment being enabled on the global EvalContext, but that doesn't make sense because experiments are explicitly module-specific. Now we'll ask the question separately for each module so we can use the module-scoped EvalContext. --- internal/terraform/node_module_expand.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/terraform/node_module_expand.go b/internal/terraform/node_module_expand.go index 271703836e..ed528f7f09 100644 --- a/internal/terraform/node_module_expand.go +++ b/internal/terraform/node_module_expand.go @@ -107,20 +107,21 @@ func (n *nodeExpandModule) Execute(globalCtx EvalContext, op walkOperation) (dia expander := globalCtx.InstanceExpander() _, call := n.Addr.Call() - // Allowing unknown values in count and for_each is currently only an - // experimental feature. This will hopefully become the default (and only) - // behavior in future, if the experiment is successful. - // - // If this is false then the codepaths that handle unknown values below - // become unreachable, because the evaluate functions will reject unknown - // values as an error. - allowUnknown := globalCtx.LanguageExperimentActive(experiments.UnknownInstances) - // nodeExpandModule itself does not have visibility into how its ancestors // were expanded, so we use the expander here to provide all possible paths // to our module, and register module instances with each of them. for _, module := range expander.ExpandModule(n.Addr.Parent()) { moduleCtx := evalContextForModuleInstance(globalCtx, module) + + // Allowing unknown values in count and for_each is currently only an + // experimental feature. This will hopefully become the default (and only) + // behavior in future, if the experiment is successful. + // + // If this is false then the codepaths that handle unknown values below + // become unreachable, because the evaluate functions will reject unknown + // values as an error. + allowUnknown := moduleCtx.LanguageExperimentActive(experiments.UnknownInstances) + switch { case n.ModuleCall.Count != nil: count, ctDiags := evaluateCountExpression(n.ModuleCall.Count, moduleCtx, allowUnknown)