Clearly this was not about attacking someone that's attacking you or military assets. This was about leverage. Attacking civilians and civilian infrastructure of countries that are assumed to have some lever over the US to force it to stop while at the same time are too weak or too afraid to defend themselves (which is why you did not see the same scale of attacks e.g. against Turkey despite it also hosting the US). It's a tactic. It's also a war crime.
Iranian strategy in this war will be studied for ages.
Russia is the aggressor there, and I don't recall Ukraine targeting other countries with Russian bases. Also, the war in Ukraine is about Russia expanding territory so it involved boots and occupation since day one, which is not the case in Iran.