diags=diags.Append(fmt.Errorf("unknown backend type %q",backendState.Backend.Type))
returnstate,diags
}
backend=initFn()
schema:=backend.ConfigSchema()
config,err:=backendState.Backend.Config(schema)
iferr!=nil{
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Failed to decode current backend config",
fmt.Sprintf("The backend configuration created by the most recent run of \"terraform init\" could not be decoded: %s. The configuration may have been initialized by an earlier version that used an incompatible configuration structure. Run \"terraform init -reconfigure\" to force re-initialization of the backend.",err),
// We'll lock the backend here to ensure that we don't have any concurrent
// operations on the state. If this fails, we'll return an error and the
// user should retry the migration later when nothing is currently updating
// the state.
id,err:=stateManager.Lock(statemgr.NewLockInfo())
iferr!=nil{
diags=diags.Append(tfdiags.Sourceless(tfdiags.Error,"Failed to lock state",fmt.Sprintf("The state is currently locked by another operation: %s. Please retry the migration later.",err)))
returnstate,diags
}
// Remember to unlock the state when we're done.
deferfunc(){
// Remember to unlock the state when we're done.
iferr:=stateManager.Unlock(id);err!=nil{
// If we couldn't unlock the state, we'll warn about that but the
// migration can actually continue.
diags=diags.Append(tfdiags.Sourceless(tfdiags.Warning,"Failed to unlock state",fmt.Sprintf("The state was successfully loaded but could not be unlocked: %s. The migration can continue but the state many need to be unlocked manually.",err)))