“The reason Russia was in Afghanistan was because terrorists were going into Russia.”
This is simply not true. The Soviet Union ventured into Afghanistan as part of its effort to prop up communism abroad, not because terrorists were striking the Soviet homeland.
“The most shameless Soviet propagandist never claimed that Afghan terrorists were attacking Russia,” said Barnett Rubin, an Afghanistan expert at New York University. “You can read all Soviet media in the 1980s and never find anything this ridiculous.”
There was ultimately a problem with extremism in Afghanistan, but it developed largely after the USSR left, and the mujahideen groups that sprang up to fight the Soviets devolved into the Taliban.