(CNN) Two years ago, Turkey declared it would buy Russia's S-400 missile defense system because the United States had dragged its feet in selling an American alternative.

But the deal, worth about $2 billion and consummated this week , has consequences far beyond the cost to Ankara's defense budget

It calls into question the decades-long strategic relationship between Turkey and the US, and even Turkey's credentials as a NATO member. It probably nullifies a massive contract for Turkey to buy US F-35 combat aircraft -- a plane the S-400 is designed to shoot down.

The deal also solidifies a deepening relationship between Turkey's President Recep Tayyip Erdogan and his Russian counterpart Vladimir Putin -- two leaders with little time for dissent at home and who need each other in Syria. And it provides the Turkish armed forces with an advanced weapon capable of covering most of Syria and their old adversary Greece (also a NATO member.)

The S-400 can shoot down aircraft at a distance of up to 150 miles (240 km) and intercept ballistic missiles up to 38 miles away.

In essence it is a destabilizing purchase in a region that could do without any more destabilizing. It is also an assertion by Turkey of its independence as a major regional power.

The US has warned Turkey it may face economic sanctions for purchasing the S-400 defense sytems.

Tension between Turkey and US

Erdogan and the United States have been at odds for years. The Turkish President said the US had protected Fethullah Gulen , the cleric (and Pennsylvania resident) he blames for an attempted coup in 2016. Erdogan declared: "The coup plotter is in your country. You are nurturing him there. It's out in the open."

Erdogan and other senior members of his ruling Justice and Development Party (AKP) have often played to anti-American sentiment among the party's conservative, nationalist base.

Erdogan was also infuriated by the US alliance with the Kurdish militia in Syria -- the YPG -- in the campaign to defeat ISIS. Turkey regards the YPG as a terrorist group affiliated with the PKK, which has fought the Turkish state for more than three decades.

When the US considered training a mainly Kurdish contingent to guard the Turkish border last year, Erdogan tweeted : "The US has now acknowledged that it has established a terror army along our borders."

The tension persists. The two sides can't agree on the establishment of a safe zone for refugees inside northern Syria. And this week, CNN reported that US military intelligence is observing a buildup of Turkish armored units that may be planning cross-border combat operations -- amid growing concerns that US troops operating in northern Syria will be caught in the middle.

"There are some indications" that Turkey is preparing for an "incursion" into Syria, but the intelligence is not yet definitive, one official said.

For its part Washington has been exasperated by prison sentences handed to US citizens in Turkey ( Pastor Andrew Brunson being the most prominent example) and Turkish staff working at the US Embassy -- seeing them as politically motivated. The Trump administration retaliated by imposing sanctions on senior Turkish ministers.

There was also tension over the Saudi response to the murder of journalist Jamal Khashoggi -- and over what was perceived as an ambivalent approach in Ankara to confronting ISIS, especially in 2015-16. Sporadic threats by Turkey to close the US airbase at Incirlik have been another irritant.

But all these difficulties pale in comparison to the fallout from the S-400 deal. Even before the first deliveries, the US warned that Turkey would be suspended from the F-35 combat jet program and stopped training its pilots.

Erdogan has said that excluding Turkey from the F-35 program would be "robbery," since Ankara has already invested more than $1 billion in the consortium building it. Altogether it planned to buy 116 planes.

The US also threatened new sanctions should Turkey complete the S-400 contract, prompting Erdogan to claim on the sidelines of the G-20 summit: "It is out of question between two strategic partners. I think it should not happen."

US President Donald Trump has suggested the sanctions could be diluted, but many in Congress are determined Turkey should be penalized. According to a US federal law (the Countering American Adversaries Through Sanctions Act), the administration must levy at least five different penalties against Turkey. Just how punitive they will be is yet to be seen.

NATO is also concerned that the S-400 deal will affect Turkey's ability to cooperate with other alliance members. "Interoperability of our armed forces is fundamental to NATO for the conduct of our operations and missions," said one official.

Military vehicles and equipment, including parts of the S-400 air defense systems, are unloaded from a Russian transport aircraft in Ankara on Friday, July 12, 2019.

Putin stirs up trouble

Russia is of course delighted that it has not only sold its S-400 to a member of NATO but helped drive a deeper wedge between Turkey and the US. The Turkish purchase is also a great shop window for the Russian defense industry. India is expected to be the next customer for the S-400.

And then there's Syria. President Vladimir Putin seduced Turkey into joining the "Astana" process with Russia and Iran on the future of Syria, essentially sidelining the United Nations and the US. Now, Erdogan needs Russian support to prevent an offensive by the Assad regime against the rebel-held province of Idlib, where Turkey has peacekeeping troops but also backs several rebel factions.

If Turkey wants to have any sway on the future shape of Syria, it has to engage with Russia. Buying the S-400 helped cement a necessary if not necessarily warm relationship.

Above all, the arrival of the first batch of S-400 equipment in Ankara on Friday is the most dramatic instance of a trend that stretches back to the Arab Spring . Erdogan, already in power for more than 15 years, wants to fashion Turkey as an independent and influential power in the region, no longer beholden to the United States and no longer in need of the American nuclear umbrella that protected it for decades.

Russian President Vladimir Putin is delighted to have helped to drive a deeper wedge between Turkey and the US.

Holding out an olive branch Friday, Turkish Defense Minister Hulusi Akar said Turkey was still considering buying US Patriot missiles "to cover our need for a long-range air and missile defense system." He also said the purchase of the S-400 "does not in any way mean a change of [Turkey's] strategic orientation."

But the course of Turkey's strategy seems set.

As Aaron Stein puts it in Foreign Affairs , Erdogan and the AKP "don't think their relationship with Washington is nearly as valuable as Washington seems to think it is."

Taking up the thread, Steven A. Cook, a longtime Turkey watcher, says Ankara "is not the partner it used to be. In the future, U.S. policy should be based on the fact that while Turkey is not an enemy of the United States, it is also not a friend."

And you don't share your best jets with countries that are not your friends.