Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Elastic IP for VPC instances per issue 18 #65

Merged
merged 7 commits into from
Aug 29, 2013

Conversation

bwhaley
Copy link
Contributor

@bwhaley bwhaley commented May 2, 2013

I needed this functionality so I wrote up part of what you discussed in Issue #18

A configuration aws.elastic_ip = true

Done

When set, part of the creation process creates an elastic IP (a new one) and assigns it to the instance.

Done

Some changes needed to make it work:

Provider ssh_info needs to take public IPs into account as a potential SSH candidate.

Done

Elastic IP needs to be tracked in the machine data dir and released when the VM is destroyed.

Not done. Not sure what the best way to accomplish this is.
Added in bwhaley/vagrant-aws@69a1f4f

@mitchellh
Copy link
Owner

Ben, this looks great! Thanks so much. Some nitpicks:

  • Instead of always allocating an EIP in VPC, we can be smart about it and allocate in a VPC if the instance is being booted into a VPC ("subnet_id" is set). That way the EIP will work in both EC2 and VPC. :)

After that, I'd be happy to merge, and we can work on some improvements.

@johntdyer This patch doesn't allow for pre-allocated EIPs, but that would be an easy improvement to make after we merge this in! :)

@bwhaley
Copy link
Contributor Author

bwhaley commented May 2, 2013

Great! Won't have that fix in until Tuesday or so.
Sent from Mailbox for iPhone

On Thu, May 2, 2013 at 2:51 PM, Mitchell Hashimoto
notifications@github.com wrote:

Ben, this looks great! Thanks so much. Some nitpicks:

  • Instead of always allocating an EIP in VPC, we can be smart about it and allocate in a VPC if the instance is being booted into a VPC ("subnet_id" is set). That way the EIP will work in both EC2 and VPC. :)
    After that, I'd be happy to merge, and we can work on some improvements.
    @johntdyer This patch doesn't allow for pre-allocated EIPs, but that would be an easy improvement to make after we merge this in! :)

    Reply to this email directly or view it on GitHub:
    Elastic IP for VPC instances per issue 18 #65 (comment)

@jtopper
Copy link

jtopper commented May 23, 2013

I've been trying out your branch here @bwhaley - you'll need to do something conditional with the launch_vpc_warning which still fires even when I've enabled an elastic_ip.

Also a vagrant destroy throws errors but I think that's down to a (now solved) bug in the upstream you branched from.

@bwhaley
Copy link
Contributor Author

bwhaley commented May 23, 2013

Thanks @jtopper, added a commit for that.

@bashtoni
Copy link

@bwhaley I'm working on this with @jtopper - it also seems as though you're not releasing the elastic IP on destroy.

@bwhaley
Copy link
Contributor Author

bwhaley commented May 24, 2013

No, that's true, I'm not. See the very first comment in this PR. Per @mitchellh above, he agreed to merge the request and fix that after integrating. OTOH, I'm happy to fix it if you can give me a quick pointer on how to track the EIP in the machine data dir. It wasn't obvious to me.

@bashtoni
Copy link

Sorry, didn't notice that.

The easiest way to get the EIP of an instance is to run curl -fs http://169.254.169.254/latest/meta-data/public-ipv4 on the instance itself (over SSH). This of course assumes that curl is installed on the remote host.

@bwhaley
Copy link
Contributor Author

bwhaley commented May 24, 2013

I understand how to get the IP of the instance, but the part I wasn't clear
about was how to track that in the machine data dir. Just point me at which
vagrant code to look at and I can add it no problem.

@jtopper
Copy link

jtopper commented May 24, 2013

I've had a good poke at the code and I can't see where useful machine state
is getting serialized either - and the docs don't obviously cover it.

I think the existing provider probably just needs the 'id' serialized, and
that's a standard part of the Vagrant::Machine object. Unless I'm
mistaken, you probably need to create your own file under the machine's
@data_dir path and write the eip to it.

On 24 May 2013 14:50, bwhaley notifications@github.com wrote:

I understand how to get the IP of the instance, but the part I wasn't
clear
about was how to track that in the machine data dir. Just point me at
which
vagrant code to look at and I can add it no problem.

On Fri, May 24, 2013 at 7:46 AM, bashtoni notifications@github.com
wrote:

Sorry, didn't notice that.

The easiest way to get the EIP of an instance is to run curl -fs
http://169.254.169.254/latest/meta-data/public-ipv4 on the instance
itself (over SSH). This of course assumes that curl is installed on the
remote host.


Reply to this email directly or view it on GitHub<
https://github.com/mitchellh/vagrant-aws/pull/65#issuecomment-18405648>
.


Reply to this email directly or view it on GitHubhttps://github.com//pull/65#issuecomment-18405894
.

@bwhaley
Copy link
Contributor Author

bwhaley commented May 28, 2013

@jtopper @bashtoni This commit releases the elastic IP for either VPC or EC2 instances. Also caught up with master.

@bashtoni
Copy link

Nice work, I just tested it and this works perfectly for me.

@bwhaley
Copy link
Contributor Author

bwhaley commented May 28, 2013

Great! Can this PR be merged now?

@bashtoni
Copy link

bashtoni commented Jun 6, 2013

@mitchellh We've been using this quite a bit over the last week with no problems - looks good to merge to me.

@gondo
Copy link

gondo commented Jun 18, 2013

+1 for merging this
i would also like to see config option to use pre-allocated IP

@@ -31,7 +31,7 @@ def read_ssh_info(aws, machine)

# Read the DNS info
return {
:host => server.dns_name || server.private_ip_address,
:host => server.public_ip_address || server.dns_name || server.private_ip_address,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to make public_ip_address default over dns_name?
Or maybe we should just drop dns_name altogether?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No good reason. I just thought it made more sense to return an EIP if it was requested rather than a DNS name. We could potentially drop either one.

Also, private_ip_address will only work if the user has some direct connection to an instance in a VPC, such as over a VPN.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes private_ip_address was added precisely for that.

Otherwise the PR looks good, I'll be merging it soon. Thanks.

@tralamazza
Copy link
Collaborator

Could you add the entry in config_spec.rb for elastic_ip. Thanks.

@pidah
Copy link
Contributor

pidah commented Aug 28, 2013

+1 for feature merge

@dldinternet
Copy link

+1 for merge. I needed this so I installed the vagrant-aws plugin built from @bwhaley 's fork!

tralamazza added a commit that referenced this pull request Aug 29, 2013
Elastic IP for VPC instances per issue 18
@tralamazza tralamazza merged commit 93f4143 into mitchellh:master Aug 29, 2013
tralamazza added a commit that referenced this pull request Aug 29, 2013
@madhurranjan
Copy link

Great! One final comment on this request . You actually don't need a json file to store the ip . You can call the api to get this information - for reference - https://github.com/mitchellh/vagrant-aws/pull/129/files#L1R20

@tralamazza
Copy link
Collaborator

Yup :) and there are other things to cleanup, example doing a dissociate_address on publicip (it's done by Fog on terminate_instances).

dldinternet pushed a commit to dldinternet/vagrant-aws that referenced this pull request Aug 29, 2013
@candtoro
Copy link

candtoro commented Oct 4, 2013

Is there a way to assign a previously allocated EIP using this provider, or anybody can suggest a workaround for this?

@dldinternet
Copy link

You will need modifications like those made by a friend of mine here: https://github.com/grosendorf/knife-ec2/commits/master
I think you will also need an updated Fog gem to support that.

@madhurranjan
Copy link

You could use this 9a86a91
if you want to explicitly specify eip as part of the Vagrantfile. We have a wrapper script that initially generates out a eip and adds that to the Vagrantfile. Reason being when we create multiple machines in parallel and you've specified :elasticip => true, and all these machines try and call the Fog api at the same time which throws an error.However, if you've specified the EIP earlier then it works perfectly fine.

@yexingok
Copy link

yexingok commented Mar 3, 2014

We are happy to see vagrant-aws already have this cool feature!
Thank you men!
Could we also put this in README.md? I guess users will be happy to see that!

@damienjoldersma
Copy link

+1 for @yexingok request to update README.md file with this new feature! Was excited to see feature working (thank you!) but took a little while googling before I found this thread... :) Cheers!

dkinzer added a commit to dkinzer/vagrant-aws that referenced this pull request Aug 18, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.