How would I animate this but not move the other side of cube?
Just add a Limit Rotation constraint to the piece in blue, provided the following pieces are parented in chain.

Make sure you set it to World Space coordinates, so it reads the absolute value instead of the parent.