OP, some context from the other side might be helpful. Yes, there are fines for American companies if they do business with Iranians. That's how sanctions work as I'm sure you're aware. But the story doesn't stop there. If an American finds out they are transacting with a sanctioned individual, or citizens of a sanctioned country like Iran or North Korea, the stakes go up: $1M USD fine and up to 20 years in federal p…
This is partially true, but not the entirety of the story. There are blanket sanction waivers ( General License ) by OFAC to allow certain things. There's also the possibility to get an OFAC license (as GitHub did.) The real issue is there is little to no advantage (realistically no money to be gained from Iran) or even awareness (sometimes the cloud infrastructure bans Iran by default and you don't have enough users…
Various tools hosted on Github can be considered dual-use (i.e. AES/TLS libraries). Furthermore, Microsoft was made to apply sanctions against Karim Khan of the ICC for his involvement in investigating the genocide of Palestinians; I doubt Microsoft would be granted an exception so they can serve Hamas' greatest supporter after that.
I don't know if Microsoft has applied for any exceptions, but even if they did, I doubt they'd be able to get them. That's on top of the probability of bad publicity ("Microsoft wants to cut deal with Iran") and the lack of incentive you mentioned.