core: Resource nodes aware when unknown_instances experiment is on

Usually language experiments have single-module scope, but this particular
one can potentially force modules other than the one that opt in to do
some behavior differently for correct results.

To minimize the risk of the new experiment code impacting those who are not
participating in the experiment, we'll want to branch into a new
DynamicExpand codepath only when at least one module is participating in
the experiment, but graph nodes alone have a more tightly-scoped view that
prevents them from answering that question directly, and so we'll
temporarily ask the ConfigTransformer to help in detecting that up top and
propagating the result into all of the resource nodes.

This commit doesn't yet make use of the new temporary field; that'll
follow in a subsequent commit that introduces the new
partial-expansion-aware alternative DynamicExpand codepath.
improve-dynamic-block-error-message
Martin Atkins 2 years ago
parent 47fd5e3e35
commit 3e2b6ffec8

@ -83,6 +83,13 @@ type NodeAbstractResource struct {
// generateConfigPath tells this node which file to write generated config
// into. If empty, then config should not be generated.
generateConfigPath string
// TEMP: [ConfigTransformer] sets this to true when at least one module
// in the configuration has opted in to the unknown_instances experiment.
// See the field of the same name in [ConfigTransformer] for more details.
// (And if that field has been removed already, then this one should've
// been too!)
unknownInstancesExperimentEnabled bool
}
var (

@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform/internal/addrs"
"github.com/hashicorp/terraform/internal/configs"
"github.com/hashicorp/terraform/internal/dag"
"github.com/hashicorp/terraform/internal/experiments"
"github.com/hashicorp/terraform/internal/tfdiags"
)
@ -50,6 +51,14 @@ type ConfigTransformer struct {
// try to delete the imported resource unless the config is updated
// manually.
generateConfigPathForImportTargets string
// TEMP: [ConfigTransformer.Transform] sets this to true if at least one
// module in the configuration has the "unknown_instances" language
// experiment enabled, because this particular experiment has cross-module
// implications (a module call with unknown instances affects everything
// beneath it in the tree) but we want to avoid activating the experimental
// code in the common case where no module is using it at all.
unknownInstancesExperimentEnabled bool
}
func (t *ConfigTransformer) Transform(g *Graph) error {
@ -62,6 +71,16 @@ func (t *ConfigTransformer) Transform(g *Graph) error {
return nil
}
// TEMP: Before we go further, we'll decide whether we're going to activate
// the experimental new behavior for the "unknown_instances" experiment.
// See the docstring for [ConfigTransformer.unknownInstancesExperimentEnabled]
// for more details.
t.Config.DeepEach(func(c *configs.Config) {
if c.Module != nil && c.Module.ActiveExperiments.Has(experiments.UnknownInstances) {
t.unknownInstancesExperimentEnabled = true
}
})
// Start the transformation process
return t.transform(g, t.Config)
}
@ -161,6 +180,10 @@ func (t *ConfigTransformer) transformSingle(g *Graph, config *configs.Config) er
Module: path,
},
importTargets: imports,
// TEMP: See the docs for this field in [ConfigTransformer] for
// more information.
unknownInstancesExperimentEnabled: t.unknownInstancesExperimentEnabled,
}
var node dag.Vertex = abstract

Loading…
Cancel
Save