There was nothing surprising about the terrorist attack that took place at Ataturk Airport in Istanbul this past Tuesday. The Turks have suffered a number of attacks this year that were similar in nature, and the Turkish authorities are fully aware that more attacks will probably take place before the year is over, since Turkish intelligence has reported that it knows of at least 35 ISIS fighters living on Turkish territory.Over the years, Turkey has supported and assisted ISIS quite a bit.ISIS members have crossed over Turkey’s borders, smuggled weapons, and Turkey has purchased oil from wells controlled by ISIS. Turkey had a clear interest in supporting these activities and had plans to become the leader of a Muslim empire that would rule over all of the Middle East.ISIS fighters might have had similar aspirations, but what Turkey didn’t understand was that ISIS was not a group that could be controlled. Neither did they foresee the pressure Turkey would receive from NATO – of which Turkey has been a member since 1952 – to cease its association with ISIS.All of these pressures forced Turkey to switch its allegiance against its will. Turkey ceased purchasing oil from and smuggling arms to ISIS, and they began allowing troops from Western countries to use its border as a base from which they could launch attacks against ISIS.But ISIS fighters still seem to be getting across the border pretty easily, and the Turkish authorities seem to be using only minimal resources to exert control. ISIS fighters who used to move freely among Turkey, Syria and Iraq seem to be using Turkey as a home base.Turkey is currently paying the price for cooperating with ISIS and the freedom of movement it allowed ISIS fighters. Up until now, Turkish intelligence officials did not consider ISIS an opponent, so as a result, they never gathered any information about the organization and its activists in Turkey were never identified or located. They never searched for potential safe houses where ISIS might be hiding activists or weapons, and they didn’t bother looking for possible signs of terrorist activity. Interior counterintelligence units need to know how to respond to and locate such activity in advance. In order to carry out a large-scale terrorist attack, a number of activists must collaborate, purchase weapons, explosives, and prepare a detailed plan. Any decent intelligence agency would have found clues about some of these actions during the planning stages prior to an attack.The Turks, unfortunately, have lost a lot of time during the years when they let ISIS operate under their noses without taking any interest in what’s going on. It takes many years for an intelligence agency to build itself up and reach a high level of capability. It needs to learn how to recruit agents, carry out surveillance, utilize technological devices and carry out arrests and interrogations. The Turkish intelligence agency is just beginning to learn how to carry out these steps.ISIS, on the other hand, is continuing to do what it’s good at. Despite the numerous military defeats it’s suffered in the field, and its diminished military strength in comparison with western military forces stationed in the region, Hezbollah, and Jabhat al-Nusra, ISIS has no problem sending a few fighters to carry out an attack in a busy city in a neighboring country, since they come across no resistance at border crossings.In other words, ISIS can continue carrying out attacks like it did this week at Ataturk Airport.The Turkish authorities have assessed that there are currently a few dozen ISIS operatives living in the country who are equipped with explosives and bombs and are prepared to carry out another attack at any given moment.The Turkish defense establishment must act quickly to hermetically seal its eastern border and prevent the illegal movement of terrorists.This will be a long and expensive process, but it is necessary if they want to wrest control over their territory.Their initial premise – that ISIS would not carry out attacks against innocent Turkish citizens – was shown to be a dismal failure. Reality has shown us that ISIS only sees black and white – you are either in favor of a Muslim caliphate or you are against one. Everyone is expendable in this war. It will be extremely difficult for Turkey to build up a working intelligence system over the next two years if they cannot first control which people are allowed to cross over their border.The Turkish government understands the trap it has found itself in. It also knows that the chances of winning the sympathy of the people and convincing them to report any suspicious activity are very slim.A large portion of the Turkish people does not agree with the religious extremism that the government has adopted, but another portion still does not understand that ISIS has turned into a bitter enemy of the state.The Turkish government will need to make some difficult decisions soon regarding the way it plans to carry out counterespionage activity against ISIS. It will undoubtedly ask for help and cooperation from its Western allies and its old/new fried, Israel.But even the most optimistic among us know that without dealing with the ISIS operatives who have already established themselves in Turkey, Turkey has no chance to succeed. Even if the Turkish authorities manage to oust almost all of the ISIS operatives, there will still be plenty of terrorist activity they will need to combat over the next few years. They should probably spend some time thinking of less risky and perhaps more expensive alternatives in the coming years.The writer is a former brigadier-general who served as a division head in the Shin Bet (Israel Security Agency).Translated by Hannah Hochner.