In answering this question, we need to establish a couple of points. I assume you are referring to World War II. We also must clarify what is meant by the word “ally" in this answer.
In 1939, the Soviet Union and Germany signed a non-aggression pact. In this agreement, both sides agreed not to fight each other in World War II. However, this really wasn’t an alliance because both sides also weren’t going to be helping each other during the war. Germany was interested in signing this agreement so they could concentrate on fighting the Allies in Western Europe. Germany understood fighting a two-front war was a difficult thing to do. However, in 1941, Germany broke this agreement and invaded the Soviet Union. Germany didn’t learn from her past mistakes.
In 1917, during World War I, the Soviet Union signed the Treaty of Brest-Litovsk with Germany. In exchange for Germany leaving the Soviet land, Russia agreed to give Germany land. This took the Soviet Union out of the war, creating a one-front war for Germany. This was not an alliance, however. Germany and the Soviet Union agreed to stop fighting each other with this treaty. They were not directly helping each other.
Depending on how you define the term “ally” and to which war you are referencing, there are a few ways to answer this question. In 1917 and 1939, there were agreements between Germany and the Soviet Union. However, these weren't alliances since each side was not directly helping the other side.