That was not the only reason. Several military analysts have said Iran is capable of much worse. Iran has also threatened much worse if Israel retaliates.
Iran launched slow attack drones that take hours to arrive on target. And announced the attack as they were launching them.
Then they waited a couple hours and launched around 100 ballistic missiles with small conventional war heads on them. Ballistic missiles take 12 mins to go from Iran to target in Israel. The USAF, RAF, IAF and JAF were scrambled and their jets knocking out the drones, so it was not too difficult to also knock out the ballistic missiles as the joint air forces were already there and active.
Iran could have sent several hundred lethal radioactive dirty bomb armed ballistic missiles with no warning at all. They could wipe Tel Aviv off the map. They showed restraint. This isn’t to be applauded, this is just fact that Israel is still under threat from Iran.