I'm reading a news article (in French) about the resurgence of conflict in Nagorno-Karabakh and I learn that Azerbaijan is predominantly a Shiite country. This, in my understanding of traditional alliances in the region, should technically place them alongside Iran (a Shiite-majority country) and therefore against Israel (in conflict with Iran) and also against Turkey (Sunni-majority country).
Instead, I learn that Israel and Azerbaijan have a 30 year history of arms trade, Turkey supports Azerbaijan militarily (despite recent tensions between Israel and Turkey) and in fact Iran seems more aligned with Armenia.
This upends my understanding of power relations in the region, can someone explain how these alliances came to be?
Edit: Can the downvoter please explain their choice?