This is my AWS setup:
- 1 VPC with:
- default public subnet, 10.0.0.0/24
- 1 EC2 micro instance, private 10.0.0.172 and public Elastic IP
- 1 RDS instance, running MySQL
- default public subnet, 10.0.0.0/24
The EC2 instance has network connection to the outside world (verified with ping 8.8.8.8
). This is it's routing table:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ip-10-0-0-1.eu- 0.0.0.0 UG 0 0 0 eth0
10.0.0.0 * 255.255.255.0 U 0 0 0 eth0
instance-data.e * 255.255.255.255 UH 0 0 0 eth0
The EC2 instance can also connect to the RDS instance.
What I want, is to launch a second EC2 instance (Amazon Linux AMI 2014.03.1 64bit) from inside the first EC2 instance, using Vagrant. The second EC2 instance should be in the same VPC subnet but it's actual IP address doesn't matter much. It also doesn't need a public Elastic IP. It does need to connect to the outside world, to install software using yum
.
This is my Vagrantfile
:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "dummy"
config.vm.provider :aws do |aws, override|
aws.access_key_id = "ACCESS_KEY_ID"
aws.secret_access_key = "SECRET_ACCESS_KEY"
aws.keypair_name = "KEYPAIR_NAME"
aws.ami = "ami-2918e35e"
aws.instance_type = "m1.small"
aws.region = "eu-west-1"
aws.subnet_id = "subnet-SUBNETID"
aws.security_groups = "sg-SECURITYGROUPID"
override.ssh.username = "ec2-user"
override.ssh.private_key_path = "PRIVATE_KEY.pem"
end
config.ssh.pty = true
config.vm.provision "shell", path: "provision.sh"
end
In the shell script provision.sh
I install some software:
yum install -y subversion
This fails, because yum
can't connect to the outside network.
When I do vagrant ssh
and check the IP address, it's in the 10.0.0.0/24 range and I can ping in either direction between the two EC2 instances (ICMP was allowed in the security group). I can't ping 8.8.8.8
and I can't yum install
software because the instance can't reach the repositories. I checked the route
and it's identical to that of the first instance.
Also, in the AWS web console, the second instance doesn't have a public IP address.
When I add this line to my Vagrantfile
:
aws.associate_public_ip = true
then I get the following error on vagrant up --provider=aws --provision
:
There are errors in the configuration of this machine. Please fix
the following errors and try again:
AWS Provider:
* The following settings shouldn't exist: associate_public_ip
and the instance does not launch.
So my question is: how can I give the vagrant instance a network connection, without using an Elastic IP?
in my installation that parameter was not exist but there is
that has the same purpose.
To find the real fields used in your plugins chech this file
of course I have the vagrant-aws-0.4.1 change with yours