code: func (r *Resource) checkSchemaVersion(is *terraform.InstanceState) (bool, int) {
  	// Get the raw interface{} value for the schema version. If it doesn't
  	// exist or is nil then set it to zero.
  	raw := is.Meta["schema_version"]
  	if raw == nil {
  		raw = "0"
  	}
  
  	// Try to convert it to a string. If it isn't a string then we pretend
  	// that it isn't set at all. It should never not be a string unless it
  	// was manually tampered with.
  	rawString, ok := raw.(string)
  	if !ok {
  		rawString = "0"
  	}
  
  	stateSchemaVersion, _ := strconv.Atoi(rawString)
  
  	// Don't run MigrateState if the version is handled by a StateUpgrader,
  	// since StateMigrateFuncs are not required to handle unknown versions
  	maxVersion := r.SchemaVersion
  	if len(r.StateUpgraders) > 0 {
  		maxVersion = r.StateUpgraders[0].Version
  	}
  
  	return stateSchemaVersion < maxVersion, stateSchemaVersion
  }
docs: // Determines if a given InstanceState needs to be migrated by checking the
  // stored version number with the current SchemaVersion