概要
Vagrantを使ってAWSインスタンスの管理設定をしていたらvagrant destroyでエラーが出て悩まされた
原因は、「初期作成されているVPCを使うとエラーが出る」もしくは、「VPCを指定しないとエラーが発生する」みたいだったが、直ったので調査は切り上げた
とりあえず、自分の解決策を残しておく
発生したエラー
$ vagrant destroy -f
/home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/middlewares/expects.rb:7:in `response_call': InvalidParameterValue => You must specify an allocation id when releasing a VPC elastic IP address (Fog::Compute::AWS::Error)
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/middlewares/response_parser.rb:9:in `response_call'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/connection.rb:388:in `response'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/connection.rb:252:in `request'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/middlewares/idempotent.rb:27:in `error_call'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/middlewares/base.rb:11:in `error_call'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/middlewares/base.rb:11:in `error_call'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/connection.rb:272:in `rescue in request'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/connection.rb:215:in `request'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/middlewares/idempotent.rb:27:in `error_call'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/middlewares/base.rb:11:in `error_call'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/middlewares/base.rb:11:in `error_call'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/connection.rb:272:in `rescue in request'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/connection.rb:215:in `request'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/middlewares/idempotent.rb:27:in `error_call'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/middlewares/base.rb:11:in `error_call'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/middlewares/base.rb:11:in `error_call'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/connection.rb:272:in `rescue in request'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/excon-0.55.0/lib/excon/connection.rb:215:in `request'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/fog-xml-0.1.2/lib/fog/xml/sax_parser_connection.rb:35:in `request'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/fog-xml-0.1.2/lib/fog/xml/connection.rb:7:in `request'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/fog-aws-1.2.0/lib/fog/aws/compute.rb:527:in `_request'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/fog-aws-1.2.0/lib/fog/aws/compute.rb:522:in `request'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/fog-aws-1.2.0/lib/fog/aws/requests/compute/release_address.rb:25:in `release_address'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/vagrant-aws-0.7.2/lib/vagrant-aws/action/terminate_instance.rb:45:in `release_address'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/vagrant-aws-0.7.2/lib/vagrant-aws/action/terminate_instance.rb:24:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/warden.rb:34:in `call'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/vagrant-aws-0.7.2/lib/vagrant-aws/action/elb_deregister_instance.rb:19:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/warden.rb:34:in `call'
from /home/nakao/.vagrant.d/gems/2.2.5/gems/vagrant-aws-0.7.2/lib/vagrant-aws/action/connect_aws.rb:43:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/warden.rb:34:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/warden.rb:34:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/warden.rb:34:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/builder.rb:116:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/runner.rb:66:in `block in run'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/util/busy.rb:19:in `busy'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/runner.rb:66:in `run'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/builtin/call.rb:53:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/warden.rb:34:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/warden.rb:34:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/warden.rb:34:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/warden.rb:34:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/builder.rb:116:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/runner.rb:66:in `block in run'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/util/busy.rb:19:in `busy'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/runner.rb:66:in `run'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/builtin/call.rb:53:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/warden.rb:34:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/builder.rb:116:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/runner.rb:66:in `block in run'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/util/busy.rb:19:in `busy'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/action/runner.rb:66:in `run'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/machine.rb:225:in `action_raw'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/machine.rb:200:in `block in action'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/environment.rb:567:in `lock'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/machine.rb:186:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/machine.rb:186:in `action'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/plugins/commands/destroy/command.rb:31:in `block in execute'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/plugin/v2/command.rb:235:in `block in with_target_vms'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/plugin/v2/command.rb:229:in `each'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/plugin/v2/command.rb:229:in `with_target_vms'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/plugins/commands/destroy/command.rb:30:in `execute'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/cli.rb:42:in `execute'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/lib/vagrant/environment.rb:308:in `cli'
from /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/bin/vagrant:127:in `<main>'
対処
- AWS VPCの設定(AWS)
- Security Groupの設定(AWS)
- vagrant-awsのインストール(Local)
- Vagrantfileに設定追加(Local)
AWS VPCの設定(AWS)
AWS VPCコンソールでVPCウィザードの手順通りに設定するだけ
VPCとはなんぞや?的な話は省略!
[手順]
1. 「1 個のパブリックサブネットを持つ VPC」を選択
2. アベイラビリティゾーンを「ap-northeast-1c」に設定
3. 後はデフォルトの設定のまま、てきとーに作成(オイッ
4. サブネットのタブ開いて サブネットID をメモ(Vagrantfileで使う)
Security Groupの設定(AWS)
Amazon EC2コンソールでセキュリティグループを新規作成する
[手順]
1. セキュリティグループ名/説明を入力
2. VPCに、先ほど作成したVPCを設定
3. インバウンドにVagrantを使ってアクセスするPCのグローバルIPを設定
4. セキュリティグループID をメモ(Vagrantfileで使う)
vagrant-awsの設定(Local)
前回記事参照
Vagrantfileに設定追加(Local)
以下の設定を追加
Vagrantfile
Vagrant.configure("2") do |config|
# Vagrant Box
config.vm.box = "dummy"
# Rsync Directory
config.vm.synced_folder "setup", "/vagrant", type: "rsync"
config.vm.provider :aws do |aws, override|
# AWS Account
aws.access_key_id = ENV['AWS_ACCESS_KEY_ID']
aws.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
# Instance Configuration
aws.tags = {
'Name' => 'DevelopEnvironment'
}
aws.instance_type = "t2.micro"
aws.ami = "ami-c68fc7a1"
aws.region = "ap-northeast-1"
aws.availability_zone = "ap-northeast-1c"
aws.associate_public_ip = true
+ aws.security_groups = ['sg-XXXXXXXX']
+ aws.elastic_ip = true
+ aws.subnet_id = "subnet-XXXXXXXX"
# Login Configuration
aws.keypair_name = "default"
override.ssh.username = "ubuntu"
override.ssh.private_key_path = "~/.ssh/default.pem"
# SSH accessable
aws.user_data = "sed -i -e 's/^\\(Defaults.*requiretty\\)/#\\1/' /etc/sudoers"
end
end
実行結果
$ vagrant up
Bringing machine 'default' up with 'aws' provider...
==> default: Warning! The AWS provider doesn't support any of the Vagrant
==> default: high-level network configurations (`config.vm.network`). They
==> default: will be silently ignored.
==> default: Launching an instance with the following settings...
==> default: -- Type: t2.micro
==> default: -- AMI: ami-c68fc7a1
==> default: -- Region: ap-northeast-1
==> default: -- Availability Zone: ap-northeast-1c
==> default: -- Keypair: default
==> default: -- Subnet ID: subnet-XXXXXXXX
==> default: -- Elastic IP: true
==> default: -- User Data: yes
==> default: -- Security Groups: ["sg-XXXXXXXX"]
==> default: -- User Data: sed -i -e 's/^\(Defaults.*requiretty\)/#\1/' /etc/sudoers
==> default: -- Block Device Mapping: []
==> default: -- Terminate On Shutdown: false
==> default: -- Monitoring: false
==> default: -- EBS optimized: false
==> default: -- Source Destination check:
==> default: -- Assigning a public IP address in a VPC: true
==> default: -- VPC tenancy specification: default
==> default: Waiting for instance to become "ready"...
==> default: Waiting for SSH to become available...
==> default: Machine is booted and ready for use!
==> default: Rsyncing folder: /mnt/c/Users/kazuyoshi/aws-training/setup/ => /vagrant
$ vagrant ssh
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-64-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
0 packages can be updated.
0 updates are security updates.
ubuntu@ip-10-147-58-161:~$ exit
logout
$ vagrant destroy -f
==> default: Terminating the instance...