If you open your iMac, you void the warranty.
Dosen't make a difference if you open it and just look around, or open it up and replace the hard drive.. if you open it, you void the warranty.
Let's say for example, you open it up, replace the hard drive, and put it all back together again.. everything works smoothly for 6 months.
Then, all of a sudden, you find your logic board is toast. You send it back to Apple, they get it open, and find a hard drive in there that wasn't factory installed, or even a brand they carry.
Now, that's clear evidence that somebody has been under the hood.. how do they know you didn't smoke the logic board while poking around in there? Maybe a little ESD action? Who knows.. maybe you left a screw rolling around inside loose?
Having been a bench tech for many years, I can tell you that opening up a computer (or most other electronic devices) instantly voids your warranty.. for any reason.. 'naturally occouring' or your own incompetence.
Sometimes it's difficult to tell if a customer has been snooping round inside, tho.. so my advice is to keep the stuff you replace.. so if you ever have to return the machine for factory service, you can put the 'stock' stuff back in.
That way, the bench tech won't have any obvious clues that you'd had it's pants off.. unless, of course, there is a warranty seal on the case somewhere.