cli: Fix init failure with deleted cache

The init command needs to initialize a backend, in order to access
state, in turn to derive provider requirements from state. The backend
initialization step requires building provider factories, which
previously would fail if a lockfile was present without a corresponding
local provider cache.

This commit ensures that in this situation only, errors with the
provider factories are temporarily ignored. This allows us to continue
to initialize the backend, fetch providers, and then report any errors
as necessary.
This commit is contained in:
Alisdair McDiarmid
2021-10-21 08:44:26 -04:00
parent 1190b95fe2
commit 39de3ebec7
3 changed files with 29 additions and 25 deletions

View File

@@ -238,7 +238,7 @@ func (c *InitCommand) Run(args []string) int {
// by a previous run, so we must still expect that "back" may be nil
// in code that follows.
var backDiags tfdiags.Diagnostics
back, backDiags = c.Backend(nil)
back, backDiags = c.Backend(&BackendOpts{Init: true})
if backDiags.HasErrors() {
// This is fine. We'll proceed with no backend, then.
back = nil