Turkey has a long history of military coups.
When Ataturk created Turkey from the ashes of the Ottoman empire in the early 1900s, aside from genociding Armenians he wrote into the constitution that the ruling government must be secular. This means that if a government acts in a manner which is too religiously motivated, the military have a duty to stage a coup.
Erdogan's rule has clearly tended towards an Islamic rule, as prohibited by the constitution.
This coup has been coming. I've heard that the coup leaders are citing 'increased terrorism', however I doubt that this is a response to yesterdays attack in Nice, they wouldn't have had the time to prepare.