The U.S. ambassador to Estonia says he will resign late next month, making him the third U.S. ambassador to step down in 2018.

In a private Facebook message shared with NBC News by a former U.S. official, U.S. Ambassador James D. Melville Jr. said he will retire on July 29. The announcement was first reported by Foreign Policy magazine.

"A Foreign Service Officers DNA is programmed to support policy and we’re schooled right from the start, that if there comes a point where one can no longer do so, particularly if one is in a position of leadership, the honorable course is to resign,” Melville wrote.

A spokesperson from the U.S. Department of State confirmed that Melville would be retiring after more than three decades of service under six presidents and 11 secretaries of state.

"Earlier today, the United States’ Ambassador to Estonia, Jim Melville, announced his intent to retire from the Foreign Service effective July 29 after 33 years of public service," the spokesperson said.

Melville said comments made by President Donald Trump on Wednesday about the European Union spurred his decision to step down.

"For the president to say the EU was 'set up to take advantage of the United States, to attack our piggy bank,' or that 'NATO is as bad as NAFTA,' is not only factually wrong but proves to me that its time to go,” Melville wrote.

On Wednesday, during a rally in North Dakota, Trump said that although the United States loves European countries, the E.U. "was set up to take advantage of the United States. And you know what, we can’t let that happen.”

The resignation comes just over a week before Trump is scheduled to head to Europe, where he will attend the NATO summit in Brussels on July 11 and 12 before heading to the United Kingdom on July 13. He will meet Russian President Vladimir Putin in Helsinki, Finland, on July 16.

Melville's resignation is the third this year behind now-former U.S. Ambassador to Panama John Feeley, who stepped down in March after announcing his intention to do so in December 2017, and now-former U.S. Ambassador to Mexico Roberta Jacobson, who stepped down in May.

Like Melville, both Feeley and Jacobson cited issues with the Trump administration in their decisions to step down.

"I resigned because the traditional core values of the United States, as manifested in the president’s National Security Strategy and his foreign policies, have been warped and betrayed. I could no longer represent him personally and remain faithful to my beliefs about what makes America truly great," Feeley said in his resignation letter.

Earlier this month, Jacobson told MSNBC's Andrea Mitchell that the president's treatment of Mexico had inhibited her ability to work with the country's government.

"Mexico has been the punching bag for this president since the beginning," Jacobson said in her first interview since leaving her position. "Despite that this Mexican government has tried very hard to cooperate with this administration, bending over backwards to some extent to their own political risk and this kind of thing makes it so much more difficult to cooperate with the Mexican government."