The competition between Iran and Turkey for regional Islamic hegemony has been in the open for decades, since the fall of the Soviet Union. The first element of that competition then became the former majority Soviet states: Kazakhstan, Kirghizstan, Uzbekistan, Azerbaijan, Turkmenistan along the ancient Silk Road - and connecting with the eastern portion of China.
Once one or the other gained a foothold, the next step was to use that basis to gain preeminence over all Islamic states and begin the push to reclaim the rest of the "Ummah" for Islam and from there the world.
Turkey stopped being an ally and friend the moment Erdogan gained power.