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.
// indicates one or more inconsistencies between the dependency
// lock file and the provider plugins actually available in the
// local cache directory.
varbufbytes.Buffer
foraddr,err:=rangeerrs{
fmt.Fprintf(&buf,"\n - %s: %s",addr,err)
}
suggestion:="To download the plugins required for this configuration, run:\n terraform init"
ifm.RunningInAutomation{
// Don't mention "terraform init" specifically if we're running in an automation wrapper
suggestion="You must install the required plugins before running Terraform operations."
//
// If initialization is allowed, we ignore this error, as it may
// be resolved by the later step where providers are fetched.
if!opts.Init{
varbufbytes.Buffer
foraddr,err:=rangeerrs{
fmt.Fprintf(&buf,"\n - %s: %s",addr,err)
}
suggestion:="To download the plugins required for this configuration, run:\n terraform init"
ifm.RunningInAutomation{
// Don't mention "terraform init" specifically if we're running in an automation wrapper
suggestion="You must install the required plugins before running Terraform operations."
}
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Required plugins are not installed",
fmt.Sprintf(
"The installed provider plugins are not consistent with the packages selected in the dependency lock file:%s\n\nTerraform uses external plugins to integrate with a variety of different infrastructure services. %s",
buf.String(),suggestion,
),
))
returnnil,diags
}
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Required plugins are not installed",
fmt.Sprintf(
"The installed provider plugins are not consistent with the packages selected in the dependency lock file:%s\n\nTerraform uses external plugins to integrate with a variety of different infrastructure services. %s",