* Correction appended.

Rick Perry, the former governor of Texas, will resign as secretary of energy later this year, President Donald Trump said during a visit to Texas on Thursday.

Perry drew scrutiny after being entangled in the president's efforts to push Ukraine officials to investigate the son of a political rival.

Perry's resignation was anticipated for several weeks, prior to news coming out about his involvement in the Ukraine scandal, in which Trump made efforts to convince the president of Ukraine, Volodymyr Zelensky, to investigate a company that formerly worked with Hunter Biden, the son of former Vice President Joe Biden, according to The New York Times.

At Louis Vuitton's Rochambeau Ranch in Johnson County on Thursday afternoon, Trump told reporters Perry will leave at the end of the year and that he had been aware for months that Perry planned to resign. Trump added that he already has a replacement for Perry and will be announcing that name "very shortly."

"Rick has done a fantastic job. But it was time," Trump said, according to White House pool reports. "He told me at the end of the year he’d like to go, and he’s got some ideas about doing something else. He’s a terrific guy."

Later Thursday, the president called Perry "very successful" during a campaign rally in Dallas.

"He spent three years with us and I want to thank you, Rick," Trump said.

Trump denied that the replacement would be Gov. Greg Abbott or Alaska Gov. Mike Dunleavy.

Calling Perry a good friend, U.S. Sen. Ted Cruz said in a statement Thursday that he wished his fellow Republican well "as he returns to private life" after a long public career.

“He went from being Texas’ longest-serving governor to heading the Department of Energy, where he was a leading advocate for U.S. energy, including liquefied natural gas," Cruz said. "Under his leadership, U.S. oil and gas production has soared — with much of that new production coming from Texas — and the United States has become a net exporter of natural gas, creating good-paying jobs, providing cleaner and more affordable energy, and boosting America’s energy independence."

Emma Platoff contributed reporting.

Correction: A previous version of this misattributed a quote said by Sen. Ted Cruz. It also gave the incorrect name for the location where Trump told reporters that Perry will leave at the end of the year. Trump said that in Johnson County.