Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Prompt user for confirmation when terminating an instance. #23

Merged
merged 1 commit into from

4 participants

@jamescarr

Currently when running "vagrant destroy" against a box that is an EC2 instance it just terminates the box without prompting the user.

This addition seems like it should work but I have no way of testing it. I'd LOVE to have an automated spec against it but I am unsure of how to do so. :(

@jamescarr

As an aside, I tried to test this with the following vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = 'dummy'
  config.vm.box_url = 'https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box'

  config.vm.provider :aws do |aws|
    aws.access_key_id = ENV["AWS_ACCESS_KEY_ID"]
    aws.secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
    aws.keypair_name = ENV["AWS_KEYPAIR_NAME"]
    aws.region = "us-west-2"
    aws.ami = "ami-87654321"
    aws.ssh_username = "ubuntu"
    aws.ssh_private_key_path = ENV["AWS_SSH_PRIVKEY"]
    aws.instance_type = "t1.micro"
    aws.tags = {
      'role' => 'testbox',
      'Name' => 'test-server'
    }
    aws.security_groups = ['default']
  end
end

Running this on rvm with ruby 1.9.3 on Mac OSX Mountain Lion:

bundle && bundle exec rake && bundle exec vagrant up --provider=aws

and wound up with this error that the aws provider could not be found. I also tried --provider=vagrant-aws.

Screen Shot 2013-03-29 at 12 37 36 AM

@chooper

:+1: regarding the title/original issue here. This should probably be consistent with the behavior of the VirtualBox provider, which prompts on destroy.

@mitchellh
Owner

Unfortunately the DestroyConfirm middleware isn't built-in to Vagrant. But it probably should be... going to do that now.

@jamescarr

cool

@mitchellh
Owner

I added the built-in middleware: mitchellh/vagrant@780a312

@mitchellh
Owner

And merged!

@mitchellh mitchellh merged commit b3e5f4f into mitchellh:master
@jamescarr

Yay!

@jamescarr jamescarr deleted the jamescarr:prompt-on-instance-termination branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 3 deletions.
  1. +9 −3 lib/vagrant-aws/action.rb
View
12 lib/vagrant-aws/action.rb
@@ -11,9 +11,15 @@ module Action
# This action is called to terminate the remote machine.
def self.action_destroy
Vagrant::Action::Builder.new.tap do |b|
- b.use ConfigValidate
- b.use ConnectAWS
- b.use TerminateInstance
+ b.use Call, DestroyConfirm do |env, b2|
+ if env2[:result]
+ b2.use ConfigValidate
+ b2.use ConnectAWS
+ b2.use TerminateInstance
+ else
+ b2.use MessageWillNotDestro
+ end
+ end
end
end
Something went wrong with that request. Please try again.