John Ryan's first-half try and the boot of Ian Keatley looked like being enough but Will Helu crossed after the break at BT Murrayfield and the visitors had to cling on, defending on their line long after 80 minutes were up.
But after Sam Hidalgo-Clyne's drop goal attempt was charged down, the victory was secured - much to Foley's relief.
"I thought we played well in the first half. We controlled a lot of the game but then we allowed them into the game and one or two loose kicks and missed tackles allowed their back three to play with more tempo," he said.
"Towards the end of the match we wrestled the game back from them. We had a five-metre scrum and the referee calls a free-kick. We should have parked up there for the remainder of the game. But we threw an interception when we should have kicked it out of the stadium. I'm very relieved now but I thought we were well worth our win.
"It was great to have Conor (Murray) and Keith Earls back. Quality players give confidence to those around them. Conor's ability as a scrum-half is exceptional. There's no one in the northern hemisphere to touch him. I thought Keith had an excellent game."
To buy tickets for the GUINNESS PRO12 Grand Final click here. Also follow us on Facebook, join the conversation on Twitter, sign up to our YouTube channel for extensive match highlights and sign up for our newsletter for regular updates on the GUINNESS PRO12.