mitchellh/vagrant-aws

Is there a flag to customize vagrant names for EC2 instances? Not EC2 tags.

Joseph-R opened this issue · 2 comments

I see how to tag servers on EC2. I do not see how to modify the name nodes appear by in the vagrant tools itself (vagrant status/up/delete/etc.)

For example, this Vagrantfile generates the following output:

$ vagrant status
Current machine states:

default                   not created (aws)

The EC2 instance is not created. Run `vagrant up` to create it.

And what we're used to doing with the VirtualBox provider is defining a name through the customize option.

Example:

    analytics.vm.provider :virtualbox do |virtualbox|
      virtualbox.customize ["modifyvm", :id, "--name", "AnalyticsServer"]  # Sets VM name in Vagrant
    end

Which let's us set namespaces for each box, like so:

$ vagrant status
Current machine states:

analytics                 not created (virtualbox)
pentaho                   not created (virtualbox)
matcher                   not created (virtualbox)

This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.

I do not see an analogue for that in the vagrant-aws README.md. Is there one?

Ideally, I'd like to name these nodes in Vagrant to the same thing I tag them with on EC2. Something like "#{USER}'s_dev_analytics_box".

Is that possible with the current toolset?

I figured out how to do it. Posting back here for posterity:

The solution is to name your VM in the config block (for Vagrant CLI), and then use the aws.tags resource to tag the instance the same way on AWS.

Example:

  config.vm.define "#{user}_hdp_dev" do |hdp|
    hdp.vm.box = "hdp_dummy_box"

    hdp.vm.provider :aws do |aws, override|
      aws.ami = "ami-57cd8732"            # Stock CentOS 6 with HVM
      aws.instance_type = "t2.large"
      aws.subnet_id = "subnet-aebab1da"   # Public subnet
      aws.security_groups = "sg-b69836d0" # SG name = "development_HDP_VMs"
      aws.keypair_name = "korrelate2012"  # Assign the default keypair for SSH.

      # Configure user AWS keys in .profile to be exported as ENV variables.
      aws.access_key_id = ENV['AWS_ACCESS_KEY']
      aws.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']

      # Tag each instance with developer name.
      aws.tags = {
        'Name' => "#{user}_hdp_dev"
      }

      # Must have private component korrelate2012 key pair in .ssh dir.
      override.ssh.username = "ec2-user"
      override.ssh.private_key_path = "~/.ssh/korrelate2012.pem"
    end

  end

Results in:

$ vagrant status
Current machine states:

analytics                 not created (virtualbox)
pentaho                   not created (virtualbox)
matcher                   not created (virtualbox)
jreid_hdp_dev             not created (aws)

Hi Joseph,

How you are passing the value to #{user} ?? Can I pass it from enviornment variable ? or I need to hardcode it ?