2023-09-27 20:00:36 -04:00
|
|
|
// Copyright IBM Corp. 2014, 2026
|
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2023-07-12 20:16:16 -04:00
|
|
|
package stackruntime
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2024-02-21 04:58:44 -05:00
|
|
|
"go.opentelemetry.io/otel/codes"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/internal/addrs"
|
2024-06-26 08:17:10 -04:00
|
|
|
"github.com/hashicorp/terraform/internal/depsfile"
|
2024-02-21 04:58:44 -05:00
|
|
|
"github.com/hashicorp/terraform/internal/providers"
|
2023-07-12 20:16:16 -04:00
|
|
|
"github.com/hashicorp/terraform/internal/stacks/stackconfig"
|
|
|
|
|
"github.com/hashicorp/terraform/internal/stacks/stackruntime/internal/stackeval"
|
|
|
|
|
"github.com/hashicorp/terraform/internal/tfdiags"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Validate performs static validation of a full stack configuration, returning
|
|
|
|
|
// diagnostics in case of any detected problems.
|
|
|
|
|
func Validate(ctx context.Context, req *ValidateRequest) tfdiags.Diagnostics {
|
|
|
|
|
ctx, span := tracer.Start(ctx, "validate stack configuration")
|
|
|
|
|
defer span.End()
|
|
|
|
|
|
2024-02-21 04:58:44 -05:00
|
|
|
main := stackeval.NewForValidating(req.Config, stackeval.ValidateOpts{
|
|
|
|
|
ProviderFactories: req.ProviderFactories,
|
2024-06-26 08:17:10 -04:00
|
|
|
DependencyLocks: req.DependencyLocks,
|
2024-02-21 04:58:44 -05:00
|
|
|
})
|
2024-02-09 21:12:52 -05:00
|
|
|
main.AllowLanguageExperiments(req.ExperimentsAllowed)
|
2023-07-14 14:45:04 -04:00
|
|
|
diags := main.ValidateAll(ctx)
|
2023-08-22 21:31:10 -04:00
|
|
|
diags = diags.Append(
|
|
|
|
|
main.DoCleanup(ctx),
|
|
|
|
|
)
|
2023-07-14 14:45:04 -04:00
|
|
|
if diags.HasErrors() {
|
|
|
|
|
span.SetStatus(codes.Error, "validation returned errors")
|
|
|
|
|
}
|
|
|
|
|
return diags
|
2023-07-12 20:16:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ValidateRequest struct {
|
2024-02-21 04:58:44 -05:00
|
|
|
Config *stackconfig.Config
|
|
|
|
|
ProviderFactories map[addrs.Provider]providers.Factory
|
2024-06-26 08:17:10 -04:00
|
|
|
DependencyLocks depsfile.Locks
|
2023-07-12 20:16:16 -04:00
|
|
|
|
2024-02-09 21:12:52 -05:00
|
|
|
ExperimentsAllowed bool
|
2023-07-12 20:16:16 -04:00
|
|
|
}
|