The day Agim Kruezi was arrested for planning a terrorist attack on home soil, he had arranged to meet with one of his most trusted friends for a gym workout.

Key points: Logan man Agim Kruezi unknowingly befriended an undercover police officer, who collected information about him

Logan man Agim Kruezi unknowingly befriended an undercover police officer, who collected information about him Kruezi told the man about his extremist views, and encouraged the officer to head to Syria to fight

Kruezi told the man about his extremist views, and encouraged the officer to head to Syria to fight Kreuzi has been sentenced to 17 years in prison for planning a terrorist attack on Australian soil

But that friend was an undercover police officer who for months had been building a case against the 25-year-old radicalised Muslim.

Known as UCO317656, the Australian Federal Police (AFP) officer met Kruezi at the iQraa Islamic Centre at Underwood, south of Brisbane, in June 2014.

The centre was soon bugged with a listening device.

Kruezi had been on the radar of counter-terrorism authorities since he tried unsuccessfully to leave the country to fight with rebel forces in Syria.

He would eventually plead guilty to preparing for a terrorist attack in Australia and was yesterday sentenced to 17 years in prison.

UCO317656 played a critical role in foiling the attack by working tirelessly to gain the trust of Kruezi and his friends, even converting to the Islamic faith in a ceremony conducted by Kruezi.

Agim Kruezi (right) was charged after the Logan Islamic centre raid. ( ABC TV News )

Over the space of months, Kruezi shared intimate details about his radicalised views, and encouraged his friend to travel to Syria to fight with Islamic State.

"What excuse are you going to have on the day of judgment when Allah says you knew better, you knew you should have fought?" he asked of the undercover officer.

"Allah has told you so many things about it and you're still going to be a coward and run away?"

Police, all the while, were listening to secretly-recorded phone calls and monitoring Kruezi's text messages, which ranged from conversations about beheading being the most humane way of killing someone, to his belief that martyrdom would lead him to heaven.

In July 2014, Kruezi bought a machete knife, which he said he needed for hunting.

The next day, he offered to sell the weapon to UCO317656 because he needed "something more concealable".

Queensland police outside the iQraa Islamic centre on the day of the 2014 raid. ( ABC News: Alyse Edwards )

A sentencing hearing in the Supreme Court in Brisbane this week was told that a month later the young man bought a sawn-off rifle on a trip to Sydney for $2,000, and spoke with other radicalised Muslims who were conspiring to "do something with Parliament House in Canberra".

The court heard UCO317656 and Kruezi's relationship became so close that while in Sydney buying the gun, Kruezi called the undercover officer and said he "missed him and that, other than family, he would be the first person you would call when you returned to Brisbane".

In another conversation, Kruezi told the AFP officer that attacks on Australians by radicalised Muslims were "inevitable and will happen".

In the following weeks, police recorded the man buying 10 litres of petrol, and "frantically" searching a dozen shops in Brisbane for bottles and corks.

Kruezi planned to use the materials to build explosive devices, mainly molotov cocktails, to harm or kill Australians.

Police raided the iQraa Islamic Centre on September 10, 2014, arresting Kruezi on terrorism-related charges.

He will not be eligible for parole until 2031, and even then, the Attorney-General could opt to have him held longer in detention.

Agim Kruezi bought a sawn-off shotgun, balaclavas and two machetes, the court heard. ( ABC News: Sharon Gordon )

Kruezi never said exactly where or when he planned to attack, but Justice Roslyn Atkinson said she was satisfied Kruezi was "well underway in planning an attack using the hardware you had acquired".

The investigation, which included phone taps, listening devices and personal interactions, was praised by Home Affairs Minister Peter Dutton.

"I would like to congratulate the police and security agencies for their work which led to this outcome," Mr Dutton said.

"The timely intervention which ultimately led to today's outcome prevented a potential terrorist attack and is a reminder of how effectively our agencies work together to turn intelligence into preventative action."

Mr Dutton said evidence collected in the investigation revealed Kruezi was only days away from carrying out a terrorist attack somewhere in Queensland.

Kruezi was found to have shown no remorse and to pose an ongoing threat to the community.