backend/local: Increase log verbosity for backend context construction
There are several steps here and a number of them can include reaching out to remote servers or executing local processes, so it's helpful to have some trace logs to better narrow down causes of errors and hangs during this step.
This commit is contained in:
parent
34c4fd316d
commit
c5940f2438
|
@ -143,6 +143,7 @@ func (b *Local) opApply(
|
||||||
doneCh := make(chan struct{})
|
doneCh := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
defer close(doneCh)
|
defer close(doneCh)
|
||||||
|
log.Printf("[INFO] backend/local: apply calling Apply")
|
||||||
_, applyDiags = tfCtx.Apply()
|
_, applyDiags = tfCtx.Apply()
|
||||||
// we always want the state, even if apply failed
|
// we always want the state, even if apply failed
|
||||||
applyState = tfCtx.State()
|
applyState = tfCtx.State()
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package local
|
package local
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
@ -35,15 +36,18 @@ func (b *Local) context(op *backend.Operation) (*terraform.Context, *configload.
|
||||||
var diags tfdiags.Diagnostics
|
var diags tfdiags.Diagnostics
|
||||||
|
|
||||||
// Get the latest state.
|
// Get the latest state.
|
||||||
|
log.Printf("[TRACE] backend/local: requesting state manager for workspace %q", op.Workspace)
|
||||||
s, err := b.StateMgr(op.Workspace)
|
s, err := b.StateMgr(op.Workspace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
diags = diags.Append(errwrap.Wrapf("Error loading state: {{err}}", err))
|
diags = diags.Append(errwrap.Wrapf("Error loading state: {{err}}", err))
|
||||||
return nil, nil, nil, diags
|
return nil, nil, nil, diags
|
||||||
}
|
}
|
||||||
|
log.Printf("[TRACE] backend/local: requesting state lock for workspace %q", op.Workspace)
|
||||||
if err := op.StateLocker.Lock(s, op.Type.String()); err != nil {
|
if err := op.StateLocker.Lock(s, op.Type.String()); err != nil {
|
||||||
diags = diags.Append(errwrap.Wrapf("Error locking state: {{err}}", err))
|
diags = diags.Append(errwrap.Wrapf("Error locking state: {{err}}", err))
|
||||||
return nil, nil, nil, diags
|
return nil, nil, nil, diags
|
||||||
}
|
}
|
||||||
|
log.Printf("[TRACE] backend/local: reading remote state for workspace %q", op.Workspace)
|
||||||
if err := s.RefreshState(); err != nil {
|
if err := s.RefreshState(); err != nil {
|
||||||
diags = diags.Append(errwrap.Wrapf("Error loading state: {{err}}", err))
|
diags = diags.Append(errwrap.Wrapf("Error loading state: {{err}}", err))
|
||||||
return nil, nil, nil, diags
|
return nil, nil, nil, diags
|
||||||
|
@ -63,6 +67,7 @@ func (b *Local) context(op *backend.Operation) (*terraform.Context, *configload.
|
||||||
// Load the latest state. If we enter contextFromPlanFile below then the
|
// Load the latest state. If we enter contextFromPlanFile below then the
|
||||||
// state snapshot in the plan file must match this, or else it'll return
|
// state snapshot in the plan file must match this, or else it'll return
|
||||||
// error diagnostics.
|
// error diagnostics.
|
||||||
|
log.Printf("[TRACE] backend/local: retrieving the local state snapshot for workspace %q", op.Workspace)
|
||||||
opts.State = s.State()
|
opts.State = s.State()
|
||||||
|
|
||||||
var tfCtx *terraform.Context
|
var tfCtx *terraform.Context
|
||||||
|
@ -77,17 +82,20 @@ func (b *Local) context(op *backend.Operation) (*terraform.Context, *configload.
|
||||||
m := sm.StateSnapshotMeta()
|
m := sm.StateSnapshotMeta()
|
||||||
stateMeta = &m
|
stateMeta = &m
|
||||||
}
|
}
|
||||||
|
log.Printf("[TRACE] backend/local: building context from plan file")
|
||||||
tfCtx, configSnap, ctxDiags = b.contextFromPlanFile(op.PlanFile, opts, stateMeta)
|
tfCtx, configSnap, ctxDiags = b.contextFromPlanFile(op.PlanFile, opts, stateMeta)
|
||||||
// Write sources into the cache of the main loader so that they are
|
// Write sources into the cache of the main loader so that they are
|
||||||
// available if we need to generate diagnostic message snippets.
|
// available if we need to generate diagnostic message snippets.
|
||||||
op.ConfigLoader.ImportSourcesFromSnapshot(configSnap)
|
op.ConfigLoader.ImportSourcesFromSnapshot(configSnap)
|
||||||
} else {
|
} else {
|
||||||
|
log.Printf("[TRACE] backend/local: building context for current working directory")
|
||||||
tfCtx, configSnap, ctxDiags = b.contextDirect(op, opts)
|
tfCtx, configSnap, ctxDiags = b.contextDirect(op, opts)
|
||||||
}
|
}
|
||||||
diags = diags.Append(ctxDiags)
|
diags = diags.Append(ctxDiags)
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
return nil, nil, nil, diags
|
return nil, nil, nil, diags
|
||||||
}
|
}
|
||||||
|
log.Printf("[TRACE] backend/local: finished building terraform.Context")
|
||||||
|
|
||||||
// If we have an operation, then we automatically do the input/validate
|
// If we have an operation, then we automatically do the input/validate
|
||||||
// here since every option requires this.
|
// here since every option requires this.
|
||||||
|
@ -98,6 +106,7 @@ func (b *Local) context(op *backend.Operation) (*terraform.Context, *configload.
|
||||||
mode |= terraform.InputModeVar
|
mode |= terraform.InputModeVar
|
||||||
mode |= terraform.InputModeVarUnset
|
mode |= terraform.InputModeVarUnset
|
||||||
|
|
||||||
|
log.Printf("[TRACE] backend/local: requesting interactive input, if necessary")
|
||||||
inputDiags := tfCtx.Input(mode)
|
inputDiags := tfCtx.Input(mode)
|
||||||
diags = diags.Append(inputDiags)
|
diags = diags.Append(inputDiags)
|
||||||
if inputDiags.HasErrors() {
|
if inputDiags.HasErrors() {
|
||||||
|
@ -107,6 +116,7 @@ func (b *Local) context(op *backend.Operation) (*terraform.Context, *configload.
|
||||||
|
|
||||||
// If validation is enabled, validate
|
// If validation is enabled, validate
|
||||||
if b.OpValidation {
|
if b.OpValidation {
|
||||||
|
log.Printf("[TRACE] backend/local: running validation operation")
|
||||||
validateDiags := tfCtx.Validate()
|
validateDiags := tfCtx.Validate()
|
||||||
diags = diags.Append(validateDiags)
|
diags = diags.Append(validateDiags)
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,7 @@ type Context struct {
|
||||||
// If the returned diagnostics contains errors then the resulting context is
|
// If the returned diagnostics contains errors then the resulting context is
|
||||||
// invalid and must not be used.
|
// invalid and must not be used.
|
||||||
func NewContext(opts *ContextOpts) (*Context, tfdiags.Diagnostics) {
|
func NewContext(opts *ContextOpts) (*Context, tfdiags.Diagnostics) {
|
||||||
|
log.Printf("[TRACE] terraform.NewContext: starting")
|
||||||
diags := CheckCoreVersionRequirements(opts.Config)
|
diags := CheckCoreVersionRequirements(opts.Config)
|
||||||
// If version constraints are not met then we'll bail early since otherwise
|
// If version constraints are not met then we'll bail early since otherwise
|
||||||
// we're likely to just see a bunch of other errors related to
|
// we're likely to just see a bunch of other errors related to
|
||||||
|
@ -175,6 +176,7 @@ func NewContext(opts *ContextOpts) (*Context, tfdiags.Diagnostics) {
|
||||||
if opts.ProviderSHA256s != nil && !opts.SkipProviderVerify {
|
if opts.ProviderSHA256s != nil && !opts.SkipProviderVerify {
|
||||||
reqd.LockExecutables(opts.ProviderSHA256s)
|
reqd.LockExecutables(opts.ProviderSHA256s)
|
||||||
}
|
}
|
||||||
|
log.Printf("[TRACE] terraform.NewContext: resolving provider version selections")
|
||||||
providerFactories, err = resourceProviderFactories(opts.ProviderResolver, reqd)
|
providerFactories, err = resourceProviderFactories(opts.ProviderResolver, reqd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
diags = diags.Append(err)
|
diags = diags.Append(err)
|
||||||
|
@ -189,6 +191,7 @@ func NewContext(opts *ContextOpts) (*Context, tfdiags.Diagnostics) {
|
||||||
provisioners: opts.Provisioners,
|
provisioners: opts.Provisioners,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("[TRACE] terraform.NewContext: loading provider schemas")
|
||||||
schemas, err := LoadSchemas(opts.Config, opts.State, components)
|
schemas, err := LoadSchemas(opts.Config, opts.State, components)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
diags = diags.Append(err)
|
diags = diags.Append(err)
|
||||||
|
@ -205,6 +208,8 @@ func NewContext(opts *ContextOpts) (*Context, tfdiags.Diagnostics) {
|
||||||
config = configs.NewEmptyConfig()
|
config = configs.NewEmptyConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("[TRACE] terraform.NewContext: complete")
|
||||||
|
|
||||||
return &Context{
|
return &Context{
|
||||||
components: components,
|
components: components,
|
||||||
schemas: schemas,
|
schemas: schemas,
|
||||||
|
|
Loading…
Reference in New Issue