My question somewhat parallels this question. There is one important difference however. In June 1941, Germany and Britain glared at each other across the English Channel, but there was no more land fighting between them in Europe after the Balkans campaign, and only minimal air and sea contact. (Hitler was fighting Britain in North Africa, but even there he "chose to" rather than "had to.") In 1812, on the other hand, Napoleon was still embroiled in the Peninsular War in Spain, which he described as an "ulcer."
The war in Spain was finely balanced, which suggests that Napoleon could have won it, if he had refrained from invading Russia. Why not throw the Grande Armee into Spain in 1812 instead? Even Hitler (much to his annoyance) refrained from attacking the Soviet Union while the Balkans campaign was in progress.
What caused him to choose to invade Russia before winning an ongoing war in Spain? There were some provocations, such as Russia's surreptitiously trading with the British, etc. But were there any existential threats comparable to the one that existed in Spain? Was there a plausible fear, for instance, that if he didn't attack Russia, that Russia would attack him? Or could it have been a case that the dangers of fighting a two front war were less understood than they were a century later?
Clarification
I am going to make explicit an intention that I had earlier only hinted at, that I am asking for "rational" reasons (if any) that Napoleon attacked Russia in 1812 (rather than later after the end of the Peninsular War). These reasons need not be "rational" with hindsight, only with what was believed in the context of the time; e.g. a fear of a preemptive Russian attack or a misunderstanding of a two front war (countries were more inclined to engage in them in the 18th rather than 20th century). What was the "conventional wisdom" at the time about an attack on Russia, given the experience of Charles XII of Sweden, but without the benefit of Hitler's or Napoleon's (later) experience? I am not seeking answers along the lines of "Napoleon was crazy" unless you make a case that rules out "rational" motives.