You're correct.
Your analysis is correct--a warlock can cast some long-duration spells by effectively spending hours instead of spell slots.
This is not unbalanced (for a single-classed warlock).
First, the spell slots that the warlock recovers on a short rest can only go up to level 5. Any long-duration spell above level 5 is subject to Mystic Arcanum, which only allows the warlock to cast it once per long rest (as explained here).
So which spells on the list are both level 5 or less and last longer than an hour? My quick perusal through the list shows only Hallucinatory Terrain, Hex, and Dream. Dream is arguably a special case, and Hex only works on one target at a time because of concentration, so your example of Hallucinatory Terrain is essentially the only spell that can be "exploited" this way. Opinions may vary about whether this "exploit" is especially powerful or not, but given that it the spell is quite limited in scope and it requires uninterrupted rests, I'd hardly consider it to be abuse.
Multiclassed warlocks can benefit this way
As Bloodcinder points out, multiclass warlocks can use their warlock spell slots to cast spells from their other classes (PHB 164):
If you have both the Spellcasting class feature and the Pact Magic class feature from the warlock class, you can use the spell slots you gain from the Pact Magic feature to cast spells you know or have prepared from classes with the Spellcasting class feature...
Thus, a warlock that has levels in wizard could cast a spell like Mage Armor, take a short rest to regain that spell slot, and then enjoy the benefits of Mage Armor for another 7 hours afterward.
As for whether this is balanced, I'd have to assume that the designers considered this possibility because the rule was written out so explicitly. After all, multiclassed spellcasters are delaying (or sacrificing) their ability to cast higher level spells, so there is some tradeoff to be considered.
Yes, you can do this
That's how it goes. Spell slots are regained at the end of a long rest, and there's no rule forbidding spellcasting during a long rest.
It's effective and somewhat cheesy, but not as broken as it might sound at first. To cast that spell before ending the rest, you need to save up a slot for it. If you intend to do this constantly, you find that while you get the spell for "tomorrow" free, you have to save one of "today's" slots in order to be able to cast it just before ending the rest. During longer expeditions it won't be that much different - you still have to save the slot to use the spell, just on a different day.
Of course, it's still a convenient way to squeeze extra utility out of one's slots when they do get left unused - and a good way to start the adventure after an uneventful day during which few slots were spent.
Best Answer
Spell Scrolls1
Provided you obtain enough of them and have enough time to cast them all, using 9th level spell scrolls would allow one to cast a lot of 9th level spells without a long rest.
Epic Boons
The DMG has rules for granting epic boons (starting on page 231) that include:
Either of these boons would allow one to cast Foresight (or another 9th level spell) twice before taking a long rest.
Monsters
Monsters do not have the same restrictions as player characters and it is also possible for them to have more than one 9th level spell slot. An example of this in published adventures is (spoilers):
1. Suggested by NautArch