One early source is Bereishis Rabba 12:15:
ה' אלהים . למלך שהיו לו כוסות ריקים, אמר המלך אם אני נותן לתוכן חמין הם מתבקעין, צונן הם מקריסין. ומה עשה המלך? ערב חמין בצונן ונתן בהם ועמדו. כך אמר הקדוש ברוך הוא: אם בורא אני את העולם במדת הרחמים, הוי חטייה סגיאין. במדת הדין היאך העולם יכול לעמוד?! אלא, הרי אני בורא אותו במדת הדין ובמדת הרחמים, והלואי יעמוד:
Hashem Elokim. [A parable] for a king who had empty cups. The king said, "If I put hot water in them, they will burst; cold water, they will warp." And what did the king do? He mixed hot water with cold water and put it in them and they remained. So said the Holy One, blessed be He: ""If I create the world with the aspect of mercy, sins will be legion; with the aspect of judgement, how will the world be able to remain?! Rather, behold, I am creating it with the aspect of judgment and with the aspect of mercy, and oh that it remain.
Note that Rashi (verse 1:1) says:
שבתחלה עלה במחשבה לבראתו במדת הדין, ראה שאין העולם מתקיים, הקדים מדת רחמים ושתפה למדת הדין, היינו דכתיב (להלן ב ד) ביום עשות ה' א-להים ארץ ושמים
At first it went up in [G-d's] thought to create [the world] with judgement, he saw that the world cannot last, he prefaced mercy and combined it with judgement, this is what it says "On the day G-d the L-rd created earth and heaven."
The יפה תאר says on the above Bereishis Rabba that the Ba'al HaAkeida has this as the text of Bereishis Rabba itself as a preface to the parable, and that is what the parable about mixing water to the right temperature for cups is coming to explain.
So the conclusion is that Bereishis Rabba is a primary source for many Rishonim, although our text seems to have lost a few lines.