Yes, there is a risk of terrorism in Spain.  This is due to the presence of terrorist cells affiliated to ISIS and Al-Qaeda who have the capability to conduct attacks in the region.  The most recent significant attack was in Barcelona in 2018.  The terrorist threat is still a concern and extreme caution is advised while traveling to Spain.