Good question, and not one that can be given an easy answer.
Following the 1979 revolution, the Soviets looked towards their southern neighbour with no small amount of concern. Grand Ayatollah Ruhollah Khomeini took control of the country and instituted a very strict interpretation of Sharia Law. Iran's new state ideology was at direct odds with that of the secular Soviet Union.
When the Iran-Iraq War broke out, the Soviets began hedging their bets as to which side would be more beneficial to them in the long run. Iraq was a traditional Soviet ally, and they were seen as a secular buffer against the encroachment of Islamic fundamentalism. Therefore, the USSR provided extensive military aid to the Iraqi regime. However, they maintained a certain level of optimism over the possibility that Iran might one day evolve past its theocratic leanings and become a valuable economic partner in the Middle East region. So what did the Soviets do? They provided covert financial assistance to the Iranian government. At the same time, a number of hard-line communist regimes and other Soviet satellite states provided extensive support to Iran; these include North Korea, Libya, Syria, Romania, and Poland, among others. Most of the armaments they provided were originally purchased from either China or the Soviet Union.
In other words, the USSR was double dealing during the war so that they would come out the winner regardless of which side actually won.