Fetching details from the dictionary...
to dig one's own grave; to bring calamity upon oneself; to make a rod for one's own back