stacks: refactor to get dependency locks through main

TF-17949
Daniel Schmidt 2 years ago
parent 2ed6e1facd
commit fb2f3ca276
No known key found for this signature in database
GPG Key ID: 377C3A4D62FBBBE2

@ -404,6 +404,7 @@ func (c *ComponentConfig) neededProviderClients(ctx context.Context, phase EvalP
func (c *ComponentConfig) neededProviderSchemas(ctx context.Context, phase EvalPhase) (map[addrs.Provider]providers.ProviderSchema, tfdiags.Diagnostics, bool) {
var diags tfdiags.Diagnostics
skipFutherValidation := false
config := c.ModuleTree(ctx)
decl := c.Declaration(ctx)
@ -415,10 +416,18 @@ func (c *ComponentConfig) neededProviderSchemas(ctx context.Context, phase EvalP
continue // not our job to report a missing provider
}
providerLockfileDiags := CheckProviderInLockfile(c.main.validating.opts.DependencyLocks, pTy, decl.DeclRange)
// We report these diagnostics in a different place
if providerLockfileDiags.HasErrors() {
return providerSchemas, diags, true
// If this phase has a dependency lockfile, check if the provider is in it.
depLocks := c.main.DependencyLocks(phase)
if depLocks != nil {
// Check if the provider is in the lockfile,
// if it is not we can not read the provider schema
providerLockfileDiags := CheckProviderInLockfile(*depLocks, pTy, decl.DeclRange)
// We report these diagnostics in a different place
if providerLockfileDiags.HasErrors() {
skipFutherValidation = true
continue
}
}
schema, err := pTy.Schema(ctx)

@ -370,7 +370,7 @@ func (c *ComponentInstance) checkProvider(ctx context.Context, sourceAddr addrs.
return stackconfigtypes.ProviderInstanceForValue(v), false, diags
}
func (c *ComponentInstance) neededProviderSchemas(ctx context.Context) (map[addrs.Provider]providers.ProviderSchema, tfdiags.Diagnostics) {
func (c *ComponentInstance) neededProviderSchemas(ctx context.Context, phase EvalPhase) (map[addrs.Provider]providers.ProviderSchema, tfdiags.Diagnostics) {
var diags tfdiags.Diagnostics
decl := c.call.Declaration(ctx)
@ -391,10 +391,14 @@ func (c *ComponentInstance) neededProviderSchemas(ctx context.Context) (map[addr
}
schema, err := pTy.Schema(ctx)
providerLockfileDiags := CheckProviderInLockfile(c.main.validating.opts.DependencyLocks, pTy, decl.DeclRange)
// We report these diagnostics in a different place
if providerLockfileDiags.HasErrors() {
continue
// If this phase has a dependency lockfile, check if the provider is in it.
depLocks := c.main.DependencyLocks(phase)
if depLocks != nil {
providerLockfileDiags := CheckProviderInLockfile(*depLocks, pTy, decl.DeclRange)
// We report these diagnostics in a different place
if providerLockfileDiags.HasErrors() {
continue
}
}
if err != nil {
@ -505,7 +509,7 @@ func (c *ComponentInstance) CheckModuleTreePlan(ctx context.Context) (*plans.Pla
}
prevState := c.PlanPrevState(ctx)
providerSchemas, moreDiags := c.neededProviderSchemas(ctx)
providerSchemas, moreDiags := c.neededProviderSchemas(ctx, PlanPhase)
diags = diags.Append(moreDiags)
if moreDiags.HasErrors() {
return nil, diags
@ -750,7 +754,7 @@ func (c *ComponentInstance) ApplyModuleTreePlan(ctx context.Context, plan *plans
return noOpResult, diags
}
providerSchemas, moreDiags := c.neededProviderSchemas(ctx)
providerSchemas, moreDiags := c.neededProviderSchemas(ctx, ApplyPhase)
diags = diags.Append(moreDiags)
if moreDiags.HasErrors() {
return noOpResult, diags

@ -16,6 +16,7 @@ import (
"github.com/hashicorp/terraform/internal/addrs"
fileProvisioner "github.com/hashicorp/terraform/internal/builtin/provisioners/file"
remoteExecProvisioner "github.com/hashicorp/terraform/internal/builtin/provisioners/remote-exec"
"github.com/hashicorp/terraform/internal/depsfile"
"github.com/hashicorp/terraform/internal/promising"
"github.com/hashicorp/terraform/internal/provisioners"
"github.com/hashicorp/terraform/internal/stacks/stackaddrs"
@ -609,3 +610,14 @@ func (m *Main) PlanTimestamp() time.Time {
// This is the default case, we are not planning / applying
return time.Now().UTC()
}
// DependencyLocks returns the dependency locks for the given phase.
func (m *Main) DependencyLocks(phase EvalPhase) *depsfile.Locks {
switch phase {
case ValidatePhase:
return &m.validating.opts.DependencyLocks
default:
return nil
}
}

@ -108,13 +108,16 @@ func (p *ProviderConfig) CheckProviderArgs(ctx context.Context, phase EvalPhase)
providerType := p.ProviderType(ctx)
decl := p.Declaration(ctx)
// Check if the provider is in the lockfile,
// if it is not we can not read the provider schema
lockfileDiags := CheckProviderInLockfile(p.main.validating.opts.DependencyLocks, providerType, decl.DeclRange)
if lockfileDiags.HasErrors() {
return cty.DynamicVal, lockfileDiags
depLocks := p.main.DependencyLocks(phase)
if depLocks != nil {
// Check if the provider is in the lockfile,
// if it is not we can not read the provider schema
lockfileDiags := CheckProviderInLockfile(*depLocks, providerType, decl.DeclRange)
if lockfileDiags.HasErrors() {
return cty.DynamicVal, lockfileDiags
}
diags = diags.Append(lockfileDiags)
}
diags = diags.Append(lockfileDiags)
spec, err := p.ProviderArgsDecoderSpec(ctx)
if err != nil {

Loading…
Cancel
Save