mirror of
https://github.com/hashicorp/terraform.git
synced 2026-02-03 20:50:59 -05:00
If the providers are not in the lockfile fetching the schema fails. This leads to follow up diagnostics that send an unclear message. Now we validate the lockfile and if something is missing we skip further validation that relies on the provider schema being present.
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package stackruntime
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.opentelemetry.io/otel/codes"
|
|
|
|
"github.com/hashicorp/terraform/internal/addrs"
|
|
"github.com/hashicorp/terraform/internal/depsfile"
|
|
"github.com/hashicorp/terraform/internal/providers"
|
|
"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()
|
|
|
|
main := stackeval.NewForValidating(req.Config, stackeval.ValidateOpts{
|
|
ProviderFactories: req.ProviderFactories,
|
|
DependencyLocks: req.DependencyLocks,
|
|
})
|
|
main.AllowLanguageExperiments(req.ExperimentsAllowed)
|
|
diags := main.ValidateAll(ctx)
|
|
diags = diags.Append(
|
|
main.DoCleanup(ctx),
|
|
)
|
|
if diags.HasErrors() {
|
|
span.SetStatus(codes.Error, "validation returned errors")
|
|
}
|
|
return diags
|
|
}
|
|
|
|
type ValidateRequest struct {
|
|
Config *stackconfig.Config
|
|
ProviderFactories map[addrs.Provider]providers.Factory
|
|
DependencyLocks depsfile.Locks
|
|
|
|
ExperimentsAllowed bool
|
|
}
|