The mainstay tools are really wrenches and allen keys, certainly these will be all you need for something trivial like fitting a rack.
But the more you get into things, there are a myriad of different tools around, often which can be used for one and only one task. For example if you want to get the cranks off you need a crank puller, of which there are a couple of different types. To change a cassette, you need the right lockring (possibly a half-a-dozen or more of these). A special tool to break a chain (you replace chains relatively regularly, compared to other maintenance). Another too to swap out a bottom bracket, a rig to check how true your wheel is.....
The good news is that you're not (certainly as an individual wanting to maintain your bike) going to want all of these tools at once - they can be collected over time. And if looked after they pretty much last forever.
I don't know whether you'd count these as tools (I would) but I'd say it is definitely worth buying, up front, tyre levers and a pump, so you're able to change a tyre and repair a puncture. These, unfortunately, are the most common tasks you'll need to perform.