The way I understand it, at the end of WWII the United States was the only country in the world with nuclear weapons, the Manhattan Project was one of their most top-secret projects, and the raw materials for nuclear weapons are extremely difficult and time consuming to produce. Was it a surprise when the US government found out Russia was nuclear capable?
You seem to have two different questions in here. One is the title one. The answer is: despite their ravaging by the war, after Hiroshima, Stalin made creating an atomic bomb a top priority. The project (headed by Beria, who also ran the secret police and the Gulag system) was able to take as much as it needed to succeed. It was an incredibly difficult effort, had about the same number of people as the Manhattan Project (500-600,000 or so), and may (by some metrics) have cost more in terms of money. It had the advantage of knowing that an atomic bomb could be made (something the Manhattan Project did not know for sure when it began) and, through both espionage and published information, had some idea of the ways that the Americans had pulled it off (though, as I discussed in a recent thread, they didn't apply that espionage data very efficiently, because they didn't entirely trust it).
In the end it took them about 4 years to get a bomb from committing to building one (the Manhattan Project was about 2.5 years), which is pretty good time. The main bottleneck for the timing was acquiring the raw materials, specifically the thousands of tons of uranium ore necessary.
Your second question is that of the surprise. In 1945, the most common estimates as to when the USSR would be able to produce a bomb put the lowest date at 5 years. This was not particularly informed — it was something of a blind guess based on assumptions about Soviet scientific and industrial capabilities, with the knowledge that known uranium resources in the USSR were pretty scant. The US had enough foresight to set up an airborne monitoring program in 1949 that "sniffed" the air at the borders of the USSR, looking for tell-tale signs (radioactive isotopes) of an atomic bomb. In September 1949, they found them.
Was it a surprise? For some, sure. President Truman thought the Soviets would never get a bomb (and he never really believed they had set one off, either! As late as 1953 he thought it was a reactor that blew up, never mind that the experts can tell the difference from the radioactive signatures). Some had thought it would take 15-20 years for them to get a bomb. Even those who thought it was 5 years — who were pretty close to being right, but off a year — generally did not update their "count." So in 1945, they said the USSR will have a bomb in 5 years; in 1946, in 5 years; in 1947, in 5 years; in 1948, in 5 years; in 1949... the Soviets were five years early! Well, no. They had been working on it the whole time, obviously.
The most common response to the initial reaction from experts was to say, well, we told you they'd get it eventually — this is within the range of their expectations. They did not attribute it to espionage (or "stealing" or getting the bomb "early") until after Klaus Fuchs was arrested, in February 1950. Then the narrative changed to one about the Soviets "stealing" the bomb and "saving" years on its development (though historians have found this is not quite as simple as that, as noted).
My favorite discussion of this very topic is in Michael Gordin's Red Cloud at Dawn, a lot of which is about the question of the US reaction to the detection of the first Soviet bomb test.