mitchellh / vagrant-aws

Use Vagrant to manage your EC2 and VPC instances.
MIT License
2.61k stars 574 forks source link

Retrieving AWS info fails in multi-machine environments #507

Closed mhavu closed 7 years ago

mhavu commented 7 years ago

I have two AWS configurations, foo and bar, and two Vagrant boxes with corresponding names, created with Packer. I can bring them up with

config.vm.box = "foo"
config.vm.provider :aws do |aws|
  aws.aws_profile = "foo"
  aws.keypair_name = "foo"
  aws.instance_type = "t2.micro"
end

or the same for bar. However, I would like to use a multi-machine setup.

For some reason, the following fails as if the AWS configuration was invalid:

config.vm.define 'foo' do |foo|
  foo.vm.box = "foo"
  foo.vm.provider :aws do |aws|
    aws.aws_profile = "foo"
    aws.keypair_name = "foo"
  end
end

config.vm.define 'bar' do |bar|
  bar.vm.box = "bar"
  bar.vm.provider :aws do |aws|
    aws.aws_profile = "bar"
    aws.keypair_name = "bar"
  end
end

config.vm.provider :aws do |aws, override|
  aws.instance_type = "t2.micro"
end

(I get the following error:

~/.vagrant.d/gems/gems/vagrant-aws-0.7.2/lib/vagrant-aws/config.rb:537:in `read_aws_files': undefined method `[]' for nil:NilClass (NoMethodError)
    from ~/.vagrant.d/gems/gems/vagrant-aws-0.7.2/lib/vagrant-aws/config.rb:513:in `get_aws_info'

Giving aws.access_key_id, aws.secret_access_key, and aws.region in the Vagrantfile doesn't help either. I'm using Vagrant 1.9.2 and AWS plugin version 0.7.2.)

How can I define a multi-machine AWS environment?

mhavu commented 7 years ago

Turns out the following works:

config.vm.define 'foo' do |foo|
  foo.vm.box = "foo"
  foo.vm.provider :aws do |aws|
    aws.instance_type = "t2.micro"
    aws.aws_profile = "foo"
    aws.keypair_name = "foo"
  end
end

config.vm.define 'bar' do |bar|
  bar.vm.box = "bar"
  bar.vm.provider :aws do |aws|
    aws.instance_type = "t2.micro"
    aws.aws_profile = "bar"
    aws.keypair_name = "bar"
  end
end

Is there a way to put the common parts (instance_type) in a single place?