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.
improve-dynamic-block-error-message
Martin Atkins 2 years ago
parent 3e2b6ffec8
commit d574082caf

@ -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)

Loading…
Cancel
Save