Iran activated their assets in Iraq to target Americans:
For three days in a row this week, rockets have been fired at areas where U.S. forces or U.S. interests are located in Iraq. On Monday, rockets targeted Camp Taji, where the U.S.-led coalition against ISIS is training Iraqi security forces. On Tuesday, more rockets were fired at a compound in Mosul where U.S. troops are based. Then, another attack on Wednesday struck an oil facility near where ExxonMobil has employees.
Shia Iran has had influence in mostly Shia Iraq for a long time. Saddam's minority Sunni Arab regime naturally led oppressed Iraqi Arab Shias to look to Shia Iran for support. Saddam ordered the invasion of revolution-wracked Iran because of that influence, believing the chaos in Iran gave Iraq an opportunity to knock Iran down.
The 1991 Persian Gulf War weakened Saddam and gave Iran an opportunity to expand influence, but Saddam put down Shia uprisings in the south following the war.
And in 2003 when the U.S.-led invasion overthrew Saddam, the now dominant majority Shias were freed from Sunni oppression. By linking up with jihadis funneled in from Syria, Iran began the process of alienating Iraqi Arab Shias from Shia--but Persian--Iran; and also getting the Sunni Arabs to rethink their insurgency and terrorism because of the proxy invasion of Iraq orchestrated by Iran.
That post foreshadowed the Awakening that flipped the Sunni Arabs and also the fight against the pro-Iran Shia death squads. The Iraqi Kurds were already--since 1991--with America. So we had a solid base of support in Iraq by 2011.
Unfortunately, following our battlefield victory, our troops were ordered out of Iraq at the end of 2011. In our absence, Iranian influence increased in the vacuum, and the quality of Iraq's officer corps declined greatly as Iraq's leaders selected officers for loyalty--to resist that Iranian influence and the threat of coups--rather than competence. And the Iraqi government alienated the Sunni Arabs to fight for influence in the majority Shias who (rightly, it must be admitted) resented the Sunni Arab history of oppression and the more recent terror campaign under al Qaeda.
As a result, the revival of al Qaeda as ISIL took place, and the 2014 uprisings in the north and west succeeded as the enfeebled Iraqi security forces--because of lack of leadership--collapsed in the face of the widespread attacks in June.
Iranian influence was further expanded as Iran stepped into the gap to form militias to replace the army and police forces that disappeared in the blink of an eye.
America at least reacted to this mistake of leaving by entering Iraq War 2.0 in late 2014. It took several years, but the ISIL caliphate that spanned Iraq and Syria was finally broken up, with the Battle for Mosul the epic campaign that signaled the destruction of the caliphate in Iraq.
American forces have remained in Iraq to continue the training of Iraqi forces and to bolster Iraq's ability to claw back control of the Iranian-controlled or influenced militias; and, yes, to watch Iran from our positions in Iraq.
Unfortunately, that Iranian influence is still strong enough to get local forces to launch rockets at American targets in Iraq.
It will take time and effort to allow Iraqi Shias to more fully feel like Arabs despite the fact that most of the Arab world is Sunni rather than identify as Shias who need fellow Shia--but Persian--Iran for support.
America must remain in Iraq to provide that support and to provide the assurance that leadership in Iraq will be decided by ballots and not bullets, which allows the leadership the luxury of supporting a competent officer corps rather than one selected for loyalty.
That outcome will be a serious defeat for Iran.
UPDATE: Iran needs ISIL to justify Iran's presence in Iraq; and ISIL needs Iran to piss off Shias enough to support the remnants of ISIL in Iraq.