mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
command: Do CLI init of backend loaded from plan
If we don't do this, we can't produce any output when applying a saved plan file. Here we also introduce a check to the local backend's ReportResult function so that it won't panic if CLI init is skipped, although that will no longer happen in the apply-from-file case due to the change described in the previous paragraph.
This commit is contained in:
parent
2b80df0163
commit
cbc548eb36
@ -408,7 +408,15 @@ func (b *Local) ReportResult(op *backend.RunningOperation, diags tfdiags.Diagnos
|
|||||||
} else {
|
} else {
|
||||||
op.Result = backend.OperationSuccess
|
op.Result = backend.OperationSuccess
|
||||||
}
|
}
|
||||||
b.ShowDiagnostics(diags)
|
if b.ShowDiagnostics != nil {
|
||||||
|
b.ShowDiagnostics(diags)
|
||||||
|
} else {
|
||||||
|
// Shouldn't generally happen, but if it does then we'll at least
|
||||||
|
// make some noise in the logs to help us spot it.
|
||||||
|
if len(diags) != 0 {
|
||||||
|
log.Printf("[ERROR] Local backend needs to report diagnostics but ShowDiagnostics callback is not set: %s", diags.ErrWithWarnings())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Colorize returns the Colorize structure that can be used for colorizing
|
// Colorize returns the Colorize structure that can be used for colorizing
|
||||||
|
@ -159,6 +159,19 @@ func (m *Meta) BackendForPlan(settings plans.Backend) (backend.Enhanced, tfdiags
|
|||||||
configureDiags := b.Configure(configVal)
|
configureDiags := b.Configure(configVal)
|
||||||
diags = diags.Append(configureDiags)
|
diags = diags.Append(configureDiags)
|
||||||
|
|
||||||
|
// If the backend supports CLI initialization, do it.
|
||||||
|
if cli, ok := b.(backend.CLI); ok {
|
||||||
|
cliOpts := m.backendCLIOpts()
|
||||||
|
if err := cli.CLIInit(cliOpts); err != nil {
|
||||||
|
diags = diags.Append(fmt.Errorf(
|
||||||
|
"Error initializing backend %T: %s\n\n"+
|
||||||
|
"This is a bug; please report it to the backend developer",
|
||||||
|
b, err,
|
||||||
|
))
|
||||||
|
return nil, diags
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If the result of loading the backend is an enhanced backend,
|
// If the result of loading the backend is an enhanced backend,
|
||||||
// then return that as-is. This works even if b == nil (it will be !ok).
|
// then return that as-is. This works even if b == nil (it will be !ok).
|
||||||
if enhanced, ok := b.(backend.Enhanced); ok {
|
if enhanced, ok := b.(backend.Enhanced); ok {
|
||||||
|
Loading…
Reference in New Issue
Block a user