Although the members of the YPG actually did originally come from the Kurdish terrorist organisation PKK, reasonably democratic structures have been established in the Syrian territories it controls, at least compared to other nearby regions. The YPG model of regional self-government, with a high rate of political participation by women, is contrary to just about everything the Turkish government aspires to.
It was clear that Afrin would end up in the Turkish regime's sights once the Kurds set up their own administration there and Syrian dictator Assad's power began to wane.
When the U.S. Secretary of Defence James Mattis came to Turkey in August of last year to co-ordinate the fight against IS with its NATO partner, Erdogan took the opportunity to make it clear that his country would never allow a Kurdish "terror corridor" to arise in Syria. Should such a threat be on the horizon, "we will then intervene", said Erdogan, adding: "We are still resolute with regard to Afrin. Our plans are proceeding as before."
Russia shows solidarity towards Turkey
There are several reasons why it took Turkey five months to carry out those plans after the president had announced an impending offensive. For one thing, the Americans strictly opposed an attack on Afrin last year because they were in dire need of the help of the Kurdish fighters to oust IS from their Syrian stronghold of Raqqa, a battle that had not yet been decided at the time.
In addition, Turkey needed Russian backing or at least its endorsement for an operation against Afrin, in particular for air attacks. Moscow has namely stationed not only an S-400 missile defence system in Syria, but also an unknown number of military observers in Afrin.