I've seen Iran is being viewed as a rival by practically every Sunni state so how come Iran maintains good ties with turkey despite it having a substantial Sunni population? I would be grateful if you could help explain this, if possible, delineating the reasons. Thank you
"Good friends" may be an exaggeration, but "the enemy of my enemy is my friend" probably explains some of that. Turkey (or rather Erdogan) sees itself/himself as the leader of the Islamic/Sunni world (and this puts it at odds with Iran somewhat) but even more so with Iran's other Islamic/Sunni enemies, namely Saudi Arabia and the UAE. For example, Turkey and the UAE are engaged in a proxy war in Libya now (on opposite sides). In Egypt, Turkey and Iran backed the same (losing) side [the Muslim brotherhood] against the (winning) side backed by the Saudis and UAE (el-Sisi).
Likewise, Turkey and Iran also have the Kurds as a common enemy. Iran (and its proxies) fought against the Kurds in Iraq fairly recently for example (2017), and Turkey invaded northern Syria for the same reason. Like Turkey, Iran also has a Kurdish minority in its own territory. There's a PKK equivalent/wing in Iran, the PJAK.
There are some counterpoints to all this, namely the Turkey-Iran divergence on Syria's future, but it still seems that their respective proxies have not really fought each other much over there. And officially both are engaged in the Astana peace process (to the exclusion of the SDC/YPG--Syria's main Kurdish party).
Also, prior to the current US sanctions, Iran was single largest supplier of oil to Turkey
Turkey, where the demand for energy is enormous, relies heavily on cheap imports of oil and gas. Its energy requirements have grown faster than any other OECD state since 2002, at 5.5% a year. Iran is one of its main sources, supplying 44.6% of Turkish crude oil imports and 17% of its natural gas imports in 2017.
As an Arab and a Muslim, from the middle east , in simple terms the sunni-shia conflict only exist in the US media and their Allies in English speaking media , I have never heard the term in Arabic media,
so simply, there is no sunni - shia hostility , only propaganda
if you want to know more here is why
the term became popular after the US invasion of Iraq, before that we never asked or cared to know what sect of Islam our neighbors were mixed marriages were common and still in SA and Bahrain people are mixed (As opposite to Iraq were they became segregated )
the US used the "divide and rule" trick to split the Iraqi resistance after the invasion, calming Iraqi shia's are a thread and being sponsored by Iran . the rest The U.S. Role in Iraqs Sectarian Violence - FPIF
the only countries that might hint to such an issue, Saudi, Bahrain (were the royal density trying to show the popular movement asking for democracy as a shia based revolt, even though the leaders are sunnis )
it is better than saying The US/Israel and their is followers -allies in political terms -Vs the US/Israel opposed countries
on Iranian , Turkish , Syrian , Tunisian , Sudan TV channels for example those countries that do not align with the US policy are called ( Resistance Front , Axis of Resistance , Rejectionist Front )