log.Printf("[TRACE] UpgradeResourceState: can't downgrade state for %s from version %d to %d",addr,src.SchemaVersion,currentVersion)
vardiagstfdiags.Diagnostics
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Resource instance managed by newer provider version",
// This is not a very good error message, but we don't retain enough
// information in state to give good feedback on what provider
// version might be required here. :(
fmt.Sprintf("The current state of %s was created by a newer provider version than is currently selected. Upgrade the %s provider to work with this state.",addr,providerType),
))
returnnil,diags
}
// If we get down here then we need to upgrade the state, with the
// provider's help.
// If this state was originally created by a version of Terraform prior to
// v0.12, this also includes translating from legacy flatmap to new-style
// representation, since only the provider has enough information to
// understand a flatmap built against an older schema.
log.Printf("[TRACE] UpgradeResourceState: upgrading state for %s from version %d to %d using provider %q",addr,src.SchemaVersion,currentVersion,providerType)
req:=providers.UpgradeResourceStateRequest{
TypeName:addr.Resource.Resource.Type,
// TODO: The internal schema version representations are all using
// uint64 instead of int64, but unsigned integers aren't friendly
// to all protobuf target languages so in practice we use int64
// on the wire. In future we will change all of our internal
fmt.Sprintf("The %s provider upgraded the state for %s from a previous version, but produced an invalid result: %s.",providerType,addr,tfdiags.FormatError(err)),