devopsgroup-io / vagrant-digitalocean

:droplet: A Vagrant provider plugin that manages DigitalOcean droplets.
Mozilla Public License 2.0
1.71k stars 182 forks source link

'vagrant rebuild' should ask for confirmation before destroying a droplet #236

Open eyemyth opened 8 years ago

eyemyth commented 8 years ago

I just lost a droplet to 'vagrant rebuild'. It should provide the same confirmation as the usual 'vagrant destroy'.

Luckily the droplet I accidentally destroyed wasn't super important.

davidalger commented 8 years ago

@eyemyth Something you could try that would solve this for you in your setups is to use the vagrant-triggers plugin to put up a warning. I've done that here, and you're welcome to copy that snippet into your own project if you'd like:

  # verify with user before allowing a rebuild to take place
  conf.trigger.before :rebuild do
    confirm = nil
    until ["Y", "y", "N", "n"].include?(confirm)
      puts "The rebuild command is a potentially destructive operation. All data on the VM will be erased!"
      confirm = ask "Are you sure you want to rebuild the VM? [y/N] "
    end
    exit unless confirm.upcase == "Y"
  end
webhive commented 7 years ago

Damn! Just accidently lost a droplet too :( Restored from 3-days ago backup but anyway too dangerous operation. And btw I was trying just to see a command help

vagrant rebuild --help 

So I got help message and command rebuild executed right after it. So first of my hosts has been lost immediately without any prompt. And I am completely disagree about this is nice-to-have feature - it should be must-have mandatory feature.

@davidalger script is very useful but no doubts it should be default behaviour without any additional scripts.