I am amazed people still think in terms of good and evil and friends and enemies. There are NO such concepts in international geopolitics.
USA is doing exactly what Iran and Pakistan are doing: pursuing their own national interests, as best as possible. That is all.
Iran has pursued its own national interests, and it has come to this point that is is under direct attack, without a lot of support from any other country. Geopolitically, that is an abysmal failure, no matter what divine or regious or moral cover one may wish to give it. Now, it must bear the consequences and try to mitigate the situation as best as possible.
All is not lost at this point, however, and compromises are always better for outcomes, for all sides.
(Similarly, Pakistan will be okay if it plays its cards better than what Iran has done. But that discussion belongs in some other thread, not here.)