As described here: http://mesosyn.com/myth2h-2.html
I've found the info that it comes from Brahmavaivarta Purana but this doesn't seem right as I've scanned through it and haven't found it.
Hinduism Stack Exchange is a question and answer site for followers of the Hindu religion and those interested in learning more about Hinduism. It only takes a minute to sign up.Sign up to join this community
The story is described in BrahmaVaivarta Purana, Krishna Janma khanda chapter 47. Chapter is named as 'Shattering pride of Indra.' Lord Vishnu takes the form of a Brahmana boy and teaches lesson of impermanence to Indra. Some verses from that chapter are:
Brahmana said: O Hari!, I have come to meet you after coming to know about the construction of this astonishing city and to ask you some important questions.
What is the time schedule fixed for the construction of this city or otherwise for how long Visswakarma would be engaged in the construction work.
No Indra has so far resorted to this type of construction. No other Vishwakarma would be competent enough to carry out such a type of construction.
On hearing the words of the boy, Indra getting arrogant because of the immense riches, laughed and enquired from the boy again.
"O boy how many Indras have you seen so far or heard about them and how many type of Vishwakarma? You kindly let me know in detail.
O best of the gods even if one is able to count particles of dust on earth in spite of that number of Indras can't be counted. This is the opinion of intellectuals.
Brahmana said "O Indra, I have created the entire group of the ants, one by one, all these ants had been established on a throne of Indra one by one. All of them after having been born in various yugas have currently been born as ants.