My opinion is that Eru knew what he was doing, and deliberately created Melkor.
'And thou, Melkor, shalt see that no theme may be played that hath not its uttermost source in me, nor can any alter the music in my despite. For he that attempteth this shall prove but mine instrument in the devising of things more wonderful, which he himself hath not imagined.'
'And thou, Melko, shalt see that no theme may be played that has not its uttermost source in me, nor can any alter the music in my despite. For he that attempts this shall but aid me in devising things yet more wonderful, which he himself has not imagined. Through Melko have terror as fire, and sorrow like dark waters, wrath like thunder, and evil as far from my light as the uttermost depths of the dark places come into the design. In the confusion of sound were made pain and cruelty, devouring flame and cold without mercy, and death without hope. Yet he shall see that in the end this redounds only to the glory of the world, and this world shall be called of all the deeds of Ilúvatar the mightiest and most lovely.'
-The Lost Road, similar passage
I think the idea is that through evil, good/beauty becomes more magnificent and more appreciated.