Jim Walsh is a senior research associate in the Massachusetts Institute of Technology's Security Studies Program. His work has focused on nuclear weapons, the Middle East, and Asia. The views expressed here are his own. View more opinion articles on CNN.

(CNN) Since the day he took office, President Donald Trump has been caught in an Iran trap, or more precisely, two traps. The first led the President to withdraw from the Iran nuclear agreement and pursue a "maximum pressure" campaign. The second trap will almost certainly lead to air strikes against Iran's nuclear facilities, perhaps within the year. Following that attack, Iran will likely respond by kicking out international inspectors and going for the bomb.

If that happens, Iran will have gone from the most inspected country in the world and, by all serious accounts, a country that was in compliance with the international nuclear agreement to a country armed with nuclear weapons. Iran will represent the second country to have obtained nuclear weapons in the Middle East, arguably the most dangerous region in the world.

It does not have to turn out that way, but if it does, the outcome will first and foremost be the result of the President's decisions. The Iranian bomb will be his most important legacy as president. After Trump leaves office, after the child internment centers are finally closed, after climate change rules are back in force, Iran will still have the bomb.

So, how did we get there?

The first trap was laid before Mr. Trump took office. Congressional hawks who preferred regime change to diplomacy tried to scuttle the international nuclear agreement. Having failed, they supported a legal process requiring the president to periodically certify that Iran was abiding by its obligations. The agreement's enemies expected Iran to cheat and hoped the certification process would provide a future opportunity for Congress to kill the deal. At that point, in 2015, no one could imagine that Donald Trump would be the next president.

But Trump won the election. And after taking office, it was clear that he hated having to sign the certifications every 120 days, even if every organ of the US government dutifully reported that Iran was keeping its end of the bargain. Certification forced him to stew about President Barack Obama's agreement over and over again. Eventually, it seems, the emotional and impulsive President could take it no more. But Trump was not content with simply withdrawing. Instead, he sought to punish Iran and all the other countries, including America's European allies, who remained in the agreement.

(Last week, the White House issued a head-scratching statement , insisting that "even before the deal's existence, Iran was violating its terms.")

And that's when things started to change. In the beginning, Iran had responded to the American onslaught with its own version of strategic patience. Tehran stayed in the agreement, maintained its compliance, negotiated with the Europeans to mitigate the effects of the sanctions, and let the US diplomatically isolate itself -- evidently planning to wait things out. The Iranians have now shifted strategy. Rather than lying on the ground waiting to be kicked again, they are pushing back. Iran is not looking to provoke a war -- a war it would surely lose -- but it will raise the cost of Trump's "maximum pressure" policy.

Oil tankers have been disabled and a drone shot down (the US has blamed Iran for the former, which it denies, and the two countries have disputed the specifics of the latter incident), but the heart of Iran's new strategy revolves around its civilian nuclear program. Step by step, starting with smaller actions and progressing to more consequential ones, Iran is backing away from the restrictions specified in the agreement. President Hassan Rouhani emphasized that these actions are reversible , if the US rejoins the international agreement, but it is difficult to imagine Trump will do so.

So, now the President finds himself in a second trap, this one of his own making. Instead of periodic certifications, he will now face periodic Iranian announcements about changes in the nuclear program. Every 60 days, perhaps, the President will have to respond to Iran's moves. The administration can impose more sanctions, but it cannot prevent Iranian engineers from increasing uranium enrichment levels. Each Iranian announcement will make the President appear impotent, and those around him will push for military strikes, as they did after the downing of the drone.

And at some point, it's fair to assume Trump will give the order for a military strike, but it won't be rescinded like it was last time. The President's recent comments provide a clue to why this outcome is likely. "I'm not talking boots on the ground," Trump said , when asked about military strikes against Iran. "I'm just saying if something would happen, it wouldn't last very long." The comment was a clear allusion to the potential use of airstrikes, rather than ground troops. "I don't need exit strategies," Trump said on another occasion.

Students of warfare will recognize in the President's comments the familiar hallmarks of past military blunders. The war will be quick. The war will be easy. The costs will be negligible and the benefits enormous. The war will be an in-and-out, clean affair. No muss, no fuss, no exit strategy required.

The President's broken national security process -- there is no confirmed secretary of defense -- is now dominated by men who have previously advocated for regime change in Iran , so it is not surprising that the President has a rosy picture of war. The seduction of supposedly sanitized air power is strong, especially for presidents who want to use military force but fear that it will be messy.

What Trump does not realize is that an air war against Iran will almost certainly -- by design or by default -- end up hitting the country's internationally inspected nuclear facilities. And by attacking Iran's nuclear infrastructure, the President will produce the very result he hoped to avoid: Iran will acquire nuclear weapons.

An Iranian decision to go for the bomb would reflect Iran's sense of pride and humiliation and public demands that the government defend the nation. In Iran, any remaining advocates of diplomacy will be pushed out of the way, discredited by the American President.

Building the bomb would be consistent with the psychology and politics of the moment, but it would also be in line with what scholars have learned about past preventive strikes aimed at nuclear programs. The most studied case is the Israeli bombing in 1981 of Saddam Hussein's Osirak nuclear reactor.

At the time, Saddam had a rather rudimentary nuclear-weapons effort and had even imprisoned his most important nuclear scientists. Post attack, the Iraqi leader made nuclear weapons a top priority and pushed intensively, if not efficiently, to build the bomb. As Målfrid Braut-Hegghammer , the leading scholar on Hussein's nuclear efforts, points out, "... on the eve of the attack on Osirak ... Iraq's pursuit of a nuclear weapons capability was both directionless and disorganized." The attack galvanized the Iraqi government and "triggered a well-funded covert program to produce nuclear weapons."

In short, it was the political effect of the bombing, not the military consequences, that mattered most.

Iraq had a modest nuclear infrastructure. Iran, on the other hand, can build a nuclear weapon if it chooses to, according to the 2016 US National Intelligence Assessment . After all, Iran knows how to build a centrifuge. It built 19,000 of them . And no matter how many airstrikes the US launches, America cannot bomb the knowledge of how to build a centrifuge out of heads of Iranian scientists.

US planes will fly. Hopefully, they will all return safely. The cost will come not from mission casualties or even from Iranian retaliation. The real payment will come due if and when there is a nuclear war in the Middle East.

Is there a way out of the trap? Yes. The President can begin to quietly ratchet down his maximum pressure campaign, for example, by issuing waivers on oil sanctions. He can find third parties to communicate with the Iranians. He does not have to be Iran's friend, but he cannot continue to back Iran into a corner. If he doesn't alter course, he can expect periodic reminders from the Iranians that they have cards to play -- nuclear cards. Can Trump change direction before it is too late? Yes. Will he; will he give up the fantasy of quick and easy military strikes without consequences? Will he realize that the pressure policy is leading him to war, that he is getting played his advisers? Maybe.

If not, history will remember Mr. Trump for one thing above all else: as the man who birthed the Iranian bomb.