Alternatively, since its just a bunch of square edges, you can just build the thing on a table with wax paper under it, foam it up and all right there. Once dry use a breadknife/saw/whatever to cut off the foam that went past the eggcrate. It also means any sticking out pieces don't have to fight gravity before you get foam all around them...
Personally, I wouldn't want to permanently bond the foam wall to the glass.
+1 to building it on a table surface for no other reason than you could really be more creative with your rock work. Using cable ties or Gorilla glue to adhere the rocks to the eggcrate, it's an easy job to spray foam around and trowel the foam around to rough it up. Most people probably just leaves the foam 'noodles' to dry but give it a minute to form a thin skin and then trowel it around the rocks and pat down the noodles and when it dries, the texture is realistically rock like with striations and pits.
I would recommend constructing the structure outside of your display then installing it. If necessary you could fabricate the insert in several sections. This way you will have maximum control over the design and not have to work within a confined space.
I did exactly what gorgok did (wax paper and shaved off backside) and it worked great. It fit nice and flush up to the rear glass. Once I had it shaved down i used aquarium silicone to stick it to the back glass.