Files
opentf/internal/lang/eval/config_validate.go
Martin Atkins e092db420e lang/eval: Stub of ConfigInstance.prepareToPlan
This is my current idea for how to resolve the chicken/egg problem of the
planning phase needing to know who uses ephemeral resource instances and
provider instances but us needing to evaluate the configuration to know
those relationships.

This borrows the evaluation behavior previously used for
ConfigInstance.Validate to produce a conservative evaluation of the
configuration without depending on any configured providers or ephemeral
resource instances, which we (in future commits) will use to discover
the relationships between those objects so that the real walk during the
planning phase can know when to start and stop them.

This relies on the idea that an evaluation with values stubbed out as
unknown should produce _at least_ the relationships that would occur with
fewer unknown values, though it might also report additional dependencies
that would vanish once values become more known. This gives the plan phase
something to start with and then we'll learn a tighter set of dependencies
during the planning phase which will form the basis of the apply-time
execution graph.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-10-27 10:15:41 -07:00

35 lines
1.2 KiB
Go

// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package eval
import (
"context"
"github.com/opentofu/opentofu/internal/lang/grapheval"
"github.com/opentofu/opentofu/internal/tfdiags"
)
// Validate checks whether the configuration instance is valid when called
// with the previously-provided input variables and dependencies.
//
// Returns at least one error diagnostic if the configuration call is not valid.
//
// This is exposed for use by "validation-only" callers like the "tofu validate"
// command, but does NOT need to be called before other methods like
// [ConfigInstance.DrivePlanning] because equivalent checks occur within those
// operations.
func (c *ConfigInstance) Validate(ctx context.Context) tfdiags.Diagnostics {
// All of our work will be associated with a workgraph worker that serves
// as the initial worker node in the work graph.
ctx = grapheval.ContextWithNewWorker(ctx)
_, diags := c.precheckedModuleInstance(ctx)
// For validation purposes we don't need to do anything more with
// the module instance we checked... the check result _is_ the validation
// result.
return diags
}